From 6971ba6c53d82380f95f7d978adb163a074604c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=87?= <52823142+Ten-K@users.noreply.github.com> Date: Mon, 28 Feb 2022 22:08:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B7=B3=E8=BD=AC=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A0=87=E7=AD=BE=E9=A1=B5=20(#199)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 跳转路由新增标签页 * fix: 跳转路由新增标签页兼容 * perf: 删除取消watch监听 --- src/layout/components/sidebar/horizontal.vue | 7 +++++++ src/layout/components/sidebar/vertical.vue | 5 ++++- src/layout/hooks/nav.ts | 7 +++++++ src/router/modules/index.ts | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/layout/components/sidebar/horizontal.vue b/src/layout/components/sidebar/horizontal.vue index dd8c84ce3..217fa6ce9 100644 --- a/src/layout/components/sidebar/horizontal.vue +++ b/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"; diff --git a/src/layout/components/sidebar/vertical.vue b/src/layout/components/sidebar/vertical.vue index 56d1dc8c3..94b81085c 100644 --- a/src/layout/components/sidebar/vertical.vue +++ b/src/layout/components/sidebar/vertical.vue @@ -49,7 +49,10 @@ onBeforeMount(() => { watch( () => route.path, - () => getSubMenuData(route.path) + () => { + getSubMenuData(route.path); + menuSelect(route.path, routers); + } ); diff --git a/src/layout/hooks/nav.ts b/src/layout/hooks/nav.ts index ba7a63456..bb13d7ad8 100644 --- a/src/layout/hooks/nav.ts +++ b/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, diff --git a/src/router/modules/index.ts b/src/router/modules/index.ts index aaa4a9bfa..4e5f51cb8 100644 --- a/src/router/modules/index.ts +++ b/src/router/modules/index.ts @@ -40,3 +40,8 @@ export const constantRoutes: Array = formatTwoStageRoutes( export const constantMenus: Array = ascending(routes).concat( ...remainingRouter ); + +// 不参与菜单的路由 +export const remainingPaths = Object.keys(remainingRouter).map(v => { + return remainingRouter[v].path; +});