import { PlusOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { Popconfirm } from 'antd'; import React, { useCallback, useRef, useState } from 'react'; import ConfigurableDrawerForm, { type ConfigurableDrawerFormRef, } from '@/components/DrawerForm'; import EnhancedProTable from '@/components/EnhancedProTable'; import type { ToolbarAction } from '@/components/EnhancedProTable/types'; import { formStatusType } from '@/constants'; import { createDept, type DeptReqVO, type DeptVO, deleteDept, getDeptPage, updateDept, } from '@/services/system/dept'; import { handleTree } from '@/utils/tree'; import { baseDeptColumns, formColumns } from './config'; const SyStemDept = () => { const configurableDrawerRef = useRef(null); const tableRef = useRef(null); const [type, setType] = useState<'create' | 'update'>('create'); const [id, setId] = useState(0); const handleEdit = (record: DeptVO) => { setType('update'); setId(record.id); configurableDrawerRef.current?.open(record); }; const onFetch = async ( params: DeptReqVO & { pageSize?: number; current?: number; }, ) => { const data = await getDeptPage({ ...params, pageNo: params.current, pageSize: params.pageSize, }); return { data: handleTree(data), success: true, total: data.total, }; }; const handleAdd = () => { setType('create'); configurableDrawerRef.current?.open({}); }; const handleSubmit = useCallback( async (values: DeptVO) => { if (type === 'create') { await createDept(values); } else { await updateDept({ ...values, id, }); } tableRef.current?.reload(); return true; }, [type, id], ); const toolbarActions: ToolbarAction[] = [ { key: 'add', label: '新建', type: 'primary', icon: , onClick: handleAdd, }, ]; const actionColumns: ProColumns = { title: '操作', dataIndex: 'option', valueType: 'option', fixed: 'right', width: 120, render: (_text: React.ReactNode, record: DeptVO, _: any, action: any) => [ handleEdit(record)}> 编辑 , { await deleteDept(record.id); action?.reload(); }} okText="是" cancelText="否" > 删除 , ], }; const columns = [...baseDeptColumns, actionColumns]; return ( <> ref={tableRef} columns={columns} request={onFetch} toolbarActions={toolbarActions} headerTitle="租户列表" showIndex={false} showSelection={false} expandable={{ defaultExpandAllRows: true, }} /> ); }; export default SyStemDept;