From 83af3dd309889489f541fc8e21894c9f79e5788c Mon Sep 17 00:00:00 2001 From: zhangwei <1504152376@qq.com> Date: 星期五, 22 八月 2025 16:09:58 +0800 Subject: [PATCH] 用户管理 --- src/router/utils.ts | 22 ++++++++++++++++++---- 1 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/router/utils.ts b/src/router/utils.ts index da5f0cd..8052c47 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -21,11 +21,15 @@ import { userKey, type DataInfo } from "@/utils/auth"; import { type menuType, routerArrays } from "@/layout/types"; import { useMultiTagsStoreHook } from "@/store/modules/multiTags"; +import { useUserStoreHook } from "@/store/modules/user"; import { usePermissionStoreHook } from "@/store/modules/permission"; const IFrame = () => import("@/layout/frame.vue"); // https://cn.vitejs.dev/guide/features.html#glob-import const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}"); +const quanxianList = ["/item"]; +const managerList = ["/user"]; +const userInfo = storageLocal().getItem<DataInfo<number>>(userKey); // 鍔ㄦ�佽矾鐢� import { getAsyncRoutes } from "@/api/routes"; @@ -54,9 +58,17 @@ /** 杩囨护meta涓璼howLink涓篺alse鐨勮彍鍗� */ function filterTree(data: RouteComponent[]) { + const hasFlsh = useUserStoreHook().nowRole.hasFlsh; + const isManager = useUserStoreHook().isManager; const newTree = cloneDeep(data).filter( - (v: { meta: { showLink: boolean } }) => v.meta?.showLink !== false + (v: { path: string; meta: { showLink: boolean } }) => { + quanxianList.includes(v.path) ? (v.meta.showLink = hasFlsh) : null; + managerList.includes(v.path) ? (v.meta.showLink = isManager) : null; + return v.meta?.showLink !== false; + } ); + console.log(newTree); + newTree.forEach( (v: { children }) => v.children && (v.children = filterTree(v.children)) ); @@ -151,7 +163,7 @@ /** 澶勭悊鍔ㄦ�佽矾鐢憋紙鍚庣杩斿洖鐨勮矾鐢憋級 */ function handleAsyncRoutes(routeList) { - if (routeList.length === 0) { + if (routeList?.length === 0) { usePermissionStoreHook().handleWholeMenus(routeList); } else { formatFlatteningRoutes(addAsyncRoutes(routeList)).map( @@ -227,7 +239,7 @@ * @returns 杩斿洖澶勭悊鍚庣殑涓�缁磋矾鐢� */ function formatFlatteningRoutes(routesList: RouteRecordRaw[]) { - if (routesList.length === 0) return routesList; + if (routesList?.length === 0) return routesList; let hierarchyList = buildHierarchyTree(routesList); for (let i = 0; i < hierarchyList.length; i++) { if (hierarchyList[i].children) { @@ -246,7 +258,7 @@ * @returns 杩斿洖灏嗕竴缁存暟缁勯噸鏂板鐞嗘垚瑙勫畾璺敱鐨勬牸寮� */ function formatTwoStageRoutes(routesList: RouteRecordRaw[]) { - if (routesList.length === 0) return routesList; + if (routesList?.length === 0) return routesList; const newRoutesList: RouteRecordRaw[] = []; routesList.forEach((v: RouteRecordRaw) => { if (v.path === "/") { @@ -387,6 +399,8 @@ usePermissionStoreHook().wholeMenus[0]?.children[0] ); tag && useMultiTagsStoreHook().handleTags("push", topMenu); + // console.log(topMenu, "topMenu"); + return topMenu; } -- Gitblit v1.9.1