diff --git a/src/pages/ListTableList/components/CreateForm.tsx b/src/pages/ListTableList/components/CreateForm.tsx deleted file mode 100644 index b62f2aa3..00000000 --- a/src/pages/ListTableList/components/CreateForm.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react'; -import { Modal } from 'antd'; -import { useIntl } from 'umi'; - -interface CreateFormProps { - modalVisible: boolean; - onCancel: () => void; -} - -const CreateForm: React.FC = (props) => { - const { modalVisible, onCancel } = props; - const intl = useIntl(); - - return ( - onCancel()} - footer={null} - > - {props.children} - - ); -}; - -export default CreateForm; diff --git a/src/pages/ListTableList/index.tsx b/src/pages/ListTableList/index.tsx index 0cd49fd3..561d934b 100644 --- a/src/pages/ListTableList/index.tsx +++ b/src/pages/ListTableList/index.tsx @@ -1,11 +1,11 @@ import { PlusOutlined } from '@ant-design/icons'; -import { Button, Divider, message, Input, Drawer } from 'antd'; +import { Button, message, Input, Drawer } from 'antd'; import React, { useState, useRef } from 'react'; import { useIntl, FormattedMessage } from 'umi'; import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import ProTable, { ProColumns, ActionType } from '@ant-design/pro-table'; +import { ModalForm, ProFormText, ProFormTextArea } from '@ant-design/pro-form'; import ProDescriptions, { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; -import CreateForm from './components/CreateForm'; import UpdateForm, { FormValueType } from './components/UpdateForm'; import { TableListItem } from './data.d'; import { queryRule, updateRule, addRule, removeRule } from './service'; @@ -73,13 +73,26 @@ const handleRemove = async (selectedRows: TableListItem[]) => { }; const TableList: React.FC<{}> = () => { + /** + * 新建窗口的弹窗 + */ const [createModalVisible, handleModalVisible] = useState(false); + /** + * 分布更新窗口的弹窗 + */ const [updateModalVisible, handleUpdateModalVisible] = useState(false); - const [stepFormValues, setStepFormValues] = useState({}); + + const [showDetail, setShowDetail] = useState(false); + const actionRef = useRef(); - const [row, setRow] = useState(); + const [currentRow, setCurrentRow] = useState(); const [selectedRowsState, setSelectedRows] = useState([]); + + /** + * 国际化配置 + */ const intl = useIntl(); + const columns: ProColumns[] = [ { title: ( @@ -90,18 +103,17 @@ const TableList: React.FC<{}> = () => { ), dataIndex: 'name', tip: '规则名称是唯一的 key', - formItemProps: { - rules: [ - { - required: true, - message: ( - - ), - }, - ], - }, render: (dom, entity) => { - return setRow(entity)}>{dom}; + return ( + { + setCurrentRow(entity); + setShowDetail(true); + }} + > + {dom} + + ); }, }, { @@ -155,10 +167,9 @@ const TableList: React.FC<{}> = () => { title: ( ), - dataIndex: 'updatedAt', sorter: true, + dataIndex: 'updatedAt', valueType: 'dateTime', - hideInForm: true, renderFormItem: (item, { defaultRender, ...rest }, form) => { const status = form.getFieldValue('status'); if (`${status}` === '0') { @@ -182,22 +193,19 @@ const TableList: React.FC<{}> = () => { title: , dataIndex: 'option', valueType: 'option', - render: (_, record) => ( - <> - { - handleUpdateModalVisible(true); - setStepFormValues(record); - }} - > - - - - - - - - ), + render: (_, record) => [ + { + handleUpdateModalVisible(true); + setCurrentRow(record); + }} + > + + , + + + , + ], }, ]; @@ -257,60 +265,78 @@ const TableList: React.FC<{}> = () => { )} - handleModalVisible(false)} modalVisible={createModalVisible}> - - onSubmit={async (value) => { - const success = await handleAdd(value); - if (success) { - handleModalVisible(false); - if (actionRef.current) { - actionRef.current.reload(); - } + { + const success = await handleAdd(value as TableListItem); + if (success) { + handleModalVisible(false); + if (actionRef.current) { + actionRef.current.reload(); } - }} - rowKey="key" - type="form" - columns={columns} + } + }} + > + + ), + }, + ]} + width="m" + name="name" /> - - {stepFormValues && Object.keys(stepFormValues).length ? ( - { - const success = await handleUpdate(value); - if (success) { - handleUpdateModalVisible(false); - setStepFormValues({}); - if (actionRef.current) { - actionRef.current.reload(); - } - } - }} - onCancel={() => { + + + { + const success = await handleUpdate(value); + if (success) { handleUpdateModalVisible(false); - setStepFormValues({}); - }} - updateModalVisible={updateModalVisible} - values={stepFormValues} - /> - ) : null} + setCurrentRow(undefined); + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + onCancel={() => { + handleUpdateModalVisible(false); + setCurrentRow(undefined); + }} + updateModalVisible={updateModalVisible} + values={currentRow || {}} + /> { - setRow(undefined); + setCurrentRow(undefined); + setShowDetail(false); }} closable={false} > - {row?.name && ( + {currentRow?.name && ( column={2} - title={row?.name} + title={currentRow?.name} request={async () => ({ - data: row || {}, + data: currentRow || {}, })} params={{ - id: row?.name, + id: currentRow?.name, }} columns={columns as ProDescriptionsItemProps[]} />