Просмотр исходного кода

[Fix 0000] 修复了自动登录时触发了路由导航循环的问题

houzekong 3 месяцев назад
Родитель
Сommit
1bbdd609c8
3 измененных файлов с 36 добавлено и 15 удалено
  1. 22 9
      src/api/sys/menu.ts
  2. 2 0
      src/api/sys/model/menuModel.ts
  3. 12 6
      src/hooks/system/useAutoLogin.ts

+ 22 - 9
src/api/sys/menu.ts

@@ -45,6 +45,27 @@ const generateStaticSealedMonitorRoute = (route: AppRouteRecordRaw, items: MineD
   }, []);
 };
 
+const processStaticRoutes = (routes: AppRouteRecordRaw[], mineStore: any) => {
+  const ignores = mineStore.getRoot?.description || '';
+  return routes.reduce((arr: AppRouteRecordRaw[], route) => {
+    // 首先处理子菜单,因为子菜单的权限和父菜单是独立的,避免子菜单还有内容的情况下被父菜单过滤
+    if (route.children && route.children.length) {
+      // 如果是生成式动态菜单,优先处理
+      if (route.meta.generation) {
+        route.children = generateStaticSealedMonitorRoute(route, mineStore.getDepartTree);
+      }
+      // 如果子菜单有内容,则递归处理
+      route.children = processStaticRoutes(route.children, mineStore);
+    }
+
+    // 最后检查,如果当前路由需要忽略且子菜单无内容则返回
+    if (ignores.includes(route.name as string) && !route.children?.length) return arr;
+
+    arr.push(route);
+    return arr;
+  }, []);
+};
+
 /**
  * @description: Get user menu based on id
  */
@@ -57,15 +78,7 @@ export const getMenuList: () => Promise<getMenuListResultModel> = () => {
       auth: res.auth || [],
       codeList: res.codeList || [],
       // menu: __STATIC_ROUTES__,
-      menu: __STATIC_ROUTES__.map((ele) => {
-        if (ele.children && ele.children.length && ele.meta?.generation) {
-          const template = ele.children[0];
-          const routes = generateStaticSealedMonitorRoute(template, mineStore.getDepartTree);
-
-          ele.children = routes;
-        }
-        return ele;
-      }),
+      menu: processStaticRoutes(__STATIC_ROUTES__, mineStore),
     };
   });
 };

+ 2 - 0
src/api/sys/model/menuModel.ts

@@ -28,4 +28,6 @@ export interface EnfMineTreeItem {
   memo?: string;
   /** 备注2 */
   memoDesc: string[];
+  /** 备注3 */
+  description: string;
 }

+ 12 - 6
src/hooks/system/useAutoLogin.ts

@@ -26,7 +26,13 @@ export function useAutoLogin() {
 
   /** 判断当前路由是否需要自动登录,本方法是同步方法,可以用于事先判断 */
   function validateRoute(route: RouteLocationNormalized) {
-    if (route.query && route.query[AUTO_LOGIN_URL_QUERY.key] === AUTO_LOGIN_URL_QUERY.val) {
+    if (
+      route.query &&
+      route.query[AUTO_LOGIN_URL_QUERY.key] === AUTO_LOGIN_URL_QUERY.val &&
+      route.query.deptId &&
+      route.query.account &&
+      route.query.username
+    ) {
       return true;
     }
 
@@ -42,7 +48,6 @@ export function useAutoLogin() {
     if (!validateRoute(route)) return;
 
     const { account, deptId, username } = route.query;
-    if (!account || !deptId || !username) return;
 
     const params = {
       account: account as string,
@@ -50,16 +55,17 @@ export function useAutoLogin() {
       username: username as string,
       checkKey: new Date().getTime(),
     };
+    delete route.query[AUTO_LOGIN_URL_QUERY.key];
+    delete route.query['account'];
+    delete route.query['deptId'];
+    delete route.query['username'];
     const userStore = useUserStore();
     try {
       await userStore.autoLogin({
         ...params,
         goHome: false,
       });
-      delete route.query[AUTO_LOGIN_URL_QUERY.key];
-      delete route.query['account'];
-      delete route.query['deptId'];
-      delete route.query['username'];
+      // delete route.query['username'];
       return;
     } catch (e) {
       const message = useMessage().createMessage;