constant.js 5.2 KB

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