import { fetchDeleteDept } from '@/services/dept'; import { ReloadOutlined } from '@ant-design/icons'; import { PageContainer, ProCard } from '@ant-design/pro-components'; import { useIntl } from '@umijs/max'; import { Button, Empty, Popconfirm, Space, Spin, Tooltip, Tree, message } from 'antd'; import type { DataNode } from 'antd/es/tree'; import { DeptForm } from './components/Form'; import { DeptUserTable } from './components/UserTable'; import { useDeptPage } from './hooks/useDeptPage'; export default function DeptPage() { const intl = useIntl(); const { loading, treeData, selectedDeptId, setSelectedDeptId, selectedDeptIds, selectedDeptName, filteredUsers, noDeptUsers, loadData, productRolesBase, } = useDeptPage(); const handleDelete = async (id: number) => { const res = await fetchDeleteDept({ id }); if (!res.success) return; message.success('删除成功'); if (selectedDeptId === id) setSelectedDeptId(undefined); loadData(); }; const renderTitle = (node: API.DeptItem) => ( {node.name} e.stopPropagation()}> 编辑} /> 新建子部门} /> handleDelete(node.id)}> 删除 ); const renderNodes = (items: API.DeptItem[]): DataNode[] => items.map((item) => ({ key: item.id, title: renderTitle(item), children: item.children ? renderNodes(item.children) : undefined, })); return (
{intl.formatMessage({ id: 'admin.dept.createRoot' })} } />
{treeData.length > 0 && ( setSelectedDeptId(keys[0] as number | undefined)} /> )}
{selectedDeptIds ? ( ) : ( )}
); }