feat: auto activate subMenu on select root menu (#5147)
* feat: auto activate subMenu on click root menu * fix: prop name fixed * chore: test and docs update
This commit is contained in:
@@ -15,6 +15,9 @@ function useExtraMenu() {
|
||||
|
||||
const menus = computed(() => accessStore.accessMenus);
|
||||
|
||||
/** 记录当前顶级菜单下哪个子菜单最后激活 */
|
||||
const defaultSubMap = new Map<string, string>();
|
||||
|
||||
const route = useRoute();
|
||||
const extraMenus = ref<MenuRecordRaw[]>([]);
|
||||
const sidebarExtraVisible = ref<boolean>(false);
|
||||
@@ -32,6 +35,12 @@ function useExtraMenu() {
|
||||
sidebarExtraVisible.value = hasChildren;
|
||||
if (!hasChildren) {
|
||||
await navigation(menu.path);
|
||||
} else if (preferences.sidebar.autoActivateChild) {
|
||||
await navigation(
|
||||
defaultSubMap.has(menu.path)
|
||||
? (defaultSubMap.get(menu.path) as string)
|
||||
: menu.path,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -89,6 +98,7 @@ function useExtraMenu() {
|
||||
menus.value,
|
||||
currentPath,
|
||||
);
|
||||
if (rootMenuPath) defaultSubMap.set(rootMenuPath, currentPath);
|
||||
extraActiveMenu.value = rootMenuPath ?? findMenu?.path ?? '';
|
||||
extraMenus.value = rootMenu?.children ?? [];
|
||||
},
|
||||
|
Reference in New Issue
Block a user