Explorar o código

部门管理查询部门列表id添加过滤

wyn hai 5 meses
pai
achega
22fbf81682
Modificáronse 1 ficheiros con 6 adicións e 2 borrados
  1. 6 2
      src/components/DepartmentManagement.tsx

+ 6 - 2
src/components/DepartmentManagement.tsx

@@ -42,7 +42,9 @@ export default function DepartmentManagement() {
     setLoading(true);
     try {
       const data = await deptApi.getDeptPage(queryParams);
-      const treeData = handleTree(data || []);
+      // 过滤掉没有 id 的项,并确保 id 存在
+      const validDeptList = (data || []).filter((dept): dept is DeptVO & { id: number } => !!dept.id);
+      const treeData = handleTree(validDeptList);
       setList(treeData);
     } catch (error: any) {
       console.error('获取部门列表失败:', error);
@@ -80,7 +82,9 @@ export default function DepartmentManagement() {
     setLoading(true);
     deptApi.getDeptPage(resetParams)
       .then((data) => {
-        const treeData = handleTree(data || []);
+        // 过滤掉没有 id 的项,并确保 id 存在
+        const validDeptList = (data || []).filter((dept): dept is DeptVO & { id: number } => !!dept.id);
+        const treeData = handleTree(validDeptList);
         setList(treeData);
       })
       .catch((error: any) => {