作者 RuoYi

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

@@ -87,7 +87,7 @@ export default { @@ -87,7 +87,7 @@ export default {
87 // 默认激活的菜单 87 // 默认激活的菜单
88 activeMenu() { 88 activeMenu() {
89 const path = this.$route.path; 89 const path = this.$route.path;
90 - let activePath = this.routers[0].path; 90 + let activePath = this.defaultRouter();
91 if (path.lastIndexOf("/") > 0) { 91 if (path.lastIndexOf("/") > 0) {
92 const tmpPath = path.substring(1, path.length); 92 const tmpPath = path.substring(1, path.length);
93 activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); 93 activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
@@ -100,7 +100,7 @@ export default { @@ -100,7 +100,7 @@ export default {
100 } 100 }
101 var routes = this.activeRoutes(activePath); 101 var routes = this.activeRoutes(activePath);
102 if (routes.length === 0) { 102 if (routes.length === 0) {
103 - activePath = this.currentIndex || this.routers[0].path 103 + activePath = this.currentIndex || this.defaultRouter()
104 this.activeRoutes(activePath); 104 this.activeRoutes(activePath);
105 } 105 }
106 return activePath; 106 return activePath;
@@ -121,6 +121,17 @@ export default { @@ -121,6 +121,17 @@ export default {
121 const width = document.body.getBoundingClientRect().width / 3; 121 const width = document.body.getBoundingClientRect().width / 3;
122 this.visibleNumber = parseInt(width / 85); 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 handleSelect(key, keyPath) { 136 handleSelect(key, keyPath) {
126 this.currentIndex = key; 137 this.currentIndex = key;
@@ -5,8 +5,6 @@ Vue.use(Router) @@ -5,8 +5,6 @@ Vue.use(Router)
5 5
6 /* Layout */ 6 /* Layout */
7 import Layout from '@/layout' 7 import Layout from '@/layout'
8 -import ParentView from '@/components/ParentView';  
9 -import InnerLink from '@/layout/components/InnerLink'  
10 8
11 /** 9 /**
12 * Note: 路由配置项 10 * Note: 路由配置项