/
index.js
67 lines (58 loc) · 2.15 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, { Fragment } from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import { Modal } from 'antd-mobile';
import { Nav, UserInfo, Footer } from '../../components';
import styles from '../msg/msg.css';
const Alert = Modal.alert;
class Me extends React.PureComponent {
componentDidMount() {
const storageResult = localStorage.getItem('User');
if (storageResult) {
const user = JSON.parse(storageResult);
if (user) {
const { dispatch } = this.props;
dispatch({ type: 'user/getUserData', payload: { userName: user.loginname }});
}
}
}
render() {
if (!localStorage.getItem('User')) {
return (
<div>
<Nav title={'消息'} showBackIcon={false} />
<div className={styles.notLogin}>
您还未登录,请先<a className={styles.loginText} href={'/login'}>登录</a>
</div>
<Footer selectedIndex={3} />
</div>
);
}
const { dispatch, userData } = this.props;
return (
<Fragment>
<Nav title={'个人中心'} showBackIcon={false} showSignOutIcon={true} rightIconFunc={() => {
Alert('退出', '确定退出登录?', [
{ text: '取消', onPress: () => console.log('cancel') },
{
text: '确定', onPress: () => dispatch({
type: 'login/logout', payload: {
cb: () => {
router.replace('/topicList');
}
}
})
},
]);
}}
/>
<UserInfo userData={userData} />
<Footer selectedIndex={3} />
</Fragment>
);
}
}
function mapStateToProps({ user }) {
return { userData: user.userData || {}};
}
export default connect(mapStateToProps)(Me);