-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathindex.js
More file actions
112 lines (101 loc) · 2.96 KB
/
index.js
File metadata and controls
112 lines (101 loc) · 2.96 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
import React, { PureComponent } from 'react';
import '@ant-design/compatible/assets/index.css';
import { Form, Input, Modal, message } from 'antd';
import { updatePwd } from '@/services/login';
import { md5Hash } from '../../utils/utils';
class UpdatePasswordDialog extends PureComponent {
formRef = React.createRef();
state = {
submitting: false,
};
onOKClick = () => {
this.formRef.current
.validateFields()
.then(values => {
if (values.new_password !== values.confirm_new_password) {
message.warning('新密码与确认新密码不一致!');
return;
}
this.setState({ submitting: true });
const formData = {
old_password: md5Hash(values.old_password),
new_password: md5Hash(values.new_password),
};
updatePwd(formData).then(res => {
if (res.status === 'OK') {
message.success('密码更新成功!');
this.handleCancel();
}
this.setState({ submitting: false });
});
})
.catch(err => {
console.log(' ----- === err :', err);
this.setState({ submitting: false });
});
};
handleCancel = () => {
const { onCancel } = this.props;
if (onCancel) {
onCancel();
}
};
dispatch = action => {
const { dispatch } = this.props;
dispatch(action);
};
render() {
const { visible } = this.props;
const { submitting } = this.state;
const formItemLayout = {
labelCol: {
span: 6,
},
wrapperCol: {
span: 16,
},
};
return (
<Modal
title="修改个人密码"
width={450}
visible={visible}
maskClosable={false}
confirmLoading={submitting}
destroyOnClose
onOk={this.onOKClick}
onCancel={this.handleCancel}
style={{ top: 20 }}
bodyStyle={{ maxHeight: 'calc( 100vh - 158px )', overflowY: 'auto' }}
>
<Form ref={this.formRef} initialValues={{}}>
<Form.Item
{...formItemLayout}
label="旧密码"
name="old_password"
rules={[{ required: true, message: '请输入旧密码' }]}
>
<Input type="password" placeholder="请输入旧密码" />
</Form.Item>
<Form.Item
{...formItemLayout}
label="新密码"
name="new_password"
rules={[{ required: true, message: '请输入新密码' }]}
>
<Input type="password" placeholder="请输入新密码" />
</Form.Item>
<Form.Item
{...formItemLayout}
label="确认新密码"
name="confirm_new_password"
rules={[{ required: true, message: '请输入确认新密码' }]}
>
<Input type="password" placeholder="请输入确认新密码" />
</Form.Item>
</Form>
</Modal>
);
}
}
export default UpdatePasswordDialog;