Просмотр исходного кода

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

RuoYi лет назад: 4
Родитель
Сommit
e798f46876
2 измененных файлов с 13 добавлено и 4 удалено
  1. 13 2
      ruoyi-ui/src/components/TopNav/index.vue
  2. 0 2
      ruoyi-ui/src/router/index.js

+ 13 - 2
ruoyi-ui/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;

+ 0 - 2
ruoyi-ui/src/router/index.js

@@ -5,8 +5,6 @@ Vue.use(Router)
5 5
 
6 6
 /* Layout */
7 7
 import Layout from '@/layout'
8
-import ParentView from '@/components/ParentView';
9
-import InnerLink from '@/layout/components/InnerLink'
10 8
 
11 9
 /**
12 10
  * Note: 路由配置项