blob: 5523cd6cd9a29da7300d7a38bc7e656d10ba2288 [file] [log] [blame]
Jiarenxiang38dcb052025-03-13 16:40:09 +08001import React from 'react';
2import { Form, Modal } from 'antd';
3import { useIntl } from '@umijs/max';
4import { ProForm, ProFormText } from '@ant-design/pro-components';
5
6/* *
7 *
8 * @author whiteshader@163.com
9 * @datetime 2023/02/06
10 *
11 * */
12
13export type FormValueType = any & Partial<API.System.User>;
14
15export type UpdateFormProps = {
16 onCancel: (flag?: boolean, formVals?: FormValueType) => void;
17 onSubmit: (values: FormValueType) => Promise<void>;
18 open: boolean;
19 values: Partial<API.System.User>;
20};
21
22const UpdateForm: React.FC<UpdateFormProps> = (props) => {
23 const [form] = Form.useForm();
24 const loginPassword = Form.useWatch('password', form);
25 const userId = props.values.userId;
26
27 const intl = useIntl();
28 const handleOk = () => {
29 form.submit();
30 };
31 const handleCancel = () => {
32 props.onCancel();
33 };
34 const handleFinish = async (values: Record<string, any>) => {
35 props.onSubmit({ ...values, userId } as FormValueType);
36 };
37
38 const checkPassword = (rule: any, value: string) => {
39 if (value === loginPassword) {
40 // 校验条件自定义
41 return Promise.resolve();
42 }
43 return Promise.reject(new Error('两次密码输入不一致'));
44 };
45
46 return (
47 <Modal
48 width={640}
49 title={intl.formatMessage({
50 id: 'system.user.reset.password',
51 defaultMessage: '密码重置',
52 })}
53 open={props.open}
54 destroyOnClose
55 onOk={handleOk}
56 onCancel={handleCancel}
57 >
58 <ProForm
59 grid={true}
60 form={form}
61 layout="horizontal"
62 onFinish={handleFinish}
63 initialValues={{
64 password: '',
65 confirm_password: '',
66 }}
67 >
68 <p>请输入用户{props.values.userName}的新密码!</p>
69 <ProFormText.Password
70 name="password"
71 label="登录密码"
72 rules={[
73 {
74 required: true,
75 message: '登录密码不可为空。',
76 },
77 ]}
78 />
79 <ProFormText.Password
80 name="confirm_password"
81 label="确认密码"
82 rules={[
83 {
84 required: true,
85 message: "确认密码",
86 },
87 { validator: checkPassword },
88 ]}
89 />
90 </ProForm>
91 </Modal>
92 );
93};
94
95export default UpdateForm;