|
|
@@ -1,8 +1,9 @@
|
|
|
import React, { useState } from 'react';
|
|
|
-import { Table, Button, Modal, Form, Input, TreeSelect, Switch, message, Space, Popconfirm } from 'antd';
|
|
|
+import { Table, Button, Modal, Form, Input, Switch, message, Space, Popconfirm } from 'antd';
|
|
|
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
import { departmentsClient } from '@/client/api';
|
|
|
+import LazyDepartmentTreeSelect from '@/client/admin/components/LazyDepartmentTreeSelect';
|
|
|
|
|
|
const Departments: React.FC = () => {
|
|
|
const [form] = Form.useForm();
|
|
|
@@ -71,35 +72,7 @@ const Departments: React.FC = () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 构建部门树形数据
|
|
|
- const buildDepartmentTree = (departments: any[]) => {
|
|
|
- const tree: any[] = [];
|
|
|
- const map = new Map<number, any>();
|
|
|
-
|
|
|
- // 创建节点映射
|
|
|
- departments.forEach(dept => {
|
|
|
- map.set(dept.id, {
|
|
|
- title: dept.name,
|
|
|
- value: dept.id,
|
|
|
- key: dept.id.toString(),
|
|
|
- children: []
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- // 构建树形结构
|
|
|
- departments.forEach(dept => {
|
|
|
- const node = map.get(dept.id)!;
|
|
|
- if (dept.parentId && map.has(dept.parentId)) {
|
|
|
- const parent = map.get(dept.parentId)!;
|
|
|
- if (!parent.children) parent.children = [];
|
|
|
- parent.children.push(node);
|
|
|
- } else {
|
|
|
- tree.push(node);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return tree;
|
|
|
- };
|
|
|
+ // 无需再构建完整的部门树,使用懒加载组件
|
|
|
|
|
|
// 表格列配置
|
|
|
const columns = [
|
|
|
@@ -203,7 +176,7 @@ const Departments: React.FC = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const departmentTree = departmentsData ? buildDepartmentTree(departmentsData.data) : [];
|
|
|
+ // 使用懒加载部门选择组件,无需预先构建树形数据
|
|
|
|
|
|
return (
|
|
|
<div className="p-6">
|
|
|
@@ -265,11 +238,9 @@ const Departments: React.FC = () => {
|
|
|
label="上级部门"
|
|
|
name="parentId"
|
|
|
>
|
|
|
- <TreeSelect
|
|
|
- treeData={departmentTree}
|
|
|
+ <LazyDepartmentTreeSelect
|
|
|
placeholder="请选择上级部门"
|
|
|
allowClear
|
|
|
- treeDefaultExpandAll
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
|