zhangwei
2025-08-05 b94b71d44d62802bb8093f64a202d0176fdade50
src/router/utils.ts
@@ -26,6 +26,7 @@
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"];
// 动态路由
import { getAsyncRoutes } from "@/api/routes";
@@ -55,9 +56,15 @@
/** 过滤meta中showLink为false的菜单 */
function filterTree(data: RouteComponent[]) {
  const hasFlsh = useUserStoreHook().nowRole.hasFlsh;
  const newTree = cloneDeep(data).filter(
    (v: { meta: { showLink: boolean } }) => v.meta?.showLink !== false
    (v: { meta: { showLink: boolean } }) => {
      quanxianList.includes(v.path) ? (v.meta.showLink = hasFlsh) : null;
      return v.meta?.showLink !== false;
    }
  );
  console.log(newTree);
  newTree.forEach(
    (v: { children }) => v.children && (v.children = filterTree(v.children))
  );
@@ -85,7 +92,7 @@
/** 从localStorage里取出当前登录用户的角色roles,过滤无权限的菜单 */
function filterNoPermissionTree(data: RouteComponent[]) {
  const currentRoles =
    storageLocal().getItem<DataInfo<number>>(userKey)?.exRoles ?? [];
    storageLocal().getItem<DataInfo<number>>(userKey)?.roles ?? [];
  const newTree = cloneDeep(data).filter((v: any) =>
    isOneOfArray(v.meta?.roles, currentRoles)
  );