Skip to content

Commit

Permalink
修复文件系统路由模式下主导航高亮效果不更新
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Nov 7, 2024
1 parent 30bf80a commit 553caa5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/store/modules/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,24 @@ const useMenuStore = defineStore(
}).catch(() => {})
}
// 设置主导航
function isPathInMenus(menus: Menu.recordRaw[], path: string) {
let flag = false
flag = menus.some((item) => {
if (item.children) {
return isPathInMenus(item.children, path)
}
return path.indexOf(`${item.path}/`) === 0 || path === item.path
})
return flag
}
function setActived(data: number | string) {
if (typeof data === 'number') {
// 如果是 number 类型,则认为是主导航的索引
actived.value = data
}
else {
// 如果是 string 类型,则认为是路由,需要查找对应的主导航索引
const findIndex = allMenus.value.findIndex(item => item.children.some(r => data.indexOf(`${r.path}/`) === 0 || data === r.path))
const findIndex = allMenus.value.findIndex(item => isPathInMenus(item.children, data))
if (findIndex >= 0) {
actived.value = findIndex
}
Expand Down

0 comments on commit 553caa5

Please sign in to comment.