'-'
zhangwei
2025-07-28 bb576469eb1e2cb2bf8e1717902702ca28f5ef65
src/layout/hooks/useNav.ts
@@ -2,7 +2,7 @@
import { getConfig } from "@/config";
import { emitter } from "@/utils/mitt";
import Avatar from "@/assets/user.jpg";
import { getTopMenu } from "@/router/utils";
import { initRouter, getTopMenu, handleAliveRoute } from "@/router/utils";
import { useFullscreen } from "@vueuse/core";
import type { routeMetaType } from "../types";
import { useRouter, useRoute } from "vue-router";
@@ -14,6 +14,7 @@
import { usePermissionStoreHook } from "@/store/modules/permission";
import ExitFullscreen from "~icons/ri/fullscreen-exit-fill";
import Fullscreen from "~icons/ri/fullscreen-fill";
import { unref } from "vue";
const errorInfo =
  "The current routing configuration is incorrect, please check the configuration";
@@ -53,7 +54,12 @@
  /** 角色 */
  const userRoles = computed(() => {
    return useUserStoreHook()?.exRoles[0];
    return useUserStoreHook()?.nowRole;
  });
  /** 角色 */
  const userRolesList = computed(() => {
    return useUserStoreHook()?.exRoles ?? [];
  });
  const avatarsStyle = computed(() => {
@@ -83,7 +89,29 @@
    if (Title) document.title = `${meta.title} | ${Title}`;
    else document.title = meta.title;
  }
  /** 刷新路由 */
  function onFresh() {
    const { fullPath, query } = unref(route);
    router.replace({
      path: "/redirect" + fullPath,
      query
    });
    handleAliveRoute(route as ToRouteType, "refresh");
  }
  /** 切换角色 */
  const changRole = item => {
    useUserStoreHook()
      .changeLogoInExRule({
        ruleCode: item.code
      })
      .then(res => {
        if (res.code == 200) {
          // 获取后端路由
          initRouter();
          onFresh();
        }
      });
  };
  /** 退出登录 */
  function logout() {
    useUserStoreHook().logOut();
@@ -156,8 +184,10 @@
    pureApp,
    username,
    userRoles,
    userRolesList,
    userAvatar,
    avatarsStyle,
    tooltipEffect
    tooltipEffect,
    changRole
  };
}