Commit 2579e8549eb0ef2c63eab8e4dd145826306d2fba

Authored by YunaiV
1 parent ba74c587

v3.7.0 顶部菜单排除隐藏的默认路由

yudao-ui-admin/src/components/TopNav/index.vue
... ... @@ -87,7 +87,7 @@ export default {
87 87 // 默认激活的菜单
88 88 activeMenu() {
89 89 const path = this.$route.path;
90   - let activePath = this.routers[0].path;
  90 + let activePath = this.defaultRouter();
91 91 if (path.lastIndexOf("/") > 0) {
92 92 const tmpPath = path.substring(1, path.length);
93 93 activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
... ... @@ -100,7 +100,7 @@ export default {
100 100 }
101 101 var routes = this.activeRoutes(activePath);
102 102 if (routes.length === 0) {
103   - activePath = this.currentIndex || this.routers[0].path
  103 + activePath = this.currentIndex || this.defaultRouter()
104 104 this.activeRoutes(activePath);
105 105 }
106 106 return activePath;
... ... @@ -121,6 +121,17 @@ export default {
121 121 const width = document.body.getBoundingClientRect().width / 3;
122 122 this.visibleNumber = parseInt(width / 85);
123 123 },
  124 + // 默认激活的路由
  125 + defaultRouter() {
  126 + let router;
  127 + Object.keys(this.routers).some((key) => {
  128 + if (!this.routers[key].hidden) {
  129 + router = this.routers[key].path;
  130 + return true;
  131 + }
  132 + });
  133 + return router;
  134 + },
124 135 // 菜单选择事件
125 136 handleSelect(key, keyPath) {
126 137 this.currentIndex = key;
... ...