constant.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.$width = Dimensions.get('window').width;
  16. global.$height = Dimensions.get('window').height;
  17. global.statusHeight = 0;
  18. global.toolbarSize = 56;
  19. global.isIOS = Platform.OS == 'ios';
  20. if (isIOS) {
  21. const {StatusBarManager} = NativeModules;
  22. StatusBarManager.getHeight(statusBarHeight => {
  23. const height = statusBarHeight.height;
  24. global.toolbarSize = 56 + height;
  25. global.statusHeight = height;
  26. });
  27. global.BRAND = '';
  28. } else {
  29. global.statusHeight = StatusBar.currentHeight;
  30. global.BRAND = DeviceInfo.getBrand().toLowerCase();
  31. }
  32. global.currency = '$';
  33. global.accessToken = '';
  34. global.startPage = {};
  35. global.storageSite = [];
  36. global.userInfo = {
  37. userPk: -1,
  38. credit: 0,
  39. nickname: 'Sign In'
  40. };
  41. global.isLogin = () => {
  42. return global.accessToken !== '';
  43. };
  44. global.getUserId = () => {
  45. return global.userInfo.userPk;
  46. };
  47. global.getUserInfo = (resolve, force) => {
  48. if (isLogin()) {
  49. if (userInfo.userPk > 0 && !force) {
  50. //console.log('-->>>>> 获取用户数据');
  51. if (resolve) resolve(global.userInfo);
  52. } else {
  53. apiUser.getProfile().then(res => {
  54. console.log('-->>>>> global.getUserInfo', res);
  55. if (res.data) {
  56. global.userInfo = res.data;
  57. if (resolve) resolve(res.data);
  58. }
  59. }).catch(err => {
  60. console.info('<<<<<-- global.getUserInfo', err);
  61. })
  62. }
  63. } else {
  64. if (resolve) resolve(global.userInfo)
  65. }
  66. }
  67. global.$vh = percent => {
  68. return (global.$height * percent) / 100;
  69. };
  70. global.$vhs = percent => {
  71. return (global.$height - global.statusHeight) * percent / 100;
  72. };
  73. global.$vht = percent => {
  74. return (global.$height - global.statusHeight) * percent / 100 - 56;
  75. };
  76. global.$vw = percent => {
  77. return (global.$width * percent) / 100;
  78. };
  79. //Theme
  80. global.colorThemes = '#FFFFFF';//#FFFFFF
  81. global.colorAccent = '#A3C93A';
  82. global.colorPrimary = '#001489';
  83. global.colorPrimaryDark = '#FFFFFF';
  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: 'white'
  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: '#333',
  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. global.ripple = {
  240. color: 'rgba(0,0,0,.3)'
  241. }
  242. global.rippleLess = {
  243. color: 'rgba(0,0,0,.3)',
  244. radius: 20,
  245. borderless: true
  246. }
  247. /*if (!__DEV__) {
  248. global.console = {
  249. info: () => {},
  250. log: () => {},
  251. warn: () => {},
  252. error: () => {},
  253. };
  254. }*/