constant.js 5.5 KB

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