constant.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * 公共配置文件
  3. * @邠心vbe on 2021/04/07
  4. */
  5. import {
  6. Text,
  7. TextInput,
  8. Dimensions,
  9. Platform,
  10. StatusBar,
  11. StyleSheet,
  12. NativeModules,
  13. } from 'react-native';
  14. import DeviceInfo from 'react-native-device-info';
  15. import apiUser from '../api/apiUser';
  16. import geolocation from '@react-native-community/geolocation';
  17. navigator.geolocation = geolocation;
  18. global.isIOS = Platform.OS == 'ios';
  19. global.$width = Dimensions.get('window').width;
  20. global.$height = Dimensions.get('window').height;
  21. global.$screen = Dimensions.get('screen').height;
  22. global.statusHeight = isIOS ? 0 : StatusBar.currentHeight;
  23. global.toolbarSize = isIOS ? 50 : 56;
  24. if (isIOS) {
  25. const {StatusBarManager} = NativeModules;
  26. StatusBarManager.getHeight(statusBarHeight => {
  27. const height = statusBarHeight.height;
  28. //global.toolbarSize = toolbarSize + height;
  29. global.statusHeight = height;
  30. });
  31. global.BRAND = '';
  32. } /*else {
  33. global.statusHeight = StatusBar.currentHeight;
  34. global.BRAND = DeviceInfo.getBrand().toLowerCase();
  35. }*/
  36. if (Text.defaultProps == null)
  37. Text.defaultProps = {};
  38. Text.defaultProps.allowFontScaling = false;
  39. if (TextInput.defaultProps == null)
  40. TextInput.defaultProps = {};
  41. TextInput.defaultProps.allowFontScaling = false;
  42. global.currency = "";//'$';
  43. global.accessToken = '';
  44. global.startPage = {};
  45. global.storageSite = [];
  46. global.chargeInfoState = {};
  47. global.userInfo = {
  48. userPk: -1,
  49. credit: 0,
  50. userType: "Public",
  51. nickname: 'Sign In'
  52. };
  53. global.isLogin = () => {
  54. return global.accessToken !== '';
  55. };
  56. global.getUserId = () => {
  57. return global.userInfo.userPk;
  58. };
  59. global.getUserInfo = (resolve, force) => {
  60. if (isLogin()) {
  61. if (userInfo.userPk > 0 && !force) {
  62. //console.log('-->>>>> 获取用户数据');
  63. if (resolve) resolve(global.userInfo);
  64. } else {
  65. apiUser.getProfile().then(res => {
  66. console.log('-->>>>> global.getUserInfo', res);
  67. if (res.data) {
  68. global.userInfo = res.data;
  69. if (resolve) resolve(res.data);
  70. }
  71. }).catch(erros => {
  72. console.info('<<<<<-- global.getUserInfo', erros);
  73. })
  74. }
  75. } else {
  76. if (resolve) resolve(global.userInfo)
  77. }
  78. }
  79. global.$vh = percent => {
  80. return (global.$height * percent) / 100;
  81. };
  82. global.$vhs = percent => {
  83. return global.$height * percent / 100 - global.statusHeight;
  84. };
  85. global.$vht = percent => {
  86. return global.$height * percent / 100 - toolbarSize;
  87. };
  88. global.$vhts = percent => {
  89. return global.$height * percent / 100 - toolbarSize - global.statusHeight;
  90. };
  91. global.$vw = percent => {
  92. return (global.$width * percent) / 100;
  93. };
  94. global.$padding = (top, right, bottom, left) => {
  95. if (top == undefined) {
  96. return {};
  97. }
  98. if (right == undefined) {
  99. right = top;
  100. }
  101. if (bottom == undefined) {
  102. bottom = top;
  103. }
  104. if (left == undefined) {
  105. left = right;
  106. }
  107. return {
  108. paddingTop: top,
  109. paddingLeft: left,
  110. paddingRight: right,
  111. paddingBottom: bottom
  112. };
  113. }
  114. global.$margin = (top, right, bottom, left) => {
  115. if (top == undefined) {
  116. return {};
  117. }
  118. if (right == undefined) {
  119. right = top;
  120. }
  121. if (bottom == undefined) {
  122. bottom = top;
  123. }
  124. if (left == undefined) {
  125. left = right;
  126. }
  127. return {
  128. marginTop: top,
  129. marginLeft: left,
  130. marginRight: right,
  131. marginBottom: bottom
  132. };
  133. }
  134. global.$borderRadius = (topLeft, topRight, bottomRight, bottomLeft) => {
  135. if (topLeft == undefined) {
  136. return {};
  137. }
  138. if (topRight == undefined) {
  139. topRight = topLeft;
  140. }
  141. if (bottomRight == undefined) {
  142. bottomRight = topLeft;
  143. }
  144. if (bottomLeft == undefined) {
  145. bottomLeft = topRight;
  146. }
  147. return {
  148. borderTopLeftRadius: topLeft,
  149. borderTopRightRadius: topRight,
  150. borderBottomLeftRadius: bottomLeft,
  151. borderBottomRightRadius: bottomRight
  152. };
  153. }
  154. global.ui = StyleSheet.create({
  155. container: {
  156. flex: 1,
  157. backgroundColor: pageBackground
  158. },
  159. flex: {
  160. flexDirection: 'row'
  161. },
  162. flexc: {
  163. alignItems: 'center',
  164. flexDirection: 'row'
  165. },
  166. flexcc: {
  167. alignItems: 'center',
  168. flexDirection: 'row',
  169. justifyContent: 'center'
  170. },
  171. flexcw: {
  172. alignItems: 'center',
  173. flexDirection: 'row',
  174. justifyContent: 'space-between'
  175. },
  176. flexvc: {
  177. alignItems: 'center',
  178. justifyContent: 'center'
  179. },
  180. flex1: {
  181. flex: 1
  182. },
  183. flex2: {
  184. flex: 2
  185. },
  186. flex3: {
  187. flex: 3
  188. },
  189. flex4: {
  190. flex: 4
  191. },
  192. flex5: {
  193. flex: 5
  194. },
  195. center: {
  196. textAlign: 'center',
  197. alignItems: 'center'
  198. },
  199. right: {
  200. textAlign: 'right',
  201. },
  202. link: {
  203. color: "#0684D4"
  204. },
  205. bold: {
  206. fontWeight: 'bold'
  207. },
  208. underline: {
  209. textDecorationLine: "underline"
  210. },
  211. blackText: {
  212. color: '#000'
  213. },
  214. mainText: {
  215. color: colorAccent
  216. },
  217. button: {
  218. flex: 1,
  219. height: 50,
  220. elevation: 2,
  221. borderRadius: 8,
  222. marginBottom: 8,
  223. alignItems: 'center',
  224. justifyContent: 'center',
  225. backgroundColor: colorAccent
  226. },
  227. buttonMini: {
  228. height: 42,
  229. borderRadius: 6,
  230. paddingLeft: 16,
  231. paddingRight: 16,
  232. alignItems: 'center',
  233. justifyContent: 'center',
  234. backgroundColor: colorAccent
  235. },
  236. buttonText: {
  237. color: textPrimary,
  238. fontSize: 17,
  239. fontWeight: 'bold',
  240. textAlign: 'center',
  241. },
  242. noData: {
  243. color: '#aaa',
  244. fontSize: 12,
  245. padding: 16,
  246. textAlign: 'center'
  247. }
  248. });
  249. /*if (!__DEV__) {
  250. global.console = {
  251. info: () => {},
  252. log: () => {},
  253. warn: () => {},
  254. error: () => {},
  255. };
  256. }*/