From 2579e8549eb0ef2c63eab8e4dd145826306d2fba Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 17 Feb 2022 00:49:46 +0800 Subject: [PATCH] v3.7.0 顶部菜单排除隐藏的默认路由 --- yudao-ui-admin/src/components/TopNav/index.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/yudao-ui-admin/src/components/TopNav/index.vue b/yudao-ui-admin/src/components/TopNav/index.vue index 47f62df..ca37281 100644 --- a/yudao-ui-admin/src/components/TopNav/index.vue +++ b/yudao-ui-admin/src/components/TopNav/index.vue @@ -87,7 +87,7 @@ export default { // 默认激活的菜单 activeMenu() { const path = this.$route.path; - let activePath = this.routers[0].path; + let activePath = this.defaultRouter(); if (path.lastIndexOf("/") > 0) { const tmpPath = path.substring(1, path.length); activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); @@ -100,7 +100,7 @@ export default { } var routes = this.activeRoutes(activePath); if (routes.length === 0) { - activePath = this.currentIndex || this.routers[0].path + activePath = this.currentIndex || this.defaultRouter() this.activeRoutes(activePath); } return activePath; @@ -121,6 +121,17 @@ export default { const width = document.body.getBoundingClientRect().width / 3; this.visibleNumber = parseInt(width / 85); }, + // 默认激活的路由 + defaultRouter() { + let router; + Object.keys(this.routers).some((key) => { + if (!this.routers[key].hidden) { + router = this.routers[key].path; + return true; + } + }); + return router; + }, // 菜单选择事件 handleSelect(key, keyPath) { this.currentIndex = key; -- libgit2 0.21.4