Browse Source

修改密码

魏超 5 years ago
parent
commit
bf908bacb1
3 changed files with 186 additions and 1 deletions
  1. 25
    1
      src/pages/UserManage/index.jsx
  2. 156
    0
      src/pages/UserManage/passwordText.jsx
  3. 5
    0
      src/services/apis.js

+ 25
- 1
src/pages/UserManage/index.jsx View File

@@ -7,6 +7,7 @@ import className from 'classnames';
7 7
 import Cell from '../../components/Cell';
8 8
 import Style from './style.less';
9 9
 import { fetch, apis } from '../../utils/request';
10
+import PasswordText from './passwordText';
10 11
 
11 12
 const { Meta } = Card;
12 13
 
@@ -33,6 +34,8 @@ const ABCol = (props) => (
33 34
 export default (props) => {
34 35
   const [members, setMembers] = useState([]);
35 36
   const [pageNavi, setPageNavi] = useState({ current: 1, pageSize: 10, total: 0 })
37
+  const [submitting, setSubmitting] = useState(false)
38
+  const [visibleData, setVisibleData] = useState({ visible: false, userId: '', oldPassword:'', newPassword: '', confirmPassword: '' })
36 39
 
37 40
   useEffect(() => {
38 41
     getMembers({ params: { pageNum: pageNavi.current, pageSize: pageNavi.pageSize } }).then((dt) => {
@@ -51,6 +54,24 @@ export default (props) => {
51 54
     }))
52 55
   }
53 56
 
57
+  /**
58
+   *回调事件
59
+   *
60
+   */
61
+  function onModalChange() {
62
+    // getList()
63
+    // setVisibleData({ visible: false, userId: '', oldPassword:'', newPassword: '', confirmPassword: '' })
64
+  }
65
+
66
+  /**
67
+   *打开编辑页
68
+   *
69
+   * @param {*} record
70
+   */
71
+  const editPassword = (record) => () => {
72
+    setVisibleData({ visible: true, userId: record.userId, oldPasswod: '', newPassword: '', confirmPassword: '',submitting:submitting})
73
+  }
74
+
54 75
   const CardBody = (cbProps) => {
55 76
     const handleSwitch = (on) => () => {
56 77
       if (!on) {
@@ -133,6 +154,7 @@ export default (props) => {
133 154
   }
134 155
 
135 156
   return (
157
+    <>
136 158
     <PageHeaderWrapper extra={<Button type="primary" icon="plus" onClick={createUser}>新建</Button>}>
137 159
       <div className={Style['flex-box']}>
138 160
         {
@@ -150,7 +172,7 @@ export default (props) => {
150 172
                       <Icon type="setting" key="rights" onClick={gotoDetail(member, 3)}/>
151 173
                     </Tooltip>,
152 174
                     <Tooltip title="重置密码">
153
-                      <Icon type="block" key="resetpass" onClick={resetPassword(member)}/>
175
+                      <Icon type="block" key="resetpass" onClick={editPassword(member)}/>
154 176
                     </Tooltip>
155 177
                   ]}
156 178
                 >
@@ -170,5 +192,7 @@ export default (props) => {
170 192
         onShowSizeChange={handleSizeChange}
171 193
       />
172 194
     </PageHeaderWrapper>
195
+    <PasswordText visibleData={visibleData} key="PasswordText" onSuccess={() => onModalChange()}/>
196
+    </>
173 197
   )
174 198
 }

+ 156
- 0
src/pages/UserManage/passwordText.jsx View File

@@ -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

+ 5
- 0
src/services/apis.js View File

@@ -19,6 +19,11 @@ const apis = {
19 19
       action: 'center',
20 20
       logout: true
21 21
     },
22
+    changePassword: {
23
+      url: `${prefix}/changePassword`,
24
+      method: 'POST',
25
+      action: 'center'
26
+    }
22 27
   },
23 28
   member: {
24 29
     list: {