From 9d4d9d33980e63ca5a00d46b875764c53b1efd64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E9=94=90=E6=B3=A2?= <10549902+zhuangruibo@user.noreply.gitee.com> Date: Sun, 26 Apr 2026 21:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=8A=9F=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/system/dept/index-fold.vue | 343 ++++++++++++++++++ .../src/views/system/dept/index.vue | 53 +-- 2 files changed, 358 insertions(+), 38 deletions(-) create mode 100644 zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index-fold.vue diff --git a/zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index-fold.vue b/zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index-fold.vue new file mode 100644 index 00000000..b039f468 --- /dev/null +++ b/zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index-fold.vue @@ -0,0 +1,343 @@ + + + diff --git a/zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index.vue b/zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index.vue index b039f468..6339df99 100644 --- a/zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index.vue +++ b/zdxt-web-client/zdxt-admin-plus-ui/src/views/system/dept/index.vue @@ -38,15 +38,13 @@ @@ -162,10 +160,8 @@ const deptList = ref([]); const loading = ref(true); const showSearch = ref(true); const deptOptions = ref([]); -const isExpandAll = ref(false); +const isExpandAll = ref(true); const deptUserList = ref([]); -const childrenMap = ref>(new Map()); -const tableKey = ref(0); const dialog = reactive({ visible: false, @@ -208,39 +204,15 @@ const data = reactive>(initData); const { queryParams, form, rules } = toRefs>(data); -/** 查询部门列表 */ +/** 查询菜单列表 */ const getList = async () => { loading.value = true; const res = await listDept(queryParams.value); - tableKey.value++; - await nextTick(); - buildLazyData(res.data); - loading.value = false; -}; - -/** 构建懒加载数据(客户端缓存,按需渲染) */ -const buildLazyData = (data: DeptVO[]) => { - const map = new Map(); - const allIds = new Set(data.map((d) => String(d.deptId))); - - for (const item of data) { - const pid = String(item.parentId); - if (!map.has(pid)) map.set(pid, []); - map.get(pid)!.push(item); - } - - for (const item of data) { - (item as any).hasChildren = map.has(String(item.deptId)); + const data = proxy?.handleTree(res.data, 'deptId'); + if (data) { + deptList.value = data; } - - childrenMap.value = map; - deptList.value = data.filter((d) => !allIds.has(String(d.parentId))); -}; - -/** 懒加载子节点 */ -const loadChildren = (row: DeptVO, _treeNode: any, resolve: (data: DeptVO[]) => void) => { - const children = childrenMap.value.get(String(row.deptId)) || []; - resolve(children); + loading.value = false; }; /** 查询当前部门的所有用户 */ @@ -272,11 +244,16 @@ const resetQuery = () => { handleQuery(); }; -/** 展开/折叠操作(仅切换根节点) */ +/** 展开/折叠操作 */ const handleToggleExpandAll = () => { isExpandAll.value = !isExpandAll.value; - deptList.value.forEach((item) => { - deptTableRef.value?.toggleRowExpansion(item, isExpandAll.value); + toggleExpandAll(deptList.value, isExpandAll.value); +}; +/** 展开/折叠所有 */ +const toggleExpandAll = (data: DeptVO[], status: boolean) => { + data.forEach((item) => { + deptTableRef.value?.toggleRowExpansion(item, status); + if (item.children && item.children.length > 0) toggleExpandAll(item.children, status); }); };