Explorar o código

add app/utils/constant.js

wudebin hai 6 meses
pai
achega
c26affc3d1
Modificáronse 1 ficheiros con 279 adicións e 0 borrados
  1. 279 0
      Strides-SPAPP/app/utils/constant.js

+ 279 - 0
Strides-SPAPP/app/utils/constant.js

@@ -0,0 +1,279 @@
+/**
+ * 公共配置文件
+ * @邠心vbe on 2021/04/07
+ */
+import {
+  Text,
+  TextInput,
+  Dimensions,
+  Platform,
+  StatusBar,
+  StyleSheet,
+  NativeModules,
+} from 'react-native';
+import DeviceInfo from 'react-native-device-info';
+import apiUser from '../api/apiUser';
+import geolocation from '@react-native-community/geolocation';
+
+navigator.geolocation = geolocation;
+
+global.isIOS = Platform.OS == 'ios';
+
+global.$width = Dimensions.get('window').width;
+global.$height = Dimensions.get('window').height;
+global.$screen = Dimensions.get('screen').height;
+global.statusHeight = isIOS ? 0 : StatusBar.currentHeight;
+global.toolbarSize = isIOS ? 50 : 56;
+global.navbarHeight = 0;
+if (isIOS) {
+  const {StatusBarManager} = NativeModules;
+  StatusBarManager.getHeight(statusBarHeight => {
+    const height = statusBarHeight.height;
+    //global.toolbarSize = toolbarSize + height;
+    global.statusHeight = height;
+  });
+  global.BRAND = '';
+} /*else {
+  global.statusHeight = StatusBar.currentHeight;
+  global.BRAND = DeviceInfo.getBrand().toLowerCase();
+}*/
+
+if (Text.defaultProps == null)
+  Text.defaultProps = {};
+Text.defaultProps.allowFontScaling = false;
+
+if (TextInput.defaultProps == null)
+  TextInput.defaultProps = {};
+TextInput.defaultProps.allowFontScaling = false;
+
+global.currency = "";//'$';
+global.accessToken = '';
+global.startPage = {};
+global.storageSite = [];
+global.chargeInfoState = {};
+
+global.userInfo = {
+  userPk: -1,
+  credit: 0,
+  userType: "Public",
+  nickname: 'Sign In'
+};
+
+global.isLogin = () => {
+  return global.accessToken !== '';
+};
+
+global.getUserId = () => {
+  return global.userInfo.userPk;
+};
+
+global.getUserInfo = (resolve, force) => {
+  if (isLogin()) {
+    if (userInfo.userPk > 0 && !force) {
+      //console.log('-->>>>> 获取用户数据');
+      if (resolve) resolve(global.userInfo);
+    } else {
+      apiUser.getProfile().then(res => {
+        console.log('-->>>>> global.getUserInfo', res);
+        if (res.data) {
+          global.userInfo = res.data;
+          if (resolve) resolve(res.data);
+        }
+      }).catch(erros => {
+        console.info('<<<<<-- global.getUserInfo', erros);
+      })
+    }
+  } else {
+    if (resolve) resolve(global.userInfo)
+  }
+}
+
+global.$vh = percent => {
+  return (global.$height * percent) / 100;
+};
+
+global.$vhs = percent => {
+  return global.$height * percent / 100 - global.statusHeight;
+};
+
+global.$vht = percent => {
+  return global.$height * percent / 100 - toolbarSize;
+};
+
+global.$vhts = percent => {
+  return global.$height * percent / 100 - toolbarSize - global.statusHeight;
+};
+
+global.$vw = percent => {
+  return (global.$width * percent) / 100;
+};
+
+global.$padding = (top, right, bottom, left) => {
+  if (top == undefined) {
+    return {};
+  }
+  if (right == undefined) {
+    right = top;
+  }
+  if (bottom == undefined) {
+    bottom = top;
+  }
+  if (left == undefined) {
+    left = right;
+  }
+  
+  return {
+    paddingTop: top,
+    paddingLeft: left,
+    paddingRight: right,
+    paddingBottom: bottom
+  };
+}
+
+global.$margin = (top, right, bottom, left) => {
+  if (top == undefined) {
+    return {};
+  }
+  if (right == undefined) {
+    right = top;
+  }
+  if (bottom == undefined) {
+    bottom = top;
+  }
+  if (left == undefined) {
+    left = right;
+  }
+  return {
+    marginTop: top,
+    marginLeft: left,
+    marginRight: right,
+    marginBottom: bottom
+  };
+}
+
+global.$borderRadius = (topLeft, topRight, bottomRight, bottomLeft) => {
+  if (topLeft == undefined) {
+    return {};
+  }
+  if (topRight == undefined) {
+    topRight = topLeft;
+  }
+  if (bottomRight == undefined) {
+    bottomRight = topLeft;
+  }
+  if (bottomLeft == undefined) {
+    bottomLeft = topRight;
+  }
+  return {
+    borderTopLeftRadius: topLeft,
+    borderTopRightRadius: topRight,
+    borderBottomLeftRadius: bottomLeft,
+    borderBottomRightRadius: bottomRight
+  };
+}
+
+global.ui = StyleSheet.create({
+  container: {
+    flex: 1,
+    backgroundColor: pageBackground
+  },
+  flex: {
+    flexDirection: 'row'
+  },
+  flexc: {
+    alignItems: 'center',
+    flexDirection: 'row'
+  },
+  flexcc: {
+    alignItems: 'center',
+    flexDirection: 'row',
+    justifyContent: 'center'
+  },
+  flexcw: {
+    alignItems: 'center',
+    flexDirection: 'row',
+    justifyContent: 'space-between'
+  },
+  flexvc: {
+    alignItems: 'center',
+    justifyContent: 'center'
+  },
+  flex1: {
+    flex: 1
+  },
+  flex2: {
+    flex: 2
+  },
+  flex3: {
+    flex: 3
+  },
+  flex4: {
+    flex: 4
+  },
+  flex5: {
+    flex: 5
+  },
+  center: {
+    textAlign: 'center',
+    alignItems: 'center'
+  },
+  right: {
+    textAlign: 'right',
+    
+  },
+  link: {
+    color: "#0684D4"
+  },
+  bold: {
+    fontWeight: 'bold'
+  },
+  underline: {
+    textDecorationLine: "underline"
+  },
+  blackText: {
+    color: '#000'
+  },
+  mainText: {
+    color: colorAccent
+  },
+  button: {
+    flex: 1,
+    height: 50,
+    elevation: 2,
+    borderRadius: 8,
+    marginBottom: 8,
+    alignItems: 'center',
+    justifyContent: 'center',
+    backgroundColor: colorAccent
+  },
+  buttonMini: {
+    height: 42,
+    borderRadius: 6,
+    paddingLeft: 16,
+    paddingRight: 16,
+    alignItems: 'center',
+    justifyContent: 'center',
+    backgroundColor: colorAccent
+  },
+  buttonText: {
+    color: textPrimary,
+    fontSize: 17,
+    fontWeight: 'bold',
+    textAlign: 'center',
+  },
+  noData: {
+    color: '#aaa',
+    fontSize: 12,
+    padding: 16,
+    textAlign: 'center'
+  }
+});
+
+/*if (!__DEV__) {
+  global.console = {
+    info: () => {},
+    log: () => {},
+    warn: () => {},
+    error: () => {},
+  };
+}*/