| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /**
- * 公共配置文件
- * @邠心vbe on 2021/04/07
- */
- import {
- Dimensions,
- Platform,
- StatusBar,
- StyleSheet,
- NativeModules,
- } from 'react-native';
- import DeviceInfo from 'react-native-device-info';
- import apiUser from '../api/apiUser';
- navigator.geolocation = require('@react-native-community/geolocation');
- global.$width = Dimensions.get('window').width;
- global.$height = Dimensions.get('window').height;
- global.statusHeight = 0;
- global.toolbarSize = 56;
- global.isIOS = Platform.OS == 'ios';
- if (isIOS) {
- const {StatusBarManager} = NativeModules;
- StatusBarManager.getHeight(statusBarHeight => {
- const height = statusBarHeight.height;
- global.toolbarSize = 56 + height;
- global.statusHeight = height;
- });
- global.BRAND = '';
- } else {
- global.statusHeight = StatusBar.currentHeight;
- global.BRAND = DeviceInfo.getBrand().toLowerCase();
- }
- global.currency = '$';
- global.accessToken = '';
- global.startPage = {};
- global.storageSite = [];
- global.userInfo = {
- userPk: -1,
- credit: 0,
- 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(err => {
- console.info('<<<<<-- global.getUserInfo', err);
- })
- }
- } else {
- if (resolve) resolve(global.userInfo)
- }
- }
- global.$vh = percent => {
- return (global.$height * percent) / 100;
- };
- global.$vhs = percent => {
- return (global.$height - global.statusHeight) * percent / 100;
- };
- global.$vht = percent => {
- return (global.$height - global.statusHeight) * percent / 100 - 56;
- };
- global.$vw = percent => {
- return (global.$width * percent) / 100;
- };
- //Theme
- global.colorAccent = '#FFCC2C';
- global.colorPrimary = '#FFCC2C';
- global.colorPrimaryDark = '#FFCC2C';
- 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: 'white'
- },
- 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: '#333',
- fontSize: 17,
- fontWeight: 'bold',
- textAlign: 'center',
- },
- noData: {
- color: '#aaa',
- fontSize: 12,
- padding: 16,
- textAlign: 'center'
- }
- });
- global.ripple = {
- color: 'rgba(0,0,0,.3)'
- }
- global.rippleLess = {
- color: 'rgba(0,0,0,.3)',
- radius: 20,
- borderless: true
- }
- /*if (!__DEV__) {
- global.console = {
- info: () => {},
- log: () => {},
- warn: () => {},
- error: () => {},
- };
- }*/
|