blob: 120d96682a9195548b82023683d5e6edd3d1b5ef [file] [log] [blame]
Jiarenxiang38dcb052025-03-13 16:40:09 +08001import React, { useEffect } from 'react';
2import { Form, Modal } from 'antd';
3import { useIntl } from '@umijs/max';
4import { ProForm, ProFormSelect } 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.Dept>;
14
15export type AuthRoleFormProps = {
16 onCancel: (flag?: boolean, formVals?: FormValueType) => void;
17 onSubmit: (values: FormValueType) => Promise<void>;
18 open: boolean;
19 roleIds: number[];
20 roles: string[];
21};
22
23const AuthRoleForm: React.FC<AuthRoleFormProps> = (props) => {
24 const [form] = Form.useForm();
25
26 useEffect(() => {
27 form.resetFields();
28 form.setFieldValue( 'roleIds', props.roleIds);
29 });
30
31 const intl = useIntl();
32 const handleOk = () => {
33 form.submit();
34 };
35 const handleCancel = () => {
36 props.onCancel();
37 };
38 const handleFinish = async (values: Record<string, any>) => {
39 props.onSubmit(values as FormValueType);
40 };
41
42 return (
43 <Modal
44 width={640}
45 title={intl.formatMessage({
46 id: 'system.user.auth.role',
47 defaultMessage: '分配角色',
48 })}
49 open={props.open}
50 destroyOnClose
51 forceRender
52 onOk={handleOk}
53 onCancel={handleCancel}
54 >
55 <ProForm
56 form={form}
57 grid={true}
58 layout="horizontal"
59 onFinish={handleFinish}
60 initialValues={{
61 login_password: '',
62 confirm_password: '',
63 }}
64 >
65 <ProFormSelect
66 name="roleIds"
67 mode="multiple"
68 label={intl.formatMessage({
69 id: 'system.user.role',
70 defaultMessage: '角色',
71 })}
72 options={props.roles}
73 placeholder="请选择角色"
74 rules={[{ required: true, message: '请选择角色!' }]}
75 />
76 </ProForm>
77 </Modal>
78 );
79};
80
81export default AuthRoleForm;