mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-06 16:03:23 +08:00
修复文件系统路由模式下主导航高亮效果不更新
This commit is contained in:
@@ -188,6 +188,16 @@ 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 类型,则认为是主导航的索引
|
||||
@@ -195,7 +205,7 @@ const useMenuStore = defineStore(
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user