|
@@ -0,0 +1,126 @@
|
|
1
|
+import React, { Component } from 'react'
|
|
2
|
+import { Modal, Button, Form, Input, Icon, notification } from 'antd'
|
|
3
|
+import request from '../../utils/request'
|
|
4
|
+import apis from '../../services/apis'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+function passwodForm(props) {
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+ const openNotificationWithIcon = (type, message) => {
|
|
11
|
+ notification[type]({
|
|
12
|
+ message,
|
|
13
|
+ description:
|
|
14
|
+ '',
|
|
15
|
+ });
|
|
16
|
+ }
|
|
17
|
+
|
|
18
|
+ function handleSubmit(e) {
|
|
19
|
+ e.preventDefault();
|
|
20
|
+ props.form.validateFieldsAndScroll((err, values) => {
|
|
21
|
+ // 两次密码比较
|
|
22
|
+ if (values.newPassword !== values.newPasswordToo) {
|
|
23
|
+ openNotificationWithIcon('error', '两次密码输入不一样,请重新输入')
|
|
24
|
+ return
|
|
25
|
+ }
|
|
26
|
+ if (!err) {
|
|
27
|
+ request({ ...apis.user.changePassword, params: { ...values } }).then(() => {
|
|
28
|
+ openNotificationWithIcon('success', '操作成功!')
|
|
29
|
+ props.form.resetFields()
|
|
30
|
+ props.onSuccess()
|
|
31
|
+ }).catch(error => {
|
|
32
|
+ // openNotificationWithIcon('error', error.message)
|
|
33
|
+ })
|
|
34
|
+ }
|
|
35
|
+ });
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ const { getFieldDecorator } = props.form
|
|
39
|
+ return (
|
|
40
|
+ <>
|
|
41
|
+ <Form labelCol={{ span: 7 }} wrapperCol={{ span: 12 }} onSubmit={(e) => handleSubmit(e)}>
|
|
42
|
+ <Form.Item label="请输入旧密码">
|
|
43
|
+ {getFieldDecorator('originalPassword', {
|
|
44
|
+ rules: [{ required: true, message: '请输入旧密码' }],
|
|
45
|
+ })(
|
|
46
|
+ <Input
|
|
47
|
+ prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
|
|
48
|
+ type="password"
|
|
49
|
+ placeholder="Password"
|
|
50
|
+ />,
|
|
51
|
+ )}
|
|
52
|
+ </Form.Item>
|
|
53
|
+ <Form.Item label="新密码">
|
|
54
|
+ {getFieldDecorator('newPassword', {
|
|
55
|
+ rules: [{ required: true, message: '请输入新密码' }],
|
|
56
|
+ })(
|
|
57
|
+ <Input
|
|
58
|
+ prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
|
|
59
|
+ type="password"
|
|
60
|
+ placeholder="Password"
|
|
61
|
+ />,
|
|
62
|
+ )}
|
|
63
|
+ </Form.Item>
|
|
64
|
+ <Form.Item label="确认新密码">
|
|
65
|
+ {getFieldDecorator('newPasswordToo', {
|
|
66
|
+ rules: [{ required: true, message: '请确认新密码' }],
|
|
67
|
+ })(
|
|
68
|
+ <Input
|
|
69
|
+ prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
|
|
70
|
+ type="password"
|
|
71
|
+ placeholder="Password"
|
|
72
|
+ />,
|
|
73
|
+ )}
|
|
74
|
+ </Form.Item>
|
|
75
|
+ <Form.Item>
|
|
76
|
+ <Button type="primary" htmlType="submit">
|
|
77
|
+ 确定
|
|
78
|
+ </Button>
|
|
79
|
+ </Form.Item>
|
|
80
|
+ </Form>
|
|
81
|
+ </>
|
|
82
|
+ )
|
|
83
|
+}
|
|
84
|
+
|
|
85
|
+const WrappedShowPasswordForm = Form.create({ name: 'passwodForm' })(passwodForm)
|
|
86
|
+
|
|
87
|
+export default class ShowPassword extends Component {
|
|
88
|
+
|
|
89
|
+ constructor(props) {
|
|
90
|
+ super(props)
|
|
91
|
+ this.state = { visible: false }
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ componentDidUpdate(prevProps) {
|
|
95
|
+ // 典型用法(不要忘记比较 props):
|
|
96
|
+ console.log('接收值: ', this.props.visible, prevProps.visible)
|
|
97
|
+ if (this.props.visible !== prevProps.visible) {
|
|
98
|
+ // eslint-disable-next-line react/no-did-update-set-state
|
|
99
|
+ this.setState({ visible: this.props.visible })
|
|
100
|
+ }
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ handleOk = e => {
|
|
104
|
+ console.log('关闭了')
|
|
105
|
+ this.props.onCancel()
|
|
106
|
+ };
|
|
107
|
+
|
|
108
|
+ handleCancel = e => {
|
|
109
|
+ console.log('关闭了')
|
|
110
|
+ this.props.onCancel()
|
|
111
|
+ };
|
|
112
|
+
|
|
113
|
+ render() {
|
|
114
|
+ return (
|
|
115
|
+ <>
|
|
116
|
+ <Modal
|
|
117
|
+ title="修改密码"
|
|
118
|
+ visible={this.state.visible}
|
|
119
|
+ onCancel={this.handleCancel}
|
|
120
|
+ footer={null}>
|
|
121
|
+ <WrappedShowPasswordForm onSuccess={(e) => this.handleCancel(e)} />
|
|
122
|
+ </Modal>
|
|
123
|
+ </>
|
|
124
|
+ );
|
|
125
|
+ }
|
|
126
|
+}
|