constant.js 5.0 KB

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