index.js
14.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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
import React from 'react'
import { Row, Icon, Modal, Button, Form, Input, message,notification } from 'antd'
import axios from '@src/axios'
import { API_USER_MANAGE ,API_SYS_MONITOR , API_SYS_MSG} from '@src/Api'
import { withRouter } from 'react-router-dom';
import Utils from '@src/utils/utils'
import storage from '@src/utils/localStorage'
import SYS_CONFIG from '@src/config/constant.js'
import { NavLink } from 'react-router-dom'
import './index.less'
import { connect } from 'react-redux';
import { saveMsgStatus } from '@src/redux/common/action';
const FormItem = Form.Item
class Header extends React.Component {
state = {
showSetting: 'none',
userName: '',
isShowErrInfo: 'block',
errInfo: '',
msgTipIcon:false,
visible : false,
msgTitle: '',
msgContent: '',
batchId: null
}
componentWillUnmount () {
this.setState = (state, callback) => {
return;
};
}
getMsgContent = () => {
const isOnceLogin = storage.get('isOnceLogin')
const userInfo = storage.get('userInfo')
if (!isOnceLogin && userInfo && userInfo.token) {
this.getWebsocket(userInfo)
axios.ajax({
url: API_SYS_MSG.getSysPcMsgDetail,
data: {
userId: userInfo.id
}
}).then(res => {
if ( res) {
notification.destroy();
const title = res.messageTitle + `<br/><span style="font-size:12px;">${Utils.formateDateToYMD(res.updateTime)}</span>`
const msgCon = res.messageContent ? res.messageContent.replace(/<\/?.+?>/g,"") : '' ;
const msgObj = {
title: res.messageTitle.substring(0, 10),
msgContent: <div>
<div className = "msgContent">{msgCon.substring(0, 50)}...</div>
<div className = "msgLink"> >> <a onClick = {()=>this.getMsgDetail(userInfo)} >点击查看详情</a></div>
</div>,
layerTitle: <div dangerouslySetInnerHTML = {{ __html: title}}></div>,
layerContent: <div dangerouslySetInnerHTML = {{ __html: res.messageContent}}></div>,
batchId : res.id
}
this.setState({
msgTitle: msgObj.layerTitle,
msgContent : msgObj.layerContent,
batchId:msgObj.id
});
const args = {
message: msgObj.title,
description: msgObj.msgContent,
duration: 0,
placement: 'bottomRight',
className: 'msgTip'
};
notification.open(args)
}
})
storage.set('isOnceLogin', true)
}
if ( isOnceLogin && userInfo && userInfo.token) {
this.getWebsocket(userInfo)
}
}
getWebsocket = (userInfo) => {
const url =`${SYS_CONFIG.wxApi}${API_SYS_MSG.asset}/${userInfo.id}`
const ws = new WebSocket(url);
const _this = this
var msgObj = {
title: '',
msgContent: '',
layerTitle: '',
layerContent: '',
msgId : ''
}
ws.onopen = function (e) {
}
ws.onmessage = function (event) {
notification.destroy()
if (event.data.indexOf('code') !== -1) {
var data = JSON.parse(event.data);
var res = data.data;
if (data.code === 0) {
const msgCon = res.messageContent ? res.messageContent.replace(/<\/?.+?>/g,"") : '' ;
const titles = res.messageTitle + `<br/><span style="font-size:12px;">${Utils.formateDateToYMD(res.updateTime)}</span>`
msgObj = {
title: res.messageTitle.substring(0, 10),
msgContent: <div>
<div className = "msgContent">{msgCon.substring(0, 50)}...</div>
<div className = "msgLink"> >> <a onClick = {()=> _this.getMsgDetail(userInfo)} >点击查看详情</a></div>
</div>,
layerTitle: <div dangerouslySetInnerHTML = {{ __html:titles}}></div>,
layerContent: <div dangerouslySetInnerHTML = {{ __html: res.messageContent}}></div>,
batchId : res.batchId
}
_this.setState({
msgTitle: msgObj.layerTitle,
msgContent : msgObj.layerContent,
batchId:msgObj.batchId
});
const args = {
message: msgObj.title,
description: msgObj.msgContent,
duration: 0,
placement: 'bottomRight',
className: 'msgTip'
};
notification.open(args);
_this.getUnReadSysPcMsgDetailCount(userInfo)
}
}
}
ws.onerror = function(msg) {
};
}
getMsgDetail=(userInfo)=>{
axios.ajax({
url: API_SYS_MSG.updateReadStatusByBatchId,
data: {
batchId: this.state.batchId,
userId: userInfo.id
}
}).then(res => {
this.setState({
visible: true
})
notification.destroy();
this.getUnReadSysPcMsgDetailCount(userInfo)
})
}
getUnReadSysPcMsgDetailCount = (userInfo) =>{
//console.log('用户信息',userInfo)
axios.ajax({
url: API_SYS_MSG.getUnReadSysPcMsgDetailCount,
data: {
userId: userInfo.id
}
}).then(res => {
if(res>0){
this.props.saveMsgStatus(true, 'MSGSTATUS')
} else {
this.props.saveMsgStatus(false, 'MSGSTATUS')
}
})
}
componentDidMount() {
let userInfo = storage.get('userInfo')
if (userInfo && Object.keys(userInfo).length !== 0) {
this.setState({
userName: storage.get('userInfo').userName
})
}
let body = document.getElementsByTagName('body')[0]
body.onclick = (e) => {
let setting = document.getElementById('setting')
if (setting === e.target) {
if (this.state.showSetting === 'none') {
this.setState({
showSetting: 'block'
})
} else {
this.setState({
showSetting: 'none'
})
}
} else {
this.setState({
showSetting: 'none'
})
}
}
if (localStorage.userInfo) {
const userInfo = JSON.parse(localStorage.userInfo)
const url =`${SYS_CONFIG.wxApi}${API_SYS_MONITOR.websocket}?userId=${userInfo.id}`
const ws = new WebSocket(url);
ws.onopen = function (e) {
}
ws.onmessage = function (event) {
if (event.data) {
let data = JSON.parse(event.data)
if (data.youAreOut) {
message.error(data.message)
storage.clearToken()
window.location.href = '#/login'
}
}
}
// 实时消息推送
this.getMsgContent()
// 实时查看是否有新消息
this.getUnReadSysPcMsgDetailCount(userInfo)
}
}
showUpdPwd = () => {
this.setState({
showUpdPwd: true
})
}
msgList=()=>{
}
logout = () => {
notification.destroy();
const userInfo = storage.get('userInfo')
if(!userInfo || !userInfo.token){
this.props.history.replace('/login');
}
axios.ajax({
url: API_USER_MANAGE.logout,
}).then(res=>{
storage.remove('isOnceLogin')
storage.remove('btnAuth')
})
this.props.history.push('/login');
storage.clearToken()
}
submit = async (e) => {
e && e.preventDefault();
let data = this.props.form.getFieldsValue();
let userInfo = storage.get('userInfo')
//验证表单
let isflag = await this.checkPwd()
//console.log(isflag);
if(!isflag){
return
}
let confPass = await this.confPass()
//console.log(confPass)
if(isflag && confPass){
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
//console.log(data);
axios.ajax({
url: API_USER_MANAGE.updPassword,
data: {
...data,
userId: userInfo.id
}
}).then(res => {
if (res) {
message.success('修改成功');
this.setState({
showUpdPwd: false,
isShowErrInfo:'none'
})
// console.log(this.);
storage.clear()
this.props.history.push('/login');
}
})
}
});
}
}
checkPwd = () => {
const data = this.props.form.getFieldsValue()
const { origPass, confPass, password } = data
//console.log(data);
return new Promise((resolve,reject)=>{
if (!origPass || origPass.replace(/^\s+|\s+$/g, '') === '') {
this.setState({
isShowErrInfo: 'block',
errInfo: '请输入原密码'
})
resolve(false)
return false
}
if (!password || password.replace(/^\s+|\s+$/g, '') === '') {
this.setState({
isShowErrInfo: 'block',
errInfo: '请输入新密码'
})
resolve(false)
return false
}
if (!confPass || confPass.replace(/^\s+|\s+$/g, '') === '') {
this.setState({
isShowErrInfo: 'block',
errInfo: '请输入确认密码'
})
resolve(false)
return false
}
if (password !== confPass) {
this.setState({
isShowErrInfo: 'block',
errInfo: '密码不一致'
})
resolve(false)
return false
}
resolve(true)
})
}
password =(e)=>{
const userInfo = this.props.form.getFieldsValue()
const { confPass, password } = userInfo
//console.log(e)
if (e && e.keyCode === 32 && password) {
this.props.form.setFieldsValue({ password: password.replace(/^\s+|\s+$/g, '') })
}
if(!confPass || confPass.replace(/^\s+|\s+$/g, '') === ''){
return false
}
if (password !== confPass) {
this.setState({
isShowErrInfo: 'block',
errInfo: '密码不一致'
})
return false
}else{
this.setState({
isShowErrInfo: 'none',
})
return true
}
}
//确认密码
confPass = (e)=>{
const data = this.props.form.getFieldsValue()
const {confPass, password } = data
//console.log(e)
if (e && e.keyCode === 32 && confPass) {
this.props.form.setFieldsValue({ confPass: confPass.replace(/^\s+|\s+$/g, '') })
}
if (password !== confPass) {
this.setState({
isShowErrInfo: 'block',
errInfo: '密码不一致'
})
return false
}else{
this.setState({
isShowErrInfo: 'none',
})
return true
}
}
render() {
const { getFieldDecorator } = this.props.form;
const { isShowErrInfo, errInfo } = this.state
const formItemLayout = {
labelCol: {
xs: 24,
sm: 8
},
wrapperCol: {
xs: 24,
sm: 16
}
}
return (
<div className='header'>
<Row>
<div className='banner'>
<img src={require('../../resource/assets/images/banner.jpg')} alt="" />
<span className='title'>保险业务核心系统</span>
<div className='login'>
<img src={require('../../resource/assets/images/login.svg')} alt="" />
<span className="userName">{this.state.userName}</span>
</div>
<NavLink replace to={'/home/msgpush/msgList'} className='message'>
<div className="msgTipCircle">
{this.props.msgStatus ?<i className="circle"></i>:''}
<img src={require('../../resource/assets/images/notice.svg')} alt="" />
</div>
<span className="userName">
系统通知
</span>
<div id='setMsg' ></div>
</NavLink>
<div onClick={this.setting} className='logout'>
<img src={require('../../resource/assets/images/setting.svg')} alt="" />
<span className="userName">系统设置</span>
<div id='setting' ></div>
</div>
<div className="setting" style={{ display: this.state.showSetting }} >
<div onClick={this.showUpdPwd} className="lock" ><i className={` iconfont icon-xiugaimima01 `} ></i> 修改密码</div>
<div onClick={this.logout} ><i className={`updPwd iconfont icon-tuichu `} ></i> 退出登录</div>
</div>
</div>
</Row>
<Modal
title="修改密码"
visible={this.state.showUpdPwd}
width={600}
onCancel={() => {
this.props.form.resetFields()
this.setState({
showUpdPwd: false,
isShowErrInfo:'none'
})
}}
footer={
<Button onClick={this.submit} style={{ width: 400, margin: '0 auto', display: 'block' }} type="primary" className="confirmBtn">提交</Button>
}
>
<Form layout="inline" >
<FormItem style={{ width: '80%' }} label="原密码" {...formItemLayout} >
{
getFieldDecorator('origPass', {
})(
<Input onKeyUp={(e) => { Utils.filterSpace(e, 'origPass',this) }} type='password' placeholder="请输入原密码" />
)
}
</FormItem>
<FormItem style={{ width: '80%' }} label="新密码" {...formItemLayout} >
{
getFieldDecorator('password', {
})(
<Input onKeyUp={this.password} type='password' placeholder="请输入新密码" />
)
}
</FormItem>
<FormItem style={{ width: '80%' }} label="确认密码" {...formItemLayout} >
{
getFieldDecorator('confPass', {
// rules: [{ validator: this.checkPwd }]
})(
<Input onKeyUp={this.confPass} type='password' style={{ width: '100%' }} placeholder="请再次确认密码" />
)
}
<div className="errInfo" style={{ display: isShowErrInfo }} >{errInfo}</div>
</FormItem>
</Form>
</Modal>
<Modal
className="msgDetailModal"
title="Basic Modal"
visible={this.state.visible}
footer = {null}
title = {this.state.msgTitle}
width = {800}
onCancel = { ()=> {
this.setState({visible: false})
}}
>
{this.state.msgContent}
</Modal>
</div>
)
}
}
export default withRouter( connect(state => ({
msgStatus: state.msgStatus
}), {
saveMsgStatus,
})(Form.create()(Header)))