AssistantContainer.js
14.3 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { Row, Col, Progress, Button, notification, Layout, Menu, Dropdown, Tooltip, Icon, Input, Badge, Tabs, Popover } from 'antd';
import cx from 'classnames';
import s from './main.les';
import { PermissionContent } from '../components/widget/PermissionLabel';
import SystemMenu from '../components/SystemMenu';
import { loadUserInfo, modifyTenant, getPermissionAction } from '../redux/actions/authed';
import { clearServiceContractsList, loadServiceContractsList, loadDepartmentNameAction } from '../redux/actions/custome'
import { loadOrganizations, loadPositions, loadTenants, getAppNameAction } from '../redux/actions/hr';
import { loadUnreadMessage, finishAllMessages, finishNotification } from '../redux/actions/notification'
import { loadSysperms, getBasicInfoAction, loadActionSysperms } from '../redux/actions/settingAction';
import { getIMToken } from '../redux/actions/workIMAction';
import { OSSURL } from '../redux/constants/Constants';
import { gotoPageByNotification } from '../utils/commonUtils';
import { menuLinkMap } from '../utils/sysMenuUtil';
import RongClundWrap from '../components/widget/RongClundWrap';
import moment from 'moment';
import CustomScrollbars from '../components/widget/CustomScrollbars';
import { loadTenantType } from './../redux/actions/contract'
const { Header, Sider, Content } = Layout;
const Search = Input.Search;
const SubMenu = Menu.SubMenu;
const TabPane = Tabs.TabPane;
moment.locale('zh-cn', {
meridiem: function (hour, minute, isLowercase) {
if (hour < 9) {
return "早上";
} else if (hour < 11 && minute < 30) {
return "上午";
} else if (hour < 13 && minute < 30) {
return "中午";
} else if (hour < 18) {
return "下午";
} else {
return "晚上";
}
}
});
const backperms = (perms = [], key) => {
let flag = true;
if (key instanceof Array) {
key.map((k, j) => {
if (perms)
perms.map((perm, i) => {
perm.name == k ? flag = false : '';
})
})
} else
if (perms)
perms.map((perm, i) => {
perm.name == key ? flag = false : '';
})
return flag;
}
class AssistantContainer extends React.Component {
constructor(props) {
super(props);
this.backMenu = this.backMenu.bind(this);
this.changeOpenSubMenu = this.changeOpenSubMenu.bind(this);
this.getUnreadMessage = this.getUnreadMessage.bind(this);
this.state = {
collapsed: false,
mode: 'inline',
active: '',
defaultSelectedKeys: '1',
defaultOpenKeys: '',
imageUrl: '',
userImage: '',
logoImage: ''
}
}
componentWillMount() {
}
componentDidMount() {
const { dispatch, location: { pathname }, userInfo, time } = this.props;
// dispatch(getIMToken());
dispatch(loadOrganizations());
dispatch(loadUserInfo());
dispatch(loadUnreadMessage())
dispatch(loadSysperms());
dispatch(loadTenants());
dispatch(loadActionSysperms());
dispatch(loadTenantType());
dispatch(getPermissionAction());
dispatch(getAppNameAction());
dispatch(loadDepartmentNameAction())
const { tenant = {}, user = {} } = userInfo;
if (tenant && tenant.id) {
dispatch(getBasicInfoAction(tenant.id));
this.setState({
userImage: `https://${window.oss.public_bucket}.${window.oss.end_point}/user_image/users/${user.id}?t=${time}`,
logoImage: `https://${window.oss.public_bucket}.${window.oss.end_point}/tenant_logo/tenants/${tenant.id}?t=${time}`
})
}
this.backMenu(pathname);
}
componentWillReceiveProps(nextProps) {
const { dispatch, time } = nextProps;
const old_time = this.props.time;
const old_userInfo = this.props.userInfo;
const old_tenant = old_userInfo ? old_userInfo.tenant : undefined;
const new_userInfo = nextProps.userInfo;
const new_tenant = new_userInfo ? new_userInfo.tenant : undefined;
if (old_tenant && new_tenant && old_tenant.id != new_tenant.id || old_time != time) {
dispatch(getBasicInfoAction(new_tenant.id))
this.setState({
userImage: `https://${window.oss.public_bucket}.${window.oss.end_point}/user_image/users/${new_userInfo.user.id}?t=${time}`,
logoImage: `https://${window.oss.public_bucket}.${window.oss.end_point}/tenant_logo/tenants/${new_userInfo.tenant.id}?t=${time}`
})
}
if (new_tenant && new_tenant.id && new_userInfo && new_userInfo.user && new_userInfo.user) {
document.title = new_tenant.name
this.setState({
userImage: `https://${window.oss.public_bucket}.${window.oss.end_point}/user_image/users/${new_userInfo.user.id}?t=${time}`,
logoImage: `https://${window.oss.public_bucket}.${window.oss.end_point}/tenant_logo/tenants/${new_userInfo.tenant.id}?t=${time}`
})
}
}
componentWillUnmount() {
}
changeOpenSubMenu(openKeys) {
console.log(openKeys);
if (openKeys.length > 0) {
this.setState({
defaultOpenKeys: openKeys[1]
})
} else {
this.setState({
defaultOpenKeys: []
})
}
}
readAllMessages(values) {
const { dispatch } = this.props;
dispatch(finishAllMessages(values));
}
readNotification(id, item) {
const { dispatch } = this.props;
gotoPageByNotification(item);
dispatch(finishNotification(id))
}
getUnreadMessage(data) {
let obj = {};
let temp = [];
if (data && data.length) {
data.map((item, i) => {
temp.push(item.id)
})
}
obj.message_ids = temp;
return (
<div className={cx(s.hover_message)}>
<div className={cx(s.top_wrap)}>
<h5 style={{ display: 'inline-block', float: 'left', marginLeft: 8, marginTop: 4 }}>消息</h5>
{data && data.length > 0 ?
<h5 style={{ cursor: 'pointer', display: 'inline-block', float: 'right', marginRight: 8 }} onClick={this.readAllMessages.bind(this, obj)}>全部标记为已读</h5>
: null
}
</div>
{data && data.length > 0 ?
data.map((item, i) => {
return (
<div className={cx(s.content_wrap)} key={i} onClick={this.readNotification.bind(this, item.id, item)} >
<Tooltip title={item.subject}>
<span style={{ display: 'inline-block', width: '396', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{item.subject}</span>
<span style={{ position: 'absolute', width: 8, height: 8, display: 'inline-block', borderRadius: 4, background: 'red', right: 8, top: 16 }}></span>
</Tooltip>
</div>
)
})
:
<div className={cx(s.empty_content_wrap)}>暂时没有新消息哦</div>
}
<div className={cx(s.bottom_wrap)}>
<a href="#/main/notification"> 查看更多</a>
</div>
</div>
)
}
backMenu(pathname) {
let key = '1', subkey = '';
const { dispatch } = this.props;
if (pathname.indexOf('container/home') != -1) {
key = '1';
subkey = '';
} else if (pathname.indexOf('container/customer') != -1) {
key = '2';
subkey = 'sub1';
} else if (pathname.indexOf('container/customService') != -1) {
key = '3';
subkey = 'sub1';
} else if (pathname.indexOf('container/provider') != -1) {
key = '4';
subkey = '';
} else if (pathname.indexOf('container/employee') != -1) {
key = '5';
subkey = '';
} else if (pathname.indexOf('container/newRecruit') != -1) {
key = '6';
subkey = 'sub2';
} else if (pathname.indexOf('container/empServer') != -1) {
key = '7';
subkey = '';
} else if (pathname.indexOf('container/report') != -1) {
key = '8';
subkey = '';
} else if (pathname.indexOf('container/report') != -1) {
key = '9';
subkey = '';
} else if (pathname.indexOf('container/setting/change-password') != -1) {
key = '20';
subkey = 'sub5';
} else if (pathname.indexOf('container/setting/my-avatar') != -1) {
key = '19';
subkey = 'sub5';
} else if (pathname.indexOf('container/setting') != -1) {
key = '10';
subkey = '';
}
this.setState({
defaultSelectedKeys: key,
defaultOpenKeys: subkey
})
}
changeTenant(value) {
const { dispatch, tenants } = this.props;
const temp = {}
tenants.map((item, i) => {
temp[item.id] = item.name
})
const name = temp[value.key];
dispatch(modifyTenant(value.key, name));
this.setState({
visible: false
});
}
onError() {
this.setState({
imageUrl: "./img/WORKAI2.png"
})
}
changeMenu(menu) {
const { item, key, selectedKeys } = menu;
document.location.href = menuLinkMap[key];
}
render() {
const { collapsed, active, imageUrl, userImage, logoImage, visible, smode } = this.state;
const { userInfo, tenants, time, logo, dispatch, perms, unreadList, height } = this.props;
const { user = {}, tenant = {} } = userInfo;
let imgPath = imageUrl;
if (logo && logo.object_id && !imageUrl) { imgPath = "//" + logo.bucket + "." + window.oss.end_point + logo.object + '?t=' + time; }
return (
<Layout style={{ minHeight: '100vh', background: '#f3f6f8', position: 'absolute', width: '100%' }} id='main_left_menu'>
<Header className={cx('main_header')} >
{(tenant.biz_type == '0' || tenant.biz_type == '1') &&
<div className="sider-menu-item" style={{ display: 'inline-block', height: '54px', minWidth: '70px', overflow: 'hidden' }}>
<img onError={() => { this.setState({ logoImage: './img/menuicon/logoIcon.png' }) }} src={logoImage} style={{ width: 'auto', width: '60px' }} alt="" />
</div>}
<div style={{ display: 'inline-block', height: '54px', overflow: 'hidden' }}>
<img src={'./img/内容.png'} style={{ width: 'auto', width: '20px' }} alt="" onClick={() => {
this.setState({
collapsed: !collapsed,
})
}} />
</div>
<div style={{ display: 'inline-block', float: 'right', height: '62px' }}>
<a className={cx(s.infor_btn)} style={{ marginRight: 4, marginLeft: 4 }}>
<Popover content={this.getUnreadMessage(unreadList)} trigger="click">
<span>
{unreadList && unreadList.length > 0 ?
<span style={{ position: 'relative' }}>
<span style={{ position: 'absolute', width: 6, height: 6, display: 'inline-block', borderRadius: 4, background: 'red', right: 8, top: 0 }}></span>
<img src='./img/menuicon/bellIcon.png' style={{ marginRight: 8, width: 12 }}></img>
</span>
:
<img src='./img/menuicon/bellIcon.png' style={{ marginRight: 8, width: 12 }}></img>}
消息
</span>
</Popover>
</a>
<span className={cx(s.divider, "ant-divider")} />
<Popover placement="bottomRight" title={''} onVisibleChange={(visible) => {
console.log(visible);
}} content={
<Menu mode="vertical" style={{ borderRight: '1px solid transparent' }} onClick={this.changeMenu.bind(this)}>
<Menu.Item key="percenter_changeimg">更改头像</Menu.Item>
<Menu.Divider />
<Menu.Item key="percenter_pwdsetting">修改密码</Menu.Item>
<Menu.Divider />
<Menu.Item key="logout">退出登录</Menu.Item>
</Menu>} trigger="hover">
<span className={cx(s.out_btn)} href={"javascrpit:;"/*"/signOut"*/} style={{ marginLeft: 4, cursor: 'pointer' }}>
<img onError={() => { this.setState({ userImage: './img/招聘头像.png' }) }} src={userImage}
alt="" style={{ width: '25px', height: '25px', margin: '0px 8px 0 0', position: 'relative', borderRadius: '50%' }} />
<span style={{ marginRight: '8px' }}>{user.name}</span>
<Icon type="down" />
</span>
</Popover>
</div>
</Header>
<Layout style={{ height: '100%', background: '#fff' }}>
<Sider trigger={null} collapsible collapsed={collapsed} style={{ background: '#FBFBFC', minHeight: '100%', zIndex: 1000 }} width={202}>
<SystemMenu location={this.props.location} collapsed={collapsed} ></SystemMenu>
<div className={cx(s.select_tenant_wrap)}>
<div className={cx(s.infor_btn)} style={{ display: 'inline-block', height: '62px', verticalAlign: 'top', color: '#fff' }}>
<Popover placement="rightBottom" title={''} content={
<Menu mode="vertical" style={{ borderRight: '1px solid transparent' }} onClick={this.changeTenant.bind(this)}>
{tenants.map((tenant, i) => {
return (
<Menu.Item key={tenant.id}>{tenant.name}</Menu.Item>
)
})}
</Menu>} trigger="click" visible={visible} onVisibleChange={(visible) => {
this.setState({
visible
})
}}>
<span style={{ cursor: 'pointer', color: "#6C7596" }}>{tenant.name}<span style={{ cursor: 'pointer', paddingLeft: '8px' }}><Icon type="right" /></span></span>
</Popover>
</div>
</div>
</Sider>
<Content style={{ margin: '15px', minHeight: 280, maxHeight: height - 54 - 30, position: 'relative', overflow: 'auto' }}>
<CustomScrollbars customName='main_scroll_bar' viewStyle={{ paddingRight: '10px', background: '#fff' }}>
<PermissionContent>
{this.props.children}
</PermissionContent>
</CustomScrollbars>
{/* <RongClundWrap></RongClundWrap> */}
</Content>
</Layout>
</Layout>
)
}
}
const mapState = (state) => {
const {
authed: { userInfo, userInfo: { perms = [] }, time, tenant },
hr: { tenants = [] },
setting: { height, width, basicInfo: { logo = {} } },
notification: { unreadList, unreadListCount }
} = state;
return {
userInfo,
unreadList,
tenants,
time,
logo,
perms,
tenant,
height,
width
}
};
export default connect(mapState)(AssistantContainer);