/
App.jsx
105 lines (86 loc) · 2.45 KB
/
App.jsx
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from 'react';
import { History } from 'react-router'
import cookie from 'react-cookie';
import { message, Menu, Link } from 'antd';
import { tokenKey, sideMenus } from 'data/config';
import { httpGet } from 'data/api';
import NavGlobal from './nav/NavGlobal.jsx';
import NavMenu from './nav/NavMenu.jsx';
function signOut(e) {
cookie.remove(tokenKey);
}
const topMenu = [
{key: "2", href:"/user/change_password", label: "修改密码"},
{key: "-1", divider: true},
{key: "3", href:"/signin", onClick: signOut, iconClass: "fa fa-fw fa-sign-out", label: "注销"},
];
const user = {
name: '某某用户',
role: {
name: 'customer'
}
};
const App = React.createClass({
displayName: 'App',
mixins: [ History ],
getInitialState() {
/* return {user: undefined}; */
return {
user: {
name: 'Test user',
role: {
name: 'user',
descr: 'Test role descr',
}
}
};
},
componentDidMount(){
console.log('NavGlobal:componentDidMount');
},
render() {
console.log('App.props:', this.props);
if (cookie.load(tokenKey) === undefined) {
console.log('X-Token is missing!');
/* message.error('请先登录系统!');
this.history.pushState(null, '/signin'); */
}
console.log('current user:', this.state.user);
const navMenu = this.state.user ? <NavMenu sideMenu={sideMenus[this.state.user.role.name]} /> : '';
return (
<div className="app-container">
<div className="app-viewport">
<NavGlobal user={this.state.user} topMenu={topMenu} />
{navMenu}
<div className="content">
{this.props.children}
</div>
</div>
</div>
);
},
});
/* Global pages */
import Signin from 'page/common/Signin.jsx';
import Signup from 'page/common/Signup.jsx';
import Blank from 'page/common/Blank.jsx';
import Err404 from 'page/common/Err404.jsx';
/* Sub pages */
import ChangePassword from 'page/common/ChangePassword.jsx';
import TestForms from 'page/demo/TestForms.jsx';
export const routes = [
{ path: '/signin', component: Signin },
{ path: '/signup', component: Signup },
{
path: '/',
component: App,
indexRoute: { component: Blank },
childRoutes: [
/* Common */
{path: '/demo/test_forms', component: TestForms},
{path: '/user/change_password', component: ChangePassword},
/* Others */
{path: '*', component: Err404},
]
},
]