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
| import { Card, Form, message } from 'antd';
| import React from 'react';
| import {
| ProForm,
| ProFormText
| } from '@ant-design/pro-components';
| import { useModel } from '@umijs/max';
| import Http from '@/utils/http';
|
| const resetPwd = async (val) => {
| const hide = message.loading('正在更新');
| try {
| const resp = await Http.doPost('api/user/update', val);
| if (resp.code === 200) {
| message.success('更新成功');
| return true;
| } else {
| message.error(resp.msg);
| return false;
| }
| } catch (error) {
| message.error('配置失败请重试!');
| return false;
| } finally {
| hide();
| }
| };
|
| const SecurityView = () => {
| const [form] = Form.useForm();
| const { initialState } = useModel('@@initialState');
| const { currentUser } = initialState || {};
|
| const handleFinish = (values) => {
| resetPwd({...values, userId: currentUser.id});
| }
|
| return (
| <>
| <Card>
| <ProForm
| form={form}
| layout="vertical"
| onFinish={handleFinish}
| submitter={{
| searchConfig: {
| submitText: '修改密码',
| },
| render: (_, dom) => dom[1],
| }}
| >
| <ProFormText.Password
| width="md"
| name="currentPwd"
| label="当前密码"
| rules={[
| {
| required: true,
| message: '请输入当前密码!',
| },
| ]}
| />
| <ProFormText.Password
| width="md"
| name="newPwd"
| label="新密码"
| rules={[
| {
| required: true,
| message: '请输入新密码!',
| },
| {
| validator(_, value) {
| if (value.length >= 4 && value.length <= 16) {
| return Promise.resolve();
| }
| return Promise.reject(new Error('新密码必须是4到16个字符!'));
| },
| },
| ]}
| />
| <ProFormText.Password
| width="md"
| name="newPwdRepeat"
| label="确认密码"
| rules={[
| {
| required: true,
| message: '请再次输入新密码!',
| },
| {
| validator(_, value) {
| if (form.getFieldValue('newPwd') === value) return Promise.resolve();
| return Promise.reject(new Error('两次输入的密码不相符!'));
| }
| }
| ]}
| />
| </ProForm>
| </Card>
| </>
| );
| };
|
| export default SecurityView;
|
|