浏览代码

fix: 跳转路由新增标签页 (#199)

* fix: 跳转路由新增标签页

* fix: 跳转路由新增标签页兼容

* perf: 删除取消watch监听
一万 3 年之前
父节点
当前提交
6971ba6c53

+ 7 - 0
src/layout/components/sidebar/horizontal.vue

@@ -45,6 +45,13 @@ watch(
   }
 );
 
+watch(
+  () => route.path,
+  () => {
+    menuSelect(route.path, routers);
+  }
+);
+
 function translationCh() {
   instance.locale = { locale: "zh" };
   locale.value = "zh";

+ 4 - 1
src/layout/components/sidebar/vertical.vue

@@ -49,7 +49,10 @@ onBeforeMount(() => {
 
 watch(
   () => route.path,
-  () => getSubMenuData(route.path)
+  () => {
+    getSubMenuData(route.path);
+    menuSelect(route.path, routers);
+  }
 );
 </script>
 

+ 7 - 0
src/layout/hooks/nav.ts

@@ -7,6 +7,7 @@ import { storageSession } from "/@/utils/storage";
 import { useAppStoreHook } from "/@/store/modules/app";
 import { Title } from "../../../public/serverConfig.json";
 import { useEpThemeStoreHook } from "/@/store/modules/epTheme";
+import { remainingPaths } from "/@/router/modules/index";
 
 export function useNav() {
   const pureApp = useAppStoreHook();
@@ -67,6 +68,7 @@ export function useNav() {
   }
 
   function menuSelect(indexPath: string, routers): void {
+    if (isRemaining(indexPath)) return;
     let parentPath = "";
     const parentPathIndex = indexPath.lastIndexOf("/");
     if (parentPathIndex > 0) {
@@ -93,6 +95,11 @@ export function useNav() {
     findCurrentRoute(indexPath, routers);
   }
 
+  // 判断路径是否参与菜单
+  function isRemaining(path: string): boolean {
+    return remainingPaths.includes(path);
+  }
+
   return {
     logout,
     backHome,

+ 5 - 0
src/router/modules/index.ts

@@ -40,3 +40,8 @@ export const constantRoutes: Array<RouteRecordRaw> = formatTwoStageRoutes(
 export const constantMenus: Array<RouteComponent> = ascending(routes).concat(
   ...remainingRouter
 );
+
+// 不参与菜单的路由
+export const remainingPaths = Object.keys(remainingRouter).map(v => {
+  return remainingRouter[v].path;
+});