SystemMenu.js
4.5 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { Button, Tabs, Menu, Icon } from 'antd';
import cx from 'classnames';
import s from './systemMenuLess.les';
import { doLogin, sendQuickLoginSmsCode } from '../redux/actions/authed';
import { clearServiceContractsList, loadServiceContractsList } from '../redux/actions/custome';
import { loadUnreadMessage, finishAllMessages, finishNotification } from '../redux/actions/notification'
import { providerMenus, menuLinkMap, menuIconMap, getMenuKeyByPath } from '../utils/sysMenuUtil';
import CustomScrollbars from './widget/CustomScrollbars';
const SubMenu = Menu.SubMenu;
class SystemMenu extends React.Component {
constructor(props) {
super(props);
this.changeMenu = this.changeMenu.bind(this);
this.onCollapse = this.onCollapse.bind(this);
this.changeOpenSubMenu = this.changeOpenSubMenu.bind(this);
this.state = {
collapsed: false,
mode: 'inline',
active: '',
defaultSelectedKeys: '',
defaultOpenKeys: '',
imageUrl: '',
userImage: '',
logoImage: ''
}
}
componentDidMount() {
const { location } = this.props;
const defaultSelectedKeys = getMenuKeyByPath(location.pathname);
this.setState({
defaultSelectedKeys
})
}
componentWillReceiveProps(nextProps) {
}
componentWillUnmount() {
}
changeOpenSubMenu(openKeys) {
if (openKeys.length > 0) {
this.setState({
defaultOpenKeys: openKeys[1]
})
} else {
this.setState({
defaultOpenKeys: []
})
}
}
onCollapse(collapsed) {
this.setState({
collapsed,
mode: collapsed ? 'vertical' : 'inline',
});
}
changeMenu(menu) {
const { item, key, selectedKeys } = menu;
const { dispatch } = this.props;
// dispatch(clearServiceContractsList());
document.location.href = menuLinkMap[key];
this.setState({
defaultSelectedKeys: key
})
dispatch(loadUnreadMessage())
}
render() {
let { menus, userInfo, height, width, collapsed } = this.props;
const { user = {}, tenant = {} } = userInfo;
const { active, imageUrl, userImage, logoImage, defaultSelectedKeys, defaultOpenKeys } = this.state;
const renderSubMenu = (subMenus) => {
return subMenus.map((subMenu, i) => {
return (
<Menu.Item key={subMenu.module}>
<span>{subMenu.display_name}</span>
{
subMenu && subMenu.is_beta && subMenu.is_beta == 'y' &&
<span style={{ color: 'rgba(153, 169, 191,0.6)' }}>( 试用 )</span>
}
</Menu.Item>
)
});
}
if (tenant.biz_type != 0) {
menus = providerMenus;
}
if (tenant.biz_type == '0' || tenant.biz_type == '1') {
return (
<div className={cx(s.system_menu_wrap, 'system_menu_wrap')} style={{ height: height - 160 }}>
<CustomScrollbars viewStyle={{ paddingRight: '10px' }} theme="white">
<Menu theme="light" mode={'inline'} onClick={this.changeMenu}
inlineCollapsed={this.props.collapsed}
onOpenChange={this.changeOpenSubMenu}
style={{ borderRight: '1px solid transparent', backgroundColor: '#fff' }}
selectedKeys={[defaultSelectedKeys]} openKeys={[defaultOpenKeys]}>
{menus && menus.map((menu, i) => {
if (menu.children) {
return (
<SubMenu key={menu.module} title={
<span>
<img
style={{ width: '20px', position: 'relative', top: '-2px', right: '5px' }}
src={menuIconMap[menu.module]} alt="" />
<span>{collapsed ? '' : menu.display_name}</span>
</span>
}>
{renderSubMenu(menu.children)}
</SubMenu>
)
} else {
return (
<Menu.Item key={menu.module} >
<img
style={{ width: '20px', position: 'relative', top: '-2px', right: '5px' }}
src={menuIconMap[menu.module]} alt="" />
<span>{menu.display_name}</span>
{/* 自然人税收 new图标 */}
{menu && menu.module && menu.module == 'persontax' && <span className={cx(s.menu_new)}></span>}
</Menu.Item>
)
}
})}
</Menu>
</CustomScrollbars>
</div>
)
} else {
return (
<div className={cx(s.system_menu_wrap, 'system_menu_wrap')} style={{ height: '100vh' }}>
</div>
)
}
}
}
const mapState = (state) => {
const {
authed: { userInfo, userInfo: { perms = [], menus = [] }, tenant },
hr: { tenants = [] },
setting: { height, width }
} = state;
return {
userInfo,
tenants,
perms,
tenant,
menus,
height,
width
}
};
export default connect(mapState)(SystemMenu);