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