傅行帆 преди 5 години
родител
ревизия
b169fc2020
променени са 2 файла, в които са добавени 287 реда и са изтрити 0 реда
  1. 131
    0
      src/components/GlobalHeader/ShowPassword.jsx
  2. 156
    0
      src/pages/UserManage/passwordText.jsx

+ 131
- 0
src/components/GlobalHeader/ShowPassword.jsx Целия файл

@@ -0,0 +1,131 @@
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.onSuccess()
30
+        }).catch(error => {
31
+          // openNotificationWithIcon('error', error.message)
32
+        })
33
+      }
34
+    });
35
+  }
36
+
37
+  // 弹框取消按钮
38
+  function handlePopCancel(e) {
39
+    props.onCancel()
40
+  }
41
+
42
+  const { getFieldDecorator } = props.form
43
+
44
+  return (
45
+    <>
46
+      <Form labelCol={{ span: 7 }} wrapperCol={{ span: 12 }} onSubmit={(e) => handleSubmit(e)}>
47
+        <Form.Item label="请输入旧密码">
48
+          {getFieldDecorator('originalPassword', {
49
+            rules: [{ required: true, message: '请输入旧密码' }],
50
+          })(
51
+            <Input
52
+              prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
53
+              type="password"
54
+              placeholder="Password"
55
+            />,
56
+          )}
57
+        </Form.Item>
58
+        <Form.Item label="新密码">
59
+          {getFieldDecorator('newPassword', {
60
+            rules: [{ required: true, message: '请输入新密码' }],
61
+          })(
62
+            <Input
63
+              prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
64
+              type="password"
65
+              placeholder="Password"
66
+            />,
67
+          )}
68
+        </Form.Item>
69
+        <Form.Item label="确认新密码">
70
+          {getFieldDecorator('newPasswordToo', {
71
+            rules: [{ required: true, message: '请确认新密码' }],
72
+          })(
73
+            <Input
74
+              prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
75
+              type="password"
76
+              placeholder="Password"
77
+            />,
78
+          )}
79
+        </Form.Item>
80
+        <Form.Item>
81
+          <Button type="primary" htmlType="submit">保存</Button>
82
+          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
83
+          <Button onClick={(e) => handlePopCancel(e)}>取消</Button>
84
+        </Form.Item>
85
+      </Form>
86
+    </>
87
+  )
88
+}
89
+
90
+const WrappedShowPasswordForm = Form.create({ name: 'passwodForm' })(passwodForm)
91
+
92
+export default class ShowPassword extends Component {
93
+
94
+  constructor(props) {
95
+    super(props)
96
+    this.state = { visible: false }
97
+  }
98
+
99
+  componentDidUpdate(prevProps) {
100
+    // 典型用法(不要忘记比较 props):
101
+    console.log('接收值: ', this.props.visible, prevProps.visible)
102
+    if (this.props.visible !== prevProps.visible) {
103
+      // eslint-disable-next-line react/no-did-update-set-state
104
+      this.setState({ visible: this.props.visible })
105
+    }
106
+  }
107
+
108
+  handleOk = e => {
109
+    console.log('修改密码成功')
110
+    this.props.onReset()
111
+  };
112
+
113
+  handleCancel = e => {
114
+    console.log('关闭了')
115
+    this.props.onCancel()
116
+  };
117
+
118
+  render() {
119
+    return (
120
+      <>
121
+        <Modal
122
+          title="修改密码"
123
+          visible={this.state.visible}
124
+          onCancel={this.handleCancel}
125
+          footer={null}>
126
+          <WrappedShowPasswordForm onSuccess={(e) => this.handleOk(e)} onCancel={(e) => this.handleCancel(e)}/>
127
+        </Modal>
128
+      </>
129
+    );
130
+  }
131
+}

+ 156
- 0
src/pages/UserManage/passwordText.jsx Целия файл

