Explorar el Código

兼容顶部栏一级菜单内部跳转

RuoYi hace 5 años
padre
commit
1eb9581d36
Se han modificado 1 ficheros con 27 adiciones y 13 borrados
  1. 27 13
      ruoyi-ui/src/components/TopNav/index.vue

+ 27 - 13
ruoyi-ui/src/components/TopNav/index.vue

@@ -30,9 +30,6 @@
30
 <script>
30
 <script>
31
 import { constantRoutes } from "@/router";
31
 import { constantRoutes } from "@/router";
32
 
32
 
33
-// 不需要激活的路由
34
-const noactiveList = ["/user/profile", "/dict/type", "/gen/edit", "/job/log"];
35
-
36
 export default {
33
 export default {
37
   data() {
34
   data() {
38
     return {
35
     return {
@@ -40,6 +37,8 @@ export default {
40
       visibleNumber: 5,
37
       visibleNumber: 5,
41
       // 是否为首次加载
38
       // 是否为首次加载
42
       isFrist: false,
39
       isFrist: false,
40
+      // 当前激活菜单的 index
41
+      currentIndex: undefined
43
     };
42
     };
44
   },
43
   },
45
   computed: {
44
   computed: {
@@ -48,7 +47,12 @@ export default {
48
       let topMenus = [];
47
       let topMenus = [];
49
       this.routers.map((menu) => {
48
       this.routers.map((menu) => {
50
         if (menu.hidden !== true) {
49
         if (menu.hidden !== true) {
51
-          topMenus.push(menu);
50
+          // 兼容顶部栏一级菜单内部跳转
51
+          if (menu.path === "/") {
52
+              topMenus.push(menu.children[0]);
53
+          } else {
54
+              topMenus.push(menu);
55
+          }
52
         }
56
         }
53
       });
57
       });
54
       return topMenus;
58
       return topMenus;
@@ -63,7 +67,11 @@ export default {
63
       this.routers.map((router) => {
67
       this.routers.map((router) => {
64
         for (var item in router.children) {
68
         for (var item in router.children) {
65
           if (router.children[item].parentPath === undefined) {
69
           if (router.children[item].parentPath === undefined) {
66
-            router.children[item].path = router.path + "/" + router.children[item].path;
70
+            if(router.path === "/") {
71
+              router.children[item].path = "/redirect/" + router.children[item].path;
72
+            } else {
73
+              router.children[item].path = router.path + "/" + router.children[item].path;
74
+            }
67
             router.children[item].parentPath = router.path;
75
             router.children[item].parentPath = router.path;
68
           }
76
           }
69
           childrenMenus.push(router.children[item]);
77
           childrenMenus.push(router.children[item]);
@@ -75,12 +83,6 @@ export default {
75
     activeMenu() {
83
     activeMenu() {
76
       const path = this.$route.path;
84
       const path = this.$route.path;
77
       let activePath = this.routers[0].path;
85
       let activePath = this.routers[0].path;
78
-      var noactive = noactiveList.some(function (item) {
79
-        return path.indexOf(item) !== -1;
80
-      });
81
-      if (noactive) {
82
-        return;
83
-      }
84
       if (path.lastIndexOf("/") > 0) {
86
       if (path.lastIndexOf("/") > 0) {
85
         const tmpPath = path.substring(1, path.length);
87
         const tmpPath = path.substring(1, path.length);
86
         activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
88
         activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
@@ -91,7 +93,11 @@ export default {
91
           activePath = "index";
93
           activePath = "index";
92
         }
94
         }
93
       }
95
       }
94
-      this.activeRoutes(activePath);
96
+      var routes = this.activeRoutes(activePath);
97
+      if (routes.length === 0) {
98
+        activePath = this.currentIndex || this.routers[0].path
99
+        this.activeRoutes(activePath);
100
+      }
95
       return activePath;
101
       return activePath;
96
     },
102
     },
97
   },
103
   },
@@ -112,10 +118,15 @@ export default {
112
     },
118
     },
113
     // 菜单选择事件
119
     // 菜单选择事件
114
     handleSelect(key, keyPath) {
120
     handleSelect(key, keyPath) {
121
+      this.currentIndex = key;
115
       if (key.indexOf("http://") !== -1 || key.indexOf("https://") !== -1) {
122
       if (key.indexOf("http://") !== -1 || key.indexOf("https://") !== -1) {
116
         // http(s):// 路径新窗口打开
123
         // http(s):// 路径新窗口打开
117
         window.open(key, "_blank");
124
         window.open(key, "_blank");
125
+      } else if (key.indexOf("/redirect") !== -1) {
126
+        // /redirect 路径内部打开
127
+        this.$router.push({ path: key.replace("/redirect", "") });
118
       } else {
128
       } else {
129
+        // 显示左侧联动菜单
119
         this.activeRoutes(key);
130
         this.activeRoutes(key);
120
       }
131
       }
121
     },
132
     },
@@ -129,7 +140,10 @@ export default {
129
           }
140
           }
130
         });
141
         });
131
       }
142
       }
132
-      this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
143
+      if(routes.length > 0) {
144
+        this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
145
+      }
146
+      return routes;
133
     }
147
     }
134
   },
148
   },
135
 };
149
 };