blob: 555fcde89ceaff1965c2bf09a5058ef5948a80b6 [file] [log] [blame]
86133aaa3f5d2025-04-20 21:33:29 +08001import React, { useEffect } from 'react';
2import {
3 ProForm,
4 ProFormDigit,
5 ProFormText,
6 ProFormRadio,
7 ProFormTextArea,
8 } from '@ant-design/pro-components';
9import { Form, Modal} from 'antd';
10import { useIntl, FormattedMessage } from '@umijs/max';
11import { DictValueEnumObj } from '@/components/DictTag';
12
13export type PostFormData = Record<string, unknown> & Partial<API.System.Post>;
14
15export type PostFormProps = {
16 onCancel: (flag?: boolean, formVals?: PostFormData) => void;
17 onSubmit: (values: PostFormData) => Promise<void>;
18 open: boolean;
19 values: Partial<API.System.Post>;
20 statusOptions: DictValueEnumObj;
21};
22
23const PostForm: React.FC<PostFormProps> = (props) => {
24 const [form] = Form.useForm();
25
26 const { statusOptions, } = props;
27
28 useEffect(() => {
29 form.resetFields();
30 form.setFieldsValue({
31 postId: props.values.postId,
32 postCode: props.values.postCode,
33 postName: props.values.postName,
34 postSort: props.values.postSort,
35 status: props.values.status,
36 createBy: props.values.createBy,
37 createTime: props.values.createTime,
38 updateBy: props.values.updateBy,
39 updateTime: props.values.updateTime,
40 remark: props.values.remark,
41 });
42 }, [form, props]);
43
44 const intl = useIntl();
45 const handleOk = () => {
46 form.submit();
47 };
48 const handleCancel = () => {
49 props.onCancel();
50 };
51 const handleFinish = async (values: Record<string, any>) => {
52 props.onSubmit(values as PostFormData);
53 };
54
55 return (
56 <Modal
57 width={640}
58 title={intl.formatMessage({
59 id: 'system.post.title',
60 defaultMessage: '编辑岗位信息',
61 })}
62 open={props.open}
63 forceRender
64 destroyOnClose
65 onOk={handleOk}
66 onCancel={handleCancel}
67 >
68 <ProForm
69 form={form}
70 grid={true}
71 submitter={false}
72 layout="horizontal"
73 onFinish={handleFinish}>
74 <ProFormDigit
75 name="postId"
76 label={intl.formatMessage({
77 id: 'system.post.post_id',
78 defaultMessage: '岗位编号',
79 })}
80 placeholder="请输入岗位编号"
81 disabled
82 hidden={true}
83 rules={[
84 {
85 required: false,
86 message: <FormattedMessage id="请输入岗位编号!" defaultMessage="请输入岗位编号!" />,
87 },
88 ]}
89 />
90 <ProFormText
91 name="postName"
92 label={intl.formatMessage({
93 id: 'system.post.post_name',
94 defaultMessage: '岗位名称',
95 })}
96 placeholder="请输入岗位名称"
97 rules={[
98 {
99 required: true,
100 message: <FormattedMessage id="请输入岗位名称!" defaultMessage="请输入岗位名称!" />,
101 },
102 ]}
103 />
104 <ProFormText
105 name="postCode"
106 label={intl.formatMessage({
107 id: 'system.post.post_code',
108 defaultMessage: '岗位编码',
109 })}
110 placeholder="请输入岗位编码"
111 rules={[
112 {
113 required: true,
114 message: <FormattedMessage id="请输入岗位编码!" defaultMessage="请输入岗位编码!" />,
115 },
116 ]}
117 />
118 <ProFormDigit
119 name="postSort"
120 label={intl.formatMessage({
121 id: 'system.post.post_sort',
122 defaultMessage: '显示顺序',
123 })}
124 placeholder="请输入显示顺序"
125 rules={[
126 {
127 required: true,
128 message: <FormattedMessage id="请输入显示顺序!" defaultMessage="请输入显示顺序!" />,
129 },
130 ]}
131 />
132 <ProFormRadio.Group
133 valueEnum={statusOptions}
134 name="status"
135 label={intl.formatMessage({
136 id: 'system.post.status',
137 defaultMessage: '状态',
138 })}
139 placeholder="请输入状态"
140 rules={[
141 {
142 required: true,
143 message: <FormattedMessage id="请输入状态!" defaultMessage="请输入状态!" />,
144 },
145 ]}
146 />
147 <ProFormTextArea
148 name="remark"
149 label={intl.formatMessage({
150 id: 'system.post.remark',
151 defaultMessage: '备注',
152 })}
153 placeholder="请输入备注"
154 rules={[
155 {
156 required: false,
157 message: <FormattedMessage id="请输入备注!" defaultMessage="请输入备注!" />,
158 },
159 ]}
160 />
161 </ProForm>
162 </Modal>
163 );
164};
165
166export default PostForm;