@@ -0,0 +1,156 @@
1
+import React, { useState, useEffect } from 'react';
2
+import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar, Radio, Modal, Descriptions, notification } from 'antd';
3
+import moment from 'moment';
4
+import request from '../../utils/request'
5
+import apis from '../../services/apis';
6
+import Styles from './style.less';
7
+
8
+
9
+const { Option } = Select;
10
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+const { Meta } = Card;
12
+
13
+const { TextArea } = Input;
14
+
15
+/**
16
+ * 图片信息
17
+ *
18
+ * @param {*} props
19
+ * @returns
20
+ */
21
+class PasswordText extends React.Component {
22
+  constructor(props) {
23
+    super(props);
24
+    this.state = {
25
+       visibleData: [{ visible: false, userId: '', oldPassword:'', newPassword: '', confirmPassword: '' }],
26
+    }
27
+  }
28
+
29
+  // 挂载之后
30
+  // componentDidMount() {
31
+  //
32
+  // }
33
+
34
+  componentDidUpdate(preProps, preState) {
35
+    if (this.props.visibleData.visible !== preState.visibleData.visible) {
36
+      console.log(this.props.visibleData)
37
+      this.setState({ visibleData: this.props.visibleData });
38
+    }
39
+  }
40
+
41
+  // 弹框确定按钮
42
+  // eslint-disable-next-line react/sort-comp
43
+  handleOk() {
44
+    this.setState({ visibleData: { visible: false, userId: '', oldPassword:'', newPassword: '', confirmPassword: '' } })
45
+  }
46
+
47
+  // 弹框取消按钮
48
+  handleCancel() {
49
+    this.setState({ visibleData: { visible: false, userId: '', oldPassword:'', newPassword: '', confirmPassword: '' } })
50
+  }
51
+
52
+  openNotificationWithIcon = (type, message) => {
53
+    notification[type]({
54
+      message,
55
+      description:
56
+        '',
57
+    });
58
+  };
59
+
60
+  // 提交
61
+  handleSubmit(e) {
62
+    e.preventDefault();
63
+    this.props.form.validateFields((err, values) => {
64
+      if (!err) {
65
+        this.submitData(values)
66
+      }
67
+    });
68
+  }
69
+
70
+  submitData(data) {
71
+    data.userId = this.props.visibleData.userId;
72
+    data.newPassword = data.newPassword 
73
+    data.confirmPassword = data.confirmPassword
74
+    const api = apis.user.changePassword;
75
+
76
+    // 网路请求
77
+    request({ ...api, data: { ...data } }).then(() => {
78
+      console.log({...data});
79
+      // eslint-disable-next-line no-unused-expressions
80
+      // this.openNotificationWithIcon('success', '操作成功')
81
+      notification.success({message: '设置成功'})
82
+      // 传递父组件事件
83
+      // onSuccess() 是自定义
84
+      // this.props.onSuccess()
85
+
86
+      // this.setState({ visibleData: { visible: false, apartmentId: '', buildingId: '' } }, () => console.log('回调:', this.state.visibleData))
87
+    }).catch(err => {
88
+      console.log('123213123')
89
+      // eslint-disable-next-line no-unused-expressions
90
+      // notification.success({message: ''})
91
+      // this.openNotificationWithIcon('error', err)
92
+    })
93
+  }
94
+
95
+  /**
96
+   * 取消按钮
97
+   *
98
+   * @memberof ModalImage
99
+   */
100
+  closeModal() {
101
+    this.setState({ visible: false, userId: '', oldPassword:'', newPassword: '', confirmPassword: '' })
102
+  }
103
+
104
+  render() {
105
+    const { getFieldDecorator } = this.props.form;
106
+    return (
107
+      <>
108
+        <Modal
109
+            title="修改密码"
110
+            width={400}
111
+            destroyOnClose="true"
112
+            footer={null}
113
+            visible={this.state.visibleData.visible}
114
+            onOk={() => this.handleOk()}
115
+            onCancel={e => this.handleCancel(e)}
116
+          >
117
+            <Form onSubmit={e => this.handleSubmit(e)}>
118
+              <Form.Item label="登录人" style={{ display: 'none' }}>
119
+                  {getFieldDecorator('userId')(<Input />)}
120
+              </Form.Item>
121
+              <Form.Item label="旧密码">
122
+                {getFieldDecorator('loginPassword', {
123
+                  rules: [
124
+                    { required: true, message: '请填写旧密码' },
125
+                  ],
126
+                })(<Input />)}
127
+              </Form.Item>
128
+              <Form.Item label="新密码">
129
+                {getFieldDecorator('newPassword', {
130
+                  rules: [
131
+                    { required: true, message: '请填写新密码' }
132
+                  ],
133
+                })(<Input />)}
134
+              </Form.Item>
135
+              <Form.Item label="确认密码">
136
+                {getFieldDecorator('confirmPassword', {
137
+                  rules: [
138
+                    { required: true, message: '请确认密码' }
139
+                  ],
140
+                })(<Input />)}
141
+              </Form.Item>
142
+              <Form.Item style={{ width: '400px', margin: 'auto', display: 'flex', justifyContent: 'space-between' }}>
143
+                <Button type="primary" htmlType="submit">保存</Button>
144
+                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
145
+                <Button onClick={e => this.handleCancel(e)}>取消</Button>
146
+              </Form.Item>
147
+            </Form>
148
+        </Modal>
149
+      </>
150
+    );
151
+  }
152
+}
153
+
154
+const WrappedModalImageForm = Form.create({ name: 'passwordText' })(PasswordText);
155
+
156
+export default WrappedModalImageForm