From 65d03dc0145afe034b72759e0db78c69c12d584e Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Mon, 25 Nov 2024 22:30:03 +0800
Subject: [PATCH] 优化代码
---
ruoyi-ui/src/views/system/role/index.vue | 4 ++--
ruoyi-ui/src/components/Breadcrumb/index.vue | 19 +++++++++++--------
ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue | 7 +++----
ruoyi-ui/src/plugins/cache.js | 2 ++
4 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/ruoyi-ui/src/components/Breadcrumb/index.vue b/ruoyi-ui/src/components/Breadcrumb/index.vue
index c97e59d..cd28414 100644
--- a/ruoyi-ui/src/components/Breadcrumb/index.vue
+++ b/ruoyi-ui/src/components/Breadcrumb/index.vue
@@ -41,14 +41,15 @@
if (index !== 0) item = item.slice(1)
return item
})
- this.getMatched(pathList, this.$store.getters.sidebarRouters, matched)
+ this.getMatched(pathList, this.$store.getters.defaultRoutes, matched)
} else {
- matched = router.matched.filter((item) => item.meta && item.meta.title)
+ matched = router.matched.filter(item => item.meta && item.meta.title)
}
+ // 判断是否为首页
if (!this.isDashboard(matched[0])) {
matched = [{ path: "/index", meta: { title: "首页" } }].concat(matched)
}
- this.levelList = matched.filter((item) => item.meta && item.meta.title && item.meta.breadcrumb !== false)
+ this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
},
findPathNum(str, char = "/") {
let index = str.indexOf(char)
@@ -60,11 +61,13 @@
return num
},
getMatched(pathList, routeList, matched) {
- let data = routeList.find((item) => item.path == pathList[0])
- matched.push(data)
- if (data.children && pathList.length) {
- pathList.shift()
- this.getMatched(pathList, data.children, matched)
+ let data = routeList.find(item => item.path == pathList[0] || (item.name += '').toLowerCase() == pathList[0])
+ if (data) {
+ matched.push(data)
+ if (data.children && pathList.length) {
+ pathList.shift()
+ this.getMatched(pathList, data.children, matched)
+ }
}
},
isDashboard(route) {
diff --git a/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue b/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue
index ca3ae18..3a81d29 100644
--- a/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue
+++ b/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue
@@ -62,11 +62,10 @@
const showingChildren = children.filter(item => {
if (item.hidden) {
return false
- } else {
- // Temp set(will be used if only has one showing child)
- this.onlyOneChild = item
- return true
}
+ // Temp set(will be used if only has one showing child)
+ this.onlyOneChild = item
+ return true
})
// When there is only one child router, the child router is displayed by default
diff --git a/ruoyi-ui/src/plugins/cache.js b/ruoyi-ui/src/plugins/cache.js
index 6f71b8e..e912c9a 100644
--- a/ruoyi-ui/src/plugins/cache.js
+++ b/ruoyi-ui/src/plugins/cache.js
@@ -26,6 +26,7 @@
if (value != null) {
return JSON.parse(value)
}
+ return null
},
remove (key) {
sessionStorage.removeItem(key);
@@ -59,6 +60,7 @@
if (value != null) {
return JSON.parse(value)
}
+ return null
},
remove (key) {
localStorage.removeItem(key);
diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue
index cc9e541..db861e5 100644
--- a/ruoyi-ui/src/views/system/role/index.vue
+++ b/ruoyi-ui/src/views/system/role/index.vue
@@ -522,8 +522,8 @@
})
});
});
- this.title = "修改角色";
});
+ this.title = "修改角色";
},
/** 选择角色权限范围触发 */
dataScopeSelectChange(value) {
@@ -543,8 +543,8 @@
this.$refs.dept.setCheckedKeys(res.checkedKeys);
});
});
- this.title = "分配数据权限";
});
+ this.title = "分配数据权限";
},
/** 分配用户操作 */
handleAuthUser: function(row) {
--
Gitblit v1.9.3