constant.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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.colorAccent = '#FFCC2C';
  81. global.colorPrimary = '#FFCC2C';
  82. global.colorPrimaryDark = '#FFCC2C';
  83. global.$padding = (top, right, bottom, left) => {
  84. if (top == undefined) {
  85. return {};
  86. }
  87. if (right == undefined) {
  88. right = top;
  89. }
  90. if (bottom == undefined) {
  91. bottom = top;
  92. }
  93. if (left == undefined) {
  94. left = right;
  95. }
  96. return {
  97. paddingTop: top,
  98. paddingLeft: left,
  99. paddingRight: right,
  100. paddingBottom: bottom
  101. };
  102. }
  103. global.$margin = (top, right, bottom, left) => {
  104. if (top == undefined) {
  105. return {};
  106. }
  107. if (right == undefined) {
  108. right = top;
  109. }
  110. if (bottom == undefined) {
  111. bottom = top;
  112. }
  113. if (left == undefined) {
  114. left = right;
  115. }
  116. return {
  117. marginTop: top,
  118. marginLeft: left,
  119. marginRight: right,
  120. marginBottom: bottom
  121. };
  122. }
  123. global.$borderRadius = (topLeft, topRight, bottomRight, bottomLeft) => {
  124. if (topLeft == undefined) {
  125. return {};
  126. }
  127. if (topRight == undefined) {
  128. topRight = topLeft;
  129. }
  130. if (bottomRight == undefined) {
  131. bottomRight = topLeft;
  132. }
  133. if (bottomLeft == undefined) {
  134. bottomLeft = topRight;
  135. }
  136. return {
  137. borderTopLeftRadius: topLeft,
  138. borderTopRightRadius: topRight,
  139. borderBottomLeftRadius: bottomLeft,
  140. borderBottomRightRadius: bottomRight
  141. };
  142. }
  143. global.ui = StyleSheet.create({
  144. container: {
  145. flex: 1,
  146. backgroundColor: 'white'
  147. },
  148. flex: {
  149. flexDirection: 'row'
  150. },
  151. flexc: {
  152. alignItems: 'center',
  153. flexDirection: 'row'
  154. },
  155. flexcc: {
  156. alignItems: 'center',
  157. flexDirection: 'row',
  158. justifyContent: 'center'
  159. },
  160. flexcw: {
  161. alignItems: 'center',
  162. flexDirection: 'row',
  163. justifyContent: 'space-between'
  164. },
  165. flexvc: {
  166. alignItems: 'center',
  167. justifyContent: 'center'
  168. },
  169. flex1: {
  170. flex: 1
  171. },
  172. flex2: {
  173. flex: 2
  174. },
  175. flex3: {
  176. flex: 3
  177. },
  178. flex4: {
  179. flex: 4
  180. },
  181. flex5: {
  182. flex: 5
  183. },
  184. center: {
  185. textAlign: 'center',
  186. alignItems: 'center'
  187. },
  188. right: {
  189. textAlign: 'right',
  190. },
  191. link: {
  192. color: "#0684D4"
  193. },
  194. bold: {
  195. fontWeight: 'bold'
  196. },
  197. underline: {
  198. textDecorationLine: "underline"
  199. },
  200. blackText: {
  201. color: '#000'
  202. },
  203. mainText: {
  204. color: colorAccent
  205. },
  206. button: {
  207. flex: 1,
  208. height: 50,
  209. elevation: 2,
  210. borderRadius: 8,
  211. marginBottom: 8,
  212. alignItems: 'center',
  213. justifyContent: 'center',
  214. backgroundColor: colorAccent
  215. },
  216. buttonMini: {
  217. height: 42,
  218. borderRadius: 6,
  219. paddingLeft: 16,
  220. paddingRight: 16,
  221. alignItems: 'center',
  222. justifyContent: 'center',
  223. backgroundColor: colorAccent
  224. },
  225. buttonText: {
  226. color: '#333',
  227. fontSize: 17,
  228. fontWeight: 'bold',
  229. textAlign: 'center',
  230. },
  231. noData: {
  232. color: '#aaa',
  233. fontSize: 12,
  234. padding: 16,
  235. textAlign: 'center'
  236. }
  237. });
  238. global.ripple = {
  239. color: 'rgba(0,0,0,.3)'
  240. }
  241. global.rippleLess = {
  242. color: 'rgba(0,0,0,.3)',
  243. radius: 20,
  244. borderless: true
  245. }
  246. /*if (!__DEV__) {
  247. global.console = {
  248. info: () => {},
  249. log: () => {},
  250. warn: () => {},
  251. error: () => {},
  252. };
  253. }*/