Jiarenxiang | 38dcb05 | 2025-03-13 16:40:09 +0800 | [diff] [blame^] | 1 | import React, { useEffect } from 'react'; |
| 2 | import { |
| 3 | ProForm, |
| 4 | ProFormDigit, |
| 5 | ProFormText, |
| 6 | ProFormSelect, |
| 7 | ProFormTextArea, |
| 8 | ProFormRadio, |
| 9 | } from '@ant-design/pro-components'; |
| 10 | import { Form, Modal} from 'antd'; |
| 11 | import { useIntl, FormattedMessage } from '@umijs/max'; |
| 12 | import { DictValueEnumObj } from '@/components/DictTag'; |
| 13 | |
| 14 | export type NoticeFormData = Record<string, unknown> & Partial<API.System.Notice>; |
| 15 | |
| 16 | export type NoticeFormProps = { |
| 17 | onCancel: (flag?: boolean, formVals?: NoticeFormData) => void; |
| 18 | onSubmit: (values: NoticeFormData) => Promise<void>; |
| 19 | open: boolean; |
| 20 | values: Partial<API.System.Notice>; |
| 21 | noticeTypeOptions: DictValueEnumObj; |
| 22 | statusOptions: DictValueEnumObj; |
| 23 | }; |
| 24 | |
| 25 | const NoticeForm: React.FC<NoticeFormProps> = (props) => { |
| 26 | const [form] = Form.useForm(); |
| 27 | |
| 28 | const { noticeTypeOptions,statusOptions, } = props; |
| 29 | |
| 30 | useEffect(() => { |
| 31 | form.resetFields(); |
| 32 | form.setFieldsValue({ |
| 33 | noticeId: props.values.noticeId, |
| 34 | noticeTitle: props.values.noticeTitle, |
| 35 | noticeType: props.values.noticeType, |
| 36 | noticeContent: props.values.noticeContent, |
| 37 | status: props.values.status, |
| 38 | createBy: props.values.createBy, |
| 39 | createTime: props.values.createTime, |
| 40 | updateBy: props.values.updateBy, |
| 41 | updateTime: props.values.updateTime, |
| 42 | remark: props.values.remark, |
| 43 | }); |
| 44 | }, [form, props]); |
| 45 | |
| 46 | const intl = useIntl(); |
| 47 | const handleOk = () => { |
| 48 | form.submit(); |
| 49 | }; |
| 50 | const handleCancel = () => { |
| 51 | props.onCancel(); |
| 52 | }; |
| 53 | const handleFinish = async (values: Record<string, any>) => { |
| 54 | props.onSubmit(values as NoticeFormData); |
| 55 | }; |
| 56 | |
| 57 | return ( |
| 58 | <Modal |
| 59 | width={640} |
| 60 | title={intl.formatMessage({ |
| 61 | id: 'system.notice.title', |
| 62 | defaultMessage: '编辑通知公告', |
| 63 | })} |
| 64 | forceRender |
| 65 | open={props.open} |
| 66 | destroyOnClose |
| 67 | onOk={handleOk} |
| 68 | onCancel={handleCancel} |
| 69 | > |
| 70 | <ProForm |
| 71 | form={form} |
| 72 | grid={true} |
| 73 | submitter={false} |
| 74 | layout="horizontal" |
| 75 | onFinish={handleFinish}> |
| 76 | <ProFormDigit |
| 77 | name="noticeId" |
| 78 | label={intl.formatMessage({ |
| 79 | id: 'system.notice.notice_id', |
| 80 | defaultMessage: '公告编号', |
| 81 | })} |
| 82 | colProps={{ md: 12, xl: 24 }} |
| 83 | placeholder="请输入公告编号" |
| 84 | disabled |
| 85 | hidden={true} |
| 86 | rules={[ |
| 87 | { |
| 88 | required: false, |
| 89 | message: <FormattedMessage id="请输入公告编号!" defaultMessage="请输入公告编号!" />, |
| 90 | }, |
| 91 | ]} |
| 92 | /> |
| 93 | <ProFormText |
| 94 | name="noticeTitle" |
| 95 | label={intl.formatMessage({ |
| 96 | id: 'system.notice.notice_title', |
| 97 | defaultMessage: '公告标题', |
| 98 | })} |
| 99 | placeholder="请输入公告标题" |
| 100 | rules={[ |
| 101 | { |
| 102 | required: true, |
| 103 | message: <FormattedMessage id="请输入公告标题!" defaultMessage="请输入公告标题!" />, |
| 104 | }, |
| 105 | ]} |
| 106 | /> |
| 107 | <ProFormSelect |
| 108 | valueEnum={noticeTypeOptions} |
| 109 | name="noticeType" |
| 110 | label={intl.formatMessage({ |
| 111 | id: 'system.notice.notice_type', |
| 112 | defaultMessage: '公告类型', |
| 113 | })} |
| 114 | colProps={{ md: 12, xl: 24 }} |
| 115 | placeholder="请输入公告类型" |
| 116 | rules={[ |
| 117 | { |
| 118 | required: true, |
| 119 | message: <FormattedMessage id="请输入公告类型!" defaultMessage="请输入公告类型!" />, |
| 120 | }, |
| 121 | ]} |
| 122 | /> |
| 123 | <ProFormRadio.Group |
| 124 | valueEnum={statusOptions} |
| 125 | name="status" |
| 126 | label={intl.formatMessage({ |
| 127 | id: 'system.notice.status', |
| 128 | defaultMessage: '公告状态', |
| 129 | })} |
| 130 | colProps={{ md: 12, xl: 24 }} |
| 131 | placeholder="请输入公告状态" |
| 132 | rules={[ |
| 133 | { |
| 134 | required: false, |
| 135 | message: <FormattedMessage id="请输入公告状态!" defaultMessage="请输入公告状态!" />, |
| 136 | }, |
| 137 | ]} |
| 138 | /> |
| 139 | <ProFormTextArea |
| 140 | name="noticeContent" |
| 141 | label={intl.formatMessage({ |
| 142 | id: 'system.notice.notice_content', |
| 143 | defaultMessage: '公告内容', |
| 144 | })} |
| 145 | colProps={{ md: 12, xl: 24 }} |
| 146 | placeholder="请输入公告内容" |
| 147 | rules={[ |
| 148 | { |
| 149 | required: false, |
| 150 | message: <FormattedMessage id="请输入公告内容!" defaultMessage="请输入公告内容!" />, |
| 151 | }, |
| 152 | ]} |
| 153 | /> |
| 154 | <ProFormText |
| 155 | name="remark" |
| 156 | label={intl.formatMessage({ |
| 157 | id: 'system.notice.remark', |
| 158 | defaultMessage: '备注', |
| 159 | })} |
| 160 | colProps={{ md: 12, xl: 24 }} |
| 161 | placeholder="请输入备注" |
| 162 | rules={[ |
| 163 | { |
| 164 | required: false, |
| 165 | message: <FormattedMessage id="请输入备注!" defaultMessage="请输入备注!" />, |
| 166 | }, |
| 167 | ]} |
| 168 | /> |
| 169 | </ProForm> |
| 170 | </Modal> |
| 171 | ); |
| 172 | }; |
| 173 | |
| 174 | export default NoticeForm; |