diff --git a/src/components/Application/search/AppSearch.vue b/src/components/Application/search/AppSearch.vue index ea0b56e..0b481b3 100644 --- a/src/components/Application/search/AppSearch.vue +++ b/src/components/Application/search/AppSearch.vue @@ -178,8 +178,7 @@ const results: SearchResult[] = []; menu.forEach((item) => { const { title, path, key, icon, children, meta } = item; - - const combinedPath = currentPath ? `${currentPath}/${path}` : path; + const combinedPath = path ? path : currentPath; const combinedName = accumulatedName ? `${accumulatedName} > ${title}` : title; if (!meta?.hidden && reg.test(title) && !children?.length) { diff --git a/src/views/system/role/auth.vue b/src/views/system/role/auth.vue index cc866d7..49a9488 100644 --- a/src/views/system/role/auth.vue +++ b/src/views/system/role/auth.vue @@ -24,6 +24,7 @@ :height="600" :checked-keys="checkedKeys" :expanded-keys="expandedKeys" + :indeterminate-keys="halfCheckedIds" @update:checked-keys="onChangePermissionsTree" ref="treeRef" @update:expanded-keys="handleExpands" @@ -68,6 +69,7 @@ const expandFlag = ref(false); const allMenuIds = ref([]); const checkedKeys = ref([]); + const halfCheckedIds = ref([]); const expandedKeys = ref([]); const menuArray = ref([]); const menuTree = ref([]); @@ -101,8 +103,8 @@ // 获取所有选择的节点 const getDeptAllCheckedKeys = () => { - const checkedKeys = treeRef.value?.getCheckedData(); - const halfCheckedKeys = treeRef.value?.getIndeterminateData()!; + const checkedKeys = treeRef.value?.getCheckedData().keys; + const halfCheckedKeys = treeRef.value?.getIndeterminateData().keys; checkedKeys?.unshift.apply(checkedKeys, halfCheckedKeys); return checkedKeys; }; @@ -121,7 +123,7 @@ /** * 关闭窗体 */ - const dialogClose = () => { + const handleClose = () => { emit('update:visible', false); }; @@ -145,13 +147,61 @@ const data = await getRoleMenuList(props.roleId); menuTree.value = buildTree(data); menuArray.value = data; - checkedKeys.value = []; menuArray.value.map((item) => { - if (item.checked) { - checkedKeys.value.push(item.id); + allMenuIds.value.push(item.id); + }); + const keys = checkTree(menuTree.value, 0, [], []); + checkedKeys.value = keys.checkedIds; + halfCheckedIds.value = keys.halfCheckedIds; + }; + /** + * 选中树结构 + * @param nodes 节点 + * @param parentId 上级ID + * @param checkedIds 选中ID集合 + * @param halfCheckedIds + */ + function checkTree(nodes, parentId = null, checkedIds, halfCheckedIds) { + nodes.forEach((node) => { + let allChildrenChecked = true; + let someChildrenChecked = false; + + // 检查子节点 + if (node.children && node.children.length > 0) { + checkTree(node.children, node.id, checkedIds, halfCheckedIds); // 递归检查子节点 + + // 遍历子节点来确定父节点的状态 + node.children.forEach((child) => { + if (child.checked) { + someChildrenChecked = true; + // 如果子节点被选中,可能需要将子节点的ID也加入checkedIds(取决于需求) + // 但通常我们只关心父节点和叶子节点的checked状态 + halfCheckedIds.push(child.id); // 可选,根据需要添加 + } else { + allChildrenChecked = false; + } + }); + + // 根据子节点的状态更新父节点的状态及数组 + if (allChildrenChecked) { + // 如果所有子节点都选中,则父节点也被视为选中 + checkedIds.push(node.id); + } else if (someChildrenChecked) { + // 如果部分子节点选中,则父节点被视为半选 + halfCheckedIds.push(parentId || node.id); // parentId用于处理递归时的父节点 + } + // 注意:如果所有子节点都未选中,则父节点不会被添加到任何数组中 + // 但如果业务需求是即使所有子节点都未选中,父节点也需要以某种方式被标记, + // 你需要在这里添加额外的逻辑。 + } else { + // 如果是叶子节点,直接根据其checked状态处理 + if (node.checked) { + checkedIds.push(node.id); + } } }); - }; + return { checkedIds, halfCheckedIds }; + } /** * 钩子函数