优化代码

This commit is contained in:
RuoYi 2024-11-25 22:20:30 +08:00
parent f8c4968b33
commit 6061c3548f
5 changed files with 15 additions and 14 deletions

View File

@ -28,7 +28,7 @@ function getBreadcrumb() {
if (index !== 0) item = item.slice(1) if (index !== 0) item = item.slice(1)
return item return item
}) })
getMatched(pathList, permissionStore.sidebarRouters, matched) getMatched(pathList, permissionStore.defaultRoutes, matched)
} else { } else {
matched = route.matched.filter((item) => item.meta && item.meta.title) matched = route.matched.filter((item) => item.meta && item.meta.title)
} }
@ -48,11 +48,13 @@ function findPathNum(str, char = "/") {
return num return num
} }
function getMatched(pathList, routeList, matched) { function getMatched(pathList, routeList, matched) {
let data = routeList.find((item) => item.path == pathList[0]) let data = routeList.find(item => item.path == pathList[0] || (item.name += '').toLowerCase() == pathList[0])
matched.push(data) if (data) {
if (data.children && pathList.length) { matched.push(data)
pathList.shift() if (data.children && pathList.length) {
getMatched(pathList, data.children, matched) pathList.shift()
getMatched(pathList, data.children, matched)
}
} }
} }
function isDashboard(route) { function isDashboard(route) {

View File

@ -57,11 +57,9 @@ function hasOneShowingChild(children = [], parent) {
const showingChildren = children.filter(item => { const showingChildren = children.filter(item => {
if (item.hidden) { if (item.hidden) {
return false 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 // When there is only one child router, the child router is displayed by default

View File

@ -26,6 +26,7 @@ const sessionCache = {
if (value != null) { if (value != null) {
return JSON.parse(value) return JSON.parse(value)
} }
return null
}, },
remove (key) { remove (key) {
sessionStorage.removeItem(key); sessionStorage.removeItem(key);
@ -59,6 +60,7 @@ const localCache = {
if (value != null) { if (value != null) {
return JSON.parse(value) return JSON.parse(value)
} }
return null
}, },
remove (key) { remove (key) {
localStorage.removeItem(key); localStorage.removeItem(key);

View File

@ -166,9 +166,8 @@ const router = createRouter({
scrollBehavior(to, from, savedPosition) { scrollBehavior(to, from, savedPosition) {
if (savedPosition) { if (savedPosition) {
return savedPosition return savedPosition
} else {
return { top: 0 }
} }
return { top: 0 }
}, },
}); });

View File

@ -443,8 +443,8 @@ function handleUpdate(row) {
}); });
}); });
}); });
title.value = "修改角色";
}); });
title.value = "修改角色";
} }
/** 根据角色ID查询菜单树结构 */ /** 根据角色ID查询菜单树结构 */
@ -558,8 +558,8 @@ function handleDataScope(row) {
}); });
}); });
}); });
title.value = "分配数据权限";
}); });
title.value = "分配数据权限";
} }
/** 提交按钮(数据权限) */ /** 提交按钮(数据权限) */