import { productcontrollerCreatestrength, productcontrollerDeletestrength, productcontrollerGetstrength, } from '@/servers/api/product'; import { PlusOutlined } from '@ant-design/icons'; import { ActionType, DrawerForm, PageContainer, ProColumns, ProFormText, ProTable, } from '@ant-design/pro-components'; import { App, Button, Popconfirm } from 'antd'; import { useRef } from 'react'; const List: React.FC = () => { const actionRef = useRef(); const { message } = App.useApp(); const columns: ProColumns[] = [ { title: '名称', dataIndex: 'name', tip: '名称是唯一的 key', formItemProps: { rules: [ { required: true, message: '名称为必填项', }, ], }, }, { title: '标识', dataIndex: 'unique_key', hideInSearch: true, }, { title: '更新时间', dataIndex: 'updatedAt', valueType: 'dateTime', hideInSearch: true, }, { title: '创建时间', dataIndex: 'createdAt', valueType: 'dateTime', hideInSearch: true, }, { title: '操作', dataIndex: 'option', valueType: 'option', render: (_, record) => ( <> {/* */} { try { const { success, message: errMsg } = await productcontrollerDeletestrength({ id: record.id }); if (!success) { throw new Error(errMsg); } actionRef.current?.reload(); } catch (error: any) { message.error(error.message); } }} > ), }, ]; return ( headerTitle="查询表格" actionRef={actionRef} rowKey="id" toolBarRender={() => []} request={async (params) => { const { data, success } = await productcontrollerGetstrength(params); return { total: data?.total || 0, data: data?.items || [], success, }; }} columns={columns} /> ); }; const CreateForm: React.FC<{ tableRef: React.MutableRefObject; }> = ({ tableRef }) => { const { message } = App.useApp(); return ( title="新建" trigger={ } autoFocusFirstInput drawerProps={{ destroyOnClose: true, }} onFinish={async (values) => { try { const { success, message: errMsg } = await productcontrollerCreatestrength(values); if (!success) { throw new Error(errMsg); } tableRef.current?.reload(); message.success('提交成功'); return true; } catch (error: any) { message.error(error.message); } }} > ); }; // const UpdateForm: React.FC<{ // tableRef: React.MutableRefObject; // values: API.Category; // }> = ({ tableRef, values: initialValues }) => { // const { message } = App.useApp(); // return ( // // title="编辑" // initialValues={initialValues} // trigger={ // // } // autoFocusFirstInput // drawerProps={{ // destroyOnClose: true, // }} // onFinish={async (values) => { // try { // const { success, message: errMsg } = // await productcontrollerUpdatestrength( // { id: initialValues.id }, // values, // ); // if (!success) { // throw new Error(errMsg); // } // message.success('提交成功'); // tableRef.current?.reload(); // return true; // } catch (error: any) { // message.error(error.message); // } // }} // > // // // // // ); // }; export default List;