From 6061c3548fb5c0e1bbae21c7648d4a4400e994a6 Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期一, 25 十一月 2024 22:20:30 +0800 Subject: [PATCH] 优化代码 --- src/views/system/role/index.vue | 4 ++-- src/plugins/cache.js | 2 ++ src/layout/components/Sidebar/SidebarItem.vue | 6 ++---- src/router/index.js | 3 +-- src/components/Breadcrumb/index.vue | 14 ++++++++------ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/components/Breadcrumb/index.vue b/src/components/Breadcrumb/index.vue index 1567961..eb5df96 100644 --- a/src/components/Breadcrumb/index.vue +++ b/src/components/Breadcrumb/index.vue @@ -28,7 +28,7 @@ if (index !== 0) item = item.slice(1) return item }) - getMatched(pathList, permissionStore.sidebarRouters, matched) + getMatched(pathList, permissionStore.defaultRoutes, matched) } else { matched = route.matched.filter((item) => item.meta && item.meta.title) } @@ -48,11 +48,13 @@ return num } function getMatched(pathList, routeList, matched) { - let data = routeList.find((item) => item.path == pathList[0]) - matched.push(data) - if (data.children && pathList.length) { - pathList.shift() - 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() + getMatched(pathList, data.children, matched) + } } } function isDashboard(route) { diff --git a/src/layout/components/Sidebar/SidebarItem.vue b/src/layout/components/Sidebar/SidebarItem.vue index b92ace2..7d292fa 100644 --- a/src/layout/components/Sidebar/SidebarItem.vue +++ b/src/layout/components/Sidebar/SidebarItem.vue @@ -57,11 +57,9 @@ const showingChildren = children.filter(item => { if (item.hidden) { return false - } else { - // Temp set(will be used if only has one showing child) - onlyOneChild.value = item - return true } + onlyOneChild.value = item + return true }) // When there is only one child router, the child router is displayed by default diff --git a/src/plugins/cache.js b/src/plugins/cache.js index 6f71b8e..e912c9a 100644 --- a/src/plugins/cache.js +++ b/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/src/router/index.js b/src/router/index.js index b05d1c1..80a843f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -166,9 +166,8 @@ scrollBehavior(to, from, savedPosition) { if (savedPosition) { return savedPosition - } else { - return { top: 0 } } + return { top: 0 } }, }); diff --git a/src/views/system/role/index.vue b/src/views/system/role/index.vue index 01dd03a..5bdb7e7 100644 --- a/src/views/system/role/index.vue +++ b/src/views/system/role/index.vue @@ -443,8 +443,8 @@ }); }); }); - title.value = "淇敼瑙掕壊"; }); + title.value = "淇敼瑙掕壊"; } /** 鏍规嵁瑙掕壊ID鏌ヨ鑿滃崟鏍戠粨鏋� */ @@ -558,8 +558,8 @@ }); }); }); - title.value = "鍒嗛厤鏁版嵁鏉冮檺"; }); + title.value = "鍒嗛厤鏁版嵁鏉冮檺"; } /** 鎻愪氦鎸夐挳锛堟暟鎹潈闄愶級 */ -- Gitblit v1.9.3