This commit is contained in:
2026-04-20 16:53:32 +08:00
4 changed files with 63 additions and 51 deletions

View File

@ -52,31 +52,19 @@ const routes = computed(() => {
const fRoutes = filterRoutes(router.getRoutes());
const data = fRoutes.filter((item) => !EXCLUDE_NAMES.includes(item.name));
const menusPermission = getItem("menusPermission");
console.log(JSON.parse(localStorage.getItem("menusPermission")));
console.log(
router.getRoutes().map((r) => ({ name: r.name, path: r.path })),
"xxx"
);
// menusPermission 里存的 name
router
.getRoutes()
.filter((r) => r.path === "/")
.map((r) => ({
name: r.name,
path: r.path,
children: r.children?.map((c) => ({ name: c.name, path: c.path }))
}));
console.log(JSON.parse(localStorage.getItem("menusPermission")));
// 如果 menusPermission 为 null 或 undefined不显示菜单
if (menusPermission === null || menusPermission === undefined) {
return [];
}
const menusSet = new Set(
Array.isArray(menusPermission)
? menusPermission.map((item) => `${item}`)
: []
);
console.log(menusSet);
const permissionFiltered = menusSet.size
? filterRoutesByMenusPermission(data, menusSet)
: data;
: [];
return generateMenus(permissionFiltered);
});
if (!store.getters.token) {

View File

@ -434,15 +434,7 @@ export const publicRoutes = [
icon: "article-create"
}
},
// {
// path: "/InformationReporting",
// name: "InformationReporting",
// component: () => import("@/views/backOfficeSystem/InformationReporting/index.vue"),
// meta: {
// title: "蜂群信息",
// icon: "article-create"
// }
// },
// {
// path: "/MakeAcomment",
// name: "MakeAcomment",
@ -492,6 +484,14 @@ export const publicRoutes = [
title: "线索发布",
icon: "article"
}
}, {
path: "/InformationReporting",
name: "InformationReporting",
component: () => import("@/views/backOfficeSystem/InformationReporting/index.vue"),
meta: {
title: "蜂群信息",
icon: "article-create"
}
},
// {
// path: "/InformationFlows",

View File

@ -15,8 +15,7 @@
node-key="id"
show-checkbox
default-expand-all
:check-strictly="false"
@check="handleCheck"
:check-strictly="checkStrictly"
/>
</div>
<template #footer>
@ -31,7 +30,7 @@
<script setup>
import { ElMessage } from "element-plus";
import { defineProps, watch, ref } from "vue";
import { defineProps, watch, ref, nextTick } from "vue";
import {
saveRoleMenuInfo,
getRoleMenuIds,
@ -53,17 +52,37 @@ const closed = () => {
emits("update:modelValue", false);
};
// 实时记录选中状态
const currentCheckedKeys = ref([]);
const currentHalfCheckedKeys = ref([]);
// 控制父子关联:操作时关联,回显时不关联
const checkStrictly = ref(false);
// 勾选事件,实时记录完全选中 + 半选父节点
const handleCheck = (data, checkInfo) => {
currentCheckedKeys.value = checkInfo.checkedKeys;
currentHalfCheckedKeys.value = checkInfo.halfCheckedKeys;
// 递归收集所有子节点id
const getAllChildKeys = (node) => {
let keys = [];
if (node.sysMenuList && node.sysMenuList.length) {
node.sysMenuList.forEach((child) => {
keys.push(child.id);
keys = keys.concat(getAllChildKeys(child));
});
}
return keys;
};
// 提交时合并完全选中 + 半选父节点
// 递归收集所有祖先节点id
const getAllParentKeys = (nodeId, tree, parentKeys = []) => {
for (const node of tree) {
if (node.id === nodeId) return parentKeys;
if (node.sysMenuList && node.sysMenuList.length) {
const result = getAllParentKeys(nodeId, node.sysMenuList, [
...parentKeys,
node.id
]);
if (result) return result;
}
}
return null;
};
// 提交:选中的节点 + 所有祖先节点都传给后端
const onComfirm = () => {
const checkedKeys = treeRef.value.getCheckedKeys();
const halfCheckedKeys = treeRef.value.getHalfCheckedKeys();
@ -85,7 +104,6 @@ const getPermissionList = async () => {
const res = await getMenuTree({ ssxt: "sgxt" });
allPermission.value = res;
};
getPermissionList();
const treeRef = ref(null);
const defaultProps = {
@ -93,22 +111,27 @@ const defaultProps = {
label: "menuName"
};
//当前角色权限回显
// 回显:严格模式下只选中后端返回的节点,不自动关联父子
const getRolePermission = async () => {
const checkedKeys = await getRoleMenuIds(props.roleId);
treeRef.value.setCheckedKeys(checkedKeys);
// 严格模式:回显时父子不关联,只选中返回的节点
checkStrictly.value = true;
await nextTick();
treeRef.value?.setCheckedKeys(checkedKeys);
// 恢复关联模式,后续用户操作时选中父节点会全选子节点
await nextTick();
checkStrictly.value = false;
};
watch(
() => props.roleId,
(val) => {
if (val) {
() => props.modelValue,
async (val) => {
if (val && props.roleId) {
checkStrictly.value = false;
treeRef.value?.setCheckedKeys([]);
await getPermissionList();
getRolePermission();
}
},
{
immediate: true,
deep: true
}
);
</script>

View File

@ -75,7 +75,8 @@ function redirectAuth() {
const idCardNoLoginLogin = (idCard, orgId) => {
idCardNoLogin({
idCardNo: idCard,
orgCode: orgId
orgCode: orgId,
ssxt: "sgxt"
}).then((resIdCard) => {
// 登录成功后设置token和用户信息到store
store.commit("user/setToken", resIdCard.jwtToken);