constant.js 5.8 KB

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