Skip to content

Commit d40c42a

Browse files
committed
fix: 修复文件系统路由模式下主导航高亮效果不更新
1 parent 91c7350 commit d40c42a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/store/modules/menu.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,24 @@ const useMenuStore = defineStore(
188188
}).catch(() => {})
189189
}
190190
// 设置主导航
191+
function isPathInMenus(menus: Menu.recordRaw[], path: string) {
192+
let flag = false
193+
flag = menus.some((item) => {
194+
if (item.children) {
195+
return isPathInMenus(item.children, path)
196+
}
197+
return path.indexOf(`${item.path}/`) === 0 || path === item.path
198+
})
199+
return flag
200+
}
191201
function setActived(data: number | string) {
192202
if (typeof data === 'number') {
193203
// 如果是 number 类型,则认为是主导航的索引
194204
actived.value = data
195205
}
196206
else {
197207
// 如果是 string 类型,则认为是路由,需要查找对应的主导航索引
198-
const findIndex = allMenus.value.findIndex(item => item.children.some(r => data.indexOf(`${r.path}/`) === 0 || data === r.path))
208+
const findIndex = allMenus.value.findIndex(item => isPathInMenus(item.children, data))
199209
if (findIndex >= 0) {
200210
actived.value = findIndex
201211
}

0 commit comments

Comments
 (0)