From b0530ed9211230227a8f94e394eda779d5ae5fc1 Mon Sep 17 00:00:00 2001 From: birt <2499248221@qq.com> Date: 星期日, 13 四月 2025 01:51:52 +0800 Subject: [PATCH] birtzhang --- zhitan-vue/src/permission.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) diff --git a/zhitan-vue/src/permission.js b/zhitan-vue/src/permission.js index 30b428a..a521d95 100644 --- a/zhitan-vue/src/permission.js +++ b/zhitan-vue/src/permission.js @@ -8,6 +8,7 @@ import useUserStore from '@/store/modules/user' import useSettingsStore from '@/store/modules/settings' import usePermissionStore from '@/store/modules/permission' +import useTagsViewStore from '@/store/modules/tagsView' NProgress.configure({ showSpinner: false }); @@ -36,6 +37,28 @@ router.addRoute(route) // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛� } }) + + // 濡傛灉鏄椤碉紝鑷姩閲嶅畾鍚戝埌绗竴涓彍鍗� + if (to.path === '/' || to.path === '/index') { + const permissionStore = usePermissionStore() + const topMenus = permissionStore.topbarRouters.filter(menu => !menu.hidden) + if (topMenus.length > 0) { + // 璺宠浆鍒扮涓�涓彍鍗� + const firstMenu = topMenus[0] + if (firstMenu.children && firstMenu.children.length > 0) { + // 鏈夊瓙鑿滃崟锛岃烦杞埌绗竴涓瓙鑿滃崟 + const firstChild = firstMenu.children[0] + const path = firstMenu.path.endsWith('/') ? firstMenu.path + firstChild.path : `${firstMenu.path}/${firstChild.path}` + next({ path: path, replace: true }) + return + } else { + // 娌℃湁瀛愯彍鍗曪紝鐩存帴璺宠浆 + next({ path: firstMenu.path, replace: true }) + return + } + } + } + next({ ...to, replace: true }) // hack鏂规硶 纭繚addRoutes宸插畬鎴� }) }).catch(err => { @@ -45,6 +68,26 @@ }) }) } else { + // 濡傛灉鏄椤碉紝鑷姩閲嶅畾鍚戝埌绗竴涓彍鍗� + if (to.path === '/' || to.path === '/index') { + const permissionStore = usePermissionStore() + const topMenus = permissionStore.topbarRouters.filter(menu => !menu.hidden) + if (topMenus.length > 0) { + // 璺宠浆鍒扮涓�涓彍鍗� + const firstMenu = topMenus[0] + if (firstMenu.children && firstMenu.children.length > 0) { + // 鏈夊瓙鑿滃崟锛岃烦杞埌绗竴涓瓙鑿滃崟 + const firstChild = firstMenu.children[0] + const path = firstMenu.path.endsWith('/') ? firstMenu.path + firstChild.path : `${firstMenu.path}/${firstChild.path}` + next({ path: path, replace: true }) + return + } else { + // 娌℃湁瀛愯彍鍗曪紝鐩存帴璺宠浆 + next({ path: firstMenu.path, replace: true }) + return + } + } + } next() } } @@ -62,4 +105,12 @@ router.afterEach(() => { NProgress.done() + + // 绉婚櫎鎵�鏈夊彲鑳界殑棣栭〉鏍囩 + const tagsViewStore = useTagsViewStore(); + if (tagsViewStore && tagsViewStore.visitedViews) { + tagsViewStore.visitedViews = tagsViewStore.visitedViews.filter( + tag => tag.path !== '/index' && tag.path !== '/' && tag.name !== 'Index' + ); + } }) -- Gitblit v1.9.3