-
Notifications
You must be signed in to change notification settings - Fork 13
/
App.js
46 lines (43 loc) · 1.14 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, {Component} from 'react';
import {View} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import Nav from './src/nav';
import Geo from './src/utils/Geo';
import RootStore from './src/mobx';
import {Provider} from 'mobx-react';
import JMessage from './src/utils/JMessage';
import UserStore from './src/mobx/userStore';
class App extends Component {
state = {
isInitGeo: false,
};
async componentDidMount() {
/* 获取缓存中的用户数据 */
const strUserInfo = await AsyncStorage.getItem('userinfo');
const userinfo = strUserInfo ? JSON.parse(strUserInfo) : {};
// 判断有没有token
if (userinfo.token) {
// 把缓存中的数据存到mobx
RootStore.setUserInfo(
userinfo.mobile,
userinfo.token,
userinfo.userId,
);
/* 极光初始化 */
JMessage.init();
}
/* 初始化高德地图 */
await Geo.initGeo();
this.setState({isInitGeo: true});
}
render() {
return (
<View style={{flex: 1}}>
<Provider RootStore={RootStore} UserStore={UserStore}>
{this.state.isInitGeo ? <Nav /> : <></>}
</Provider>
</View>
);
}
}
export default App;