86133 | aaa3f5d | 2025-04-20 21:33:29 +0800 | [diff] [blame] | 1 | import { Button, Col, Form, message, Row } from 'antd'; |
| 2 | import React, { Fragment, useEffect } from 'react'; |
| 3 | import { history } from '@umijs/max'; |
| 4 | import styles from '../style.less'; |
| 5 | import { ProForm, ProFormText, ProFormTextArea } from '@ant-design/pro-components'; |
| 6 | |
| 7 | export type BaseInfoProps = { |
| 8 | values?: any; |
| 9 | onStepSubmit?: any; |
| 10 | }; |
| 11 | |
| 12 | const BaseInfo: React.FC<BaseInfoProps> = (props) => { |
| 13 | const [form] = Form.useForm(); |
| 14 | const { onStepSubmit } = props; |
| 15 | |
| 16 | useEffect(() => { |
| 17 | form.resetFields(); |
| 18 | form.setFieldsValue({ |
| 19 | tableName: props.values.tableName, |
| 20 | }); |
| 21 | }); |
| 22 | |
| 23 | const onValidateForm = async () => { |
| 24 | const values = await form.validateFields(); |
| 25 | if (onStepSubmit) { |
| 26 | onStepSubmit('base', values); |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | return ( |
| 31 | <Fragment> |
| 32 | <Row> |
| 33 | <Col span={24}> |
| 34 | <ProForm |
| 35 | form={form} |
| 36 | onFinish={async () => { |
| 37 | message.success('提交成功'); |
| 38 | }} |
| 39 | initialValues={{ |
| 40 | tableName: props.values?.tableName, |
| 41 | tableComment: props.values?.tableComment, |
| 42 | className: props.values?.className, |
| 43 | functionAuthor: props.values?.functionAuthor, |
| 44 | remark: props.values?.remark, |
| 45 | }} |
| 46 | submitter={{ |
| 47 | resetButtonProps: { |
| 48 | style: { display: 'none' }, |
| 49 | }, |
| 50 | submitButtonProps: { |
| 51 | style: { display: 'none' }, |
| 52 | }, |
| 53 | }} |
| 54 | > |
| 55 | <Row> |
| 56 | <Col span={12} order={1}> |
| 57 | <ProFormText |
| 58 | |
| 59 | name="tableName" |
| 60 | label="表名称" |
| 61 | rules={[ |
| 62 | { |
| 63 | required: true, |
| 64 | message: '表名称不可为空。', |
| 65 | }, |
| 66 | ]} |
| 67 | /> |
| 68 | </Col> |
| 69 | <Col span={12} order={2}> |
| 70 | <ProFormText |
| 71 | name="tableComment" |
| 72 | label="表描述" |
| 73 | /> |
| 74 | </Col> |
| 75 | </Row> |
| 76 | <Row> |
| 77 | <Col span={12} order={1}> |
| 78 | <ProFormText |
| 79 | |
| 80 | name="className" |
| 81 | label="实体类名称" |
| 82 | rules={[ |
| 83 | { |
| 84 | required: true, |
| 85 | message: '实体类名称不可为空。', |
| 86 | }, |
| 87 | ]} |
| 88 | /> |
| 89 | </Col> |
| 90 | <Col span={12} order={2}> |
| 91 | <ProFormText name="functionAuthor" label="作者" /> |
| 92 | </Col> |
| 93 | </Row> |
| 94 | <Row> |
| 95 | <Col span={24}> |
| 96 | <ProFormTextArea name="remark" label="备注" /> |
| 97 | </Col> |
| 98 | </Row> |
| 99 | </ProForm> |
| 100 | </Col> |
| 101 | </Row> |
| 102 | <Row justify="center"> |
| 103 | <Col span={4}> |
| 104 | <Button |
| 105 | type="primary" |
| 106 | className={styles.step_buttons} |
| 107 | onClick={() => { |
| 108 | history.back(); |
| 109 | }} |
| 110 | > |
| 111 | 返回 |
| 112 | </Button> |
| 113 | </Col> |
| 114 | <Col span={4}> |
| 115 | <Button type="primary" onClick={onValidateForm}> |
| 116 | 下一步 |
| 117 | </Button> |
| 118 | </Col> |
| 119 | </Row> |
| 120 | </Fragment> |
| 121 | ); |
| 122 | }; |
| 123 | |
| 124 | export default BaseInfo; |