From 42c9e19f80e588dda6b3ae29c2d94d0da5c50691 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 31 Mar 2025 21:53:08 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=A7=92=E8=89=B2=20role=20?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=20100%=EF=BC=88?= =?UTF-8?q?=E5=9F=BA=E4=BA=8E=20VbenTree=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/assign-data-permission-form.vue | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue b/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue index 66e21ded5..434445aed 100644 --- a/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue +++ b/apps/web-antd/src/views/system/role/modules/assign-data-permission-form.vue @@ -23,10 +23,9 @@ const formData = ref(); const deptTree = ref([]); // 部门树 const deptLoading = ref(false); // 加载部门列表 const isAllSelected = ref(false); // 全选状态 -const isExpanded = ref(true); // 展开状态 -const isDeptCheckStrictly = ref(true); // 父子联动状态 - -const treeRef = ref(); // 树组件引用 +const isExpanded = ref(false); // 展开状态 +const isCheckStrictly = ref(true); // 父子联动状态 +const expandedKeys = ref([]); // 展开的节点 const [Form, formApi] = useVbenForm({ layout: 'horizontal', @@ -75,6 +74,7 @@ const [Modal, modalApi] = useVbenModal({ await formApi.setValues(formData.value); // 加载部门列表 await loadDeptTree(); + toggleExpandAll(); } finally { modalApi.lock(false); } @@ -85,8 +85,8 @@ const [Modal, modalApi] = useVbenModal({ async function loadDeptTree() { deptLoading.value = true; try { - const res = await getDeptList(); - deptTree.value = handleTree(res); + const data = await getDeptList(); + deptTree.value = handleTree(data); } finally { deptLoading.value = false; } @@ -95,40 +95,33 @@ async function loadDeptTree() { /** 全选/全不选 */ function toggleSelectAll() { isAllSelected.value = !isAllSelected.value; - if (treeRef.value) { - // 根据VbenTree组件的API,调用相应方法全选或全不选 - if (isAllSelected.value) { - // 全选逻辑,可能需要根据实际实现调整 - const allIds = getAllNodeIds(deptTree.value); - formApi.setFieldValue('dataScopeDeptIds', allIds); - } else { - // 全不选 - formApi.setFieldValue('dataScopeDeptIds', []); - } + if (isAllSelected.value) { + const allIds = getAllNodeIds(deptTree.value); + formApi.setFieldValue('dataScopeDeptIds', allIds); + } else { + formApi.setFieldValue('dataScopeDeptIds', []); } } /** 展开/折叠所有节点 */ -function toggleExpandAll() { +async function toggleExpandAll() { isExpanded.value = !isExpanded.value; - debugger - if (treeRef.value) { - if (isExpanded.value) { - treeRef.value.expandAll(); // 展开所有节点 - } else { - treeRef.value.collapseAll(); // 折叠所有节点 - } + if (isExpanded.value) { + // 获取所有节点的 ID + expandedKeys.value = getAllNodeIds(deptTree.value); + } else { + expandedKeys.value = []; } } /** 切换父子联动 */ function toggleCheckStrictly() { - isDeptCheckStrictly.value = !isDeptCheckStrictly.value; + isCheckStrictly.value = !isCheckStrictly.value; } -/** 递归获取所有节点ID */ -function getAllNodeIds(nodes, ids = []) { - nodes.forEach((node) => { +/** 递归获取所有节点 ID */ +function getAllNodeIds(nodes: any[], ids: number[] = []): number[] { + nodes.forEach((node: any) => { ids.push(node.id); if (node.children && node.children.length > 0) { getAllNodeIds(node.children, ids); @@ -143,16 +136,17 @@ function getAllNodeIds(nodes, ids = []) {
@@ -165,7 +159,7 @@ function getAllNodeIds(nodes, ids = []) { 全部展开 - + 父子联动