You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

edit.tsx 5.4 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { DictValueEnumObj } from '@/components/DictTag';
  2. import KFModal from '@/components/KFModal';
  3. import {
  4. ProForm,
  5. ProFormDigit,
  6. ProFormRadio,
  7. ProFormSelect,
  8. ProFormText,
  9. ProFormTextArea,
  10. } from '@ant-design/pro-components';
  11. import { FormattedMessage, useIntl } from '@umijs/max';
  12. import { Form } from 'antd';
  13. import React, { useEffect } from 'react';
  14. export type NoticeFormData = Record<string, unknown> & Partial<API.System.Notice>;
  15. export type NoticeFormProps = {
  16. onCancel: (flag?: boolean, formVals?: NoticeFormData) => void;
  17. onSubmit: (values: NoticeFormData) => Promise<void>;
  18. open: boolean;
  19. values: Partial<API.System.Notice>;
  20. noticeTypeOptions: DictValueEnumObj;
  21. statusOptions: DictValueEnumObj;
  22. };
  23. const NoticeForm: React.FC<NoticeFormProps> = (props) => {
  24. const [form] = Form.useForm();
  25. const { noticeTypeOptions, statusOptions } = props;
  26. const formLayout = {
  27. labelCol: { span: 4 },
  28. wrapperCol: { span: 20 },
  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 || Object.keys(statusOptions)[0],
  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, statusOptions]);
  45. const intl = useIntl();
  46. const handleOk = () => {
  47. form.submit();
  48. };
  49. const handleCancel = () => {
  50. props.onCancel();
  51. };
  52. const handleFinish = async (values: Record<string, any>) => {
  53. props.onSubmit(values as NoticeFormData);
  54. };
  55. return (
  56. <KFModal
  57. width={680}
  58. title={intl.formatMessage({
  59. id: 'system.notice.title',
  60. defaultMessage: '编辑通知公告',
  61. })}
  62. forceRender
  63. open={props.open}
  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. {...formLayout}
  75. size="large"
  76. labelAlign="right"
  77. autoComplete="off"
  78. >
  79. <ProFormDigit
  80. name="noticeId"
  81. label={intl.formatMessage({
  82. id: 'system.notice.notice_id',
  83. defaultMessage: '公告编号',
  84. })}
  85. colProps={{ md: 12, xl: 24 }}
  86. placeholder="请输入公告编号"
  87. disabled
  88. hidden={true}
  89. rules={[
  90. {
  91. required: false,
  92. message: <FormattedMessage id="请输入公告编号!" defaultMessage="请输入公告编号!" />,
  93. },
  94. ]}
  95. />
  96. <ProFormText
  97. name="noticeTitle"
  98. label={intl.formatMessage({
  99. id: 'system.notice.notice_title',
  100. defaultMessage: '公告标题',
  101. })}
  102. placeholder="请输入公告标题"
  103. rules={[
  104. {
  105. required: true,
  106. message: <FormattedMessage id="请输入公告标题!" defaultMessage="请输入公告标题!" />,
  107. },
  108. ]}
  109. />
  110. <ProFormSelect
  111. valueEnum={noticeTypeOptions}
  112. name="noticeType"
  113. label={intl.formatMessage({
  114. id: 'system.notice.notice_type',
  115. defaultMessage: '公告类型',
  116. })}
  117. colProps={{ md: 12, xl: 24 }}
  118. placeholder="请输入公告类型"
  119. rules={[
  120. {
  121. required: true,
  122. message: <FormattedMessage id="请输入公告类型!" defaultMessage="请输入公告类型!" />,
  123. },
  124. ]}
  125. />
  126. <ProFormRadio.Group
  127. valueEnum={statusOptions}
  128. name="status"
  129. label={intl.formatMessage({
  130. id: 'system.notice.status',
  131. defaultMessage: '公告状态',
  132. })}
  133. colProps={{ md: 12, xl: 24 }}
  134. placeholder="请输入公告状态"
  135. rules={[
  136. {
  137. required: false,
  138. message: <FormattedMessage id="请输入公告状态!" defaultMessage="请输入公告状态!" />,
  139. },
  140. ]}
  141. />
  142. <ProFormTextArea
  143. name="noticeContent"
  144. label={intl.formatMessage({
  145. id: 'system.notice.notice_content',
  146. defaultMessage: '公告内容',
  147. })}
  148. colProps={{ md: 12, xl: 24 }}
  149. placeholder="请输入公告内容"
  150. rules={[
  151. {
  152. required: false,
  153. message: <FormattedMessage id="请输入公告内容!" defaultMessage="请输入公告内容!" />,
  154. },
  155. ]}
  156. />
  157. <ProFormText
  158. name="remark"
  159. label={intl.formatMessage({
  160. id: 'system.notice.remark',
  161. defaultMessage: '备注',
  162. })}
  163. colProps={{ md: 12, xl: 24 }}
  164. placeholder="请输入备注"
  165. rules={[
  166. {
  167. required: false,
  168. message: <FormattedMessage id="请输入备注!" defaultMessage="请输入备注!" />,
  169. },
  170. ]}
  171. />
  172. </ProForm>
  173. </KFModal>
  174. );
  175. };
  176. export default NoticeForm;