u
This commit is contained in:
1 parent
5f28a10d89
commit
32d423b759
59 files changed
+5101
-1098
No files matched your search
@@ -46,14 +46,15 @@ const router = createRouter({
|
||||
scrollBehavior: () => ({ top: 0 }),
|
||||
})
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
router.beforeEach((to) => {
|
||||
NProgress.start()
|
||||
|
||||
const title = to.meta.title as string | undefined
|
||||
document.title = title ? `${title} - ${APP_TITLE}` : APP_TITLE
|
||||
|
||||
// 登录校验待用户模块落地后接入;当前直接放行。
|
||||
next()
|
||||
// vue-router 5 已弃用 next 回调,改用返回值:放行 return true,拦截 return false。
|
||||
return true
|
||||
})
|
||||
|
||||
router.afterEach(() => {
|
||||
@@ -83,19 +84,30 @@ export function findMenuItemByPath(path: string): MenuItem | undefined {
|
||||
* 由当前路径反查它的所有祖先分组 key(从顶级到最近一级)。
|
||||
* 支持多级嵌套与详情页:/ocean/booking/123 会命中「海运」「订舱业务」。
|
||||
* 返回数组保证侧栏能逐层展开所有祖先分组。
|
||||
*
|
||||
* ⚠️ 这里的「命中」必须是【叶子】命中,不能是「分组 path 前缀命中」——
|
||||
* 否则 /ocean/booking 会因 startsWith('/ocean/') 在「海运」这一层就提前返回,
|
||||
* 丢掉真正的祖先链 [ocean, ocean-booking-group],导致刷新后不展开。
|
||||
*/
|
||||
export function findParentKeysByPath(path: string): string[] {
|
||||
const walk = (items: MenuItem[], parents: string[]): string[] | null => {
|
||||
for (const item of items) {
|
||||
// 命中叶子(无 children)或其自身 path:记录所有祖先
|
||||
if (item.path === path || path.startsWith(`${item.path}/`)) {
|
||||
// 叶子(无 children)且精确命中 / 前缀命中(详情页):返回累计的祖先
|
||||
if (!item.children?.length) {
|
||||
if (item.path === path || path.startsWith(`${item.path}/`)) {
|
||||
return parents
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// 分组:自身 path 精确命中(父级 path 与叶子相同的情况,如 /ocean/booking)
|
||||
if (item.path === path) {
|
||||
return parents
|
||||
}
|
||||
// 有子级:分组,继续下钻
|
||||
if (item.children?.length) {
|
||||
const found = walk(item.children, [...parents, item.key])
|
||||
if (found) return found
|
||||
}
|
||||
|
||||
// 继续下钻,把当前分组 key 计入祖先链
|
||||
const found = walk(item.children, [...parents, item.key])
|
||||
if (found) return found
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user