constant.js 5.4 KB

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