作者 RuoYi

优化代码

@@ -41,14 +41,15 @@ export default { @@ -41,14 +41,15 @@ export default {
41 if (index !== 0) item = item.slice(1) 41 if (index !== 0) item = item.slice(1)
42 return item 42 return item
43 }) 43 })
44 - this.getMatched(pathList, this.$store.getters.sidebarRouters, matched) 44 + this.getMatched(pathList, this.$store.getters.defaultRoutes, matched)
45 } else { 45 } else {
46 - matched = router.matched.filter((item) => item.meta && item.meta.title) 46 + matched = router.matched.filter(item => item.meta && item.meta.title)
47 } 47 }
  48 + // 判断是否为首页
48 if (!this.isDashboard(matched[0])) { 49 if (!this.isDashboard(matched[0])) {
49 matched = [{ path: "/index", meta: { title: "首页" } }].concat(matched) 50 matched = [{ path: "/index", meta: { title: "首页" } }].concat(matched)
50 } 51 }
51 - this.levelList = matched.filter((item) => item.meta && item.meta.title && item.meta.breadcrumb !== false) 52 + this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
52 }, 53 },
53 findPathNum(str, char = "/") { 54 findPathNum(str, char = "/") {
54 let index = str.indexOf(char) 55 let index = str.indexOf(char)
@@ -60,11 +61,13 @@ export default { @@ -60,11 +61,13 @@ export default {
60 return num 61 return num
61 }, 62 },
62 getMatched(pathList, routeList, matched) { 63 getMatched(pathList, routeList, matched) {
63 - let data = routeList.find((item) => item.path == pathList[0])  
64 - matched.push(data)  
65 - if (data.children && pathList.length) {  
66 - pathList.shift()  
67 - this.getMatched(pathList, data.children, matched) 64 + let data = routeList.find(item => item.path == pathList[0] || (item.name += '').toLowerCase() == pathList[0])
  65 + if (data) {
  66 + matched.push(data)
  67 + if (data.children && pathList.length) {
  68 + pathList.shift()
  69 + this.getMatched(pathList, data.children, matched)
  70 + }
68 } 71 }
69 }, 72 },
70 isDashboard(route) { 73 isDashboard(route) {
@@ -62,11 +62,10 @@ export default { @@ -62,11 +62,10 @@ export default {
62 const showingChildren = children.filter(item => { 62 const showingChildren = children.filter(item => {
63 if (item.hidden) { 63 if (item.hidden) {
64 return false 64 return false
65 - } else {  
66 - // Temp set(will be used if only has one showing child)  
67 - this.onlyOneChild = item  
68 - return true  
69 } 65 }
  66 + // Temp set(will be used if only has one showing child)
  67 + this.onlyOneChild = item
  68 + return true
70 }) 69 })
71 70
72 // When there is only one child router, the child router is displayed by default 71 // When there is only one child router, the child router is displayed by default
@@ -26,6 +26,7 @@ const sessionCache = { @@ -26,6 +26,7 @@ const sessionCache = {
26 if (value != null) { 26 if (value != null) {
27 return JSON.parse(value) 27 return JSON.parse(value)
28 } 28 }
  29 + return null
29 }, 30 },
30 remove (key) { 31 remove (key) {
31 sessionStorage.removeItem(key); 32 sessionStorage.removeItem(key);
@@ -59,6 +60,7 @@ const localCache = { @@ -59,6 +60,7 @@ const localCache = {
59 if (value != null) { 60 if (value != null) {
60 return JSON.parse(value) 61 return JSON.parse(value)
61 } 62 }
  63 + return null
62 }, 64 },
63 remove (key) { 65 remove (key) {
64 localStorage.removeItem(key); 66 localStorage.removeItem(key);
@@ -522,8 +522,8 @@ export default { @@ -522,8 +522,8 @@ export default {
522 }) 522 })
523 }); 523 });
524 }); 524 });
525 - this.title = "修改角色";  
526 }); 525 });
  526 + this.title = "修改角色";
527 }, 527 },
528 /** 选择角色权限范围触发 */ 528 /** 选择角色权限范围触发 */
529 dataScopeSelectChange(value) { 529 dataScopeSelectChange(value) {
@@ -543,8 +543,8 @@ export default { @@ -543,8 +543,8 @@ export default {
543 this.$refs.dept.setCheckedKeys(res.checkedKeys); 543 this.$refs.dept.setCheckedKeys(res.checkedKeys);
544 }); 544 });
545 }); 545 });
546 - this.title = "分配数据权限";  
547 }); 546 });
  547 + this.title = "分配数据权限";
548 }, 548 },
549 /** 分配用户操作 */ 549 /** 分配用户操作 */
550 handleAuthUser: function(row) { 550 handleAuthUser: function(row) {