feat(router): 支持通过 activeMenuName 指定菜单高亮路径
All checks were successful
CI/CD Pipeline / playwright (push) Successful in 2m18s
CI/CD Pipeline / build-and-deploy (push) Successful in 4m24s

This commit is contained in:
严浩
2025-11-03 15:54:11 +08:00
parent f9f82e4d29
commit 166d76d980
7 changed files with 47 additions and 5 deletions

View File

@@ -17,10 +17,17 @@ export function useMetaLayoutsNMenuOptions({ menuInstRef }: { menuInstRef: Ref<M
const selectedKey = ref('');
watch(
() => router.currentRoute.value.path,
(newPath) => {
selectedKey.value = newPath;
menuInstRef.value?.showOption(newPath); // 展开菜单,确保设定的元素被显示,如果不传入 key 会展示当前选中元素
() => router.currentRoute.value,
(route) => {
// 优先使用 activeMenuName通过路由名称解析为路径如果没有则使用当前路径
const activeMenuPath = route.meta.activeMenuName
? router.resolve({ name: route.meta.activeMenuName }).path
: route.path;
console.debug(`route.meta.activeMenuName :>> `, route.meta.activeMenuName);
selectedKey.value = activeMenuPath;
menuInstRef.value?.showOption(activeMenuPath); // 展开菜单,确保设定的元素被显示
},
{ immediate: true },
);