fix: header-mixed layout side-menu active (#5265)
* fix: header-mixed layout side-menu active * fix: config test
This commit is contained in:
parent
ff8d5ca351
commit
2eb7fed9f4
@ -71,7 +71,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
|||||||
"collapsedShowTitle": false,
|
"collapsedShowTitle": false,
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"expandOnHover": true,
|
"expandOnHover": true,
|
||||||
"extraCollapse": true,
|
"extraCollapse": false,
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"width": 224,
|
"width": 224,
|
||||||
},
|
},
|
||||||
|
@ -71,7 +71,7 @@ const defaultPreferences: Preferences = {
|
|||||||
collapsedShowTitle: false,
|
collapsedShowTitle: false,
|
||||||
enable: true,
|
enable: true,
|
||||||
expandOnHover: true,
|
expandOnHover: true,
|
||||||
extraCollapse: true,
|
extraCollapse: false,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
width: 224,
|
width: 224,
|
||||||
},
|
},
|
||||||
|
@ -96,6 +96,17 @@ const showHeaderNav = computed(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
handleMenuSelect,
|
||||||
|
handleMenuOpen,
|
||||||
|
headerActive,
|
||||||
|
headerMenus,
|
||||||
|
sidebarActive,
|
||||||
|
sidebarMenus,
|
||||||
|
mixHeaderMenus,
|
||||||
|
sidebarVisible,
|
||||||
|
} = useMixedMenu();
|
||||||
|
|
||||||
// 侧边多列菜单
|
// 侧边多列菜单
|
||||||
const {
|
const {
|
||||||
extraActiveMenu,
|
extraActiveMenu,
|
||||||
@ -105,19 +116,7 @@ const {
|
|||||||
handleMixedMenuSelect,
|
handleMixedMenuSelect,
|
||||||
handleSideMouseLeave,
|
handleSideMouseLeave,
|
||||||
sidebarExtraVisible,
|
sidebarExtraVisible,
|
||||||
} = useExtraMenu();
|
} = useExtraMenu(mixHeaderMenus);
|
||||||
|
|
||||||
const {
|
|
||||||
handleMenuSelect,
|
|
||||||
handleMenuOpen,
|
|
||||||
headerActive,
|
|
||||||
headerMenus,
|
|
||||||
sidebarActive,
|
|
||||||
sidebarMenus,
|
|
||||||
mixedSidebarActive,
|
|
||||||
mixHeaderMenus,
|
|
||||||
sidebarVisible,
|
|
||||||
} = useMixedMenu();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 包装菜单,翻译菜单名称
|
* 包装菜单,翻译菜单名称
|
||||||
@ -275,7 +274,7 @@ const headerSlots = computed(() => {
|
|||||||
</template>
|
</template>
|
||||||
<template #mixed-menu>
|
<template #mixed-menu>
|
||||||
<LayoutMixedMenu
|
<LayoutMixedMenu
|
||||||
:active-path="isHeaderMixedNav ? mixedSidebarActive : extraActiveMenu"
|
:active-path="extraActiveMenu"
|
||||||
:menus="wrapperMenus(mixHeaderMenus, false)"
|
:menus="wrapperMenus(mixHeaderMenus, false)"
|
||||||
:rounded="isMenuRounded"
|
:rounded="isMenuRounded"
|
||||||
:theme="sidebarTheme"
|
:theme="sidebarTheme"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { MenuRecordRaw } from '@vben/types';
|
import type { MenuRecordRaw } from '@vben/types';
|
||||||
|
|
||||||
import { computed, nextTick, ref, watch } from 'vue';
|
import { computed, type ComputedRef, ref, watch } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
import { preferences } from '@vben/preferences';
|
import { preferences } from '@vben/preferences';
|
||||||
@ -9,11 +9,11 @@ import { findRootMenuByPath } from '@vben/utils';
|
|||||||
|
|
||||||
import { useNavigation } from './use-navigation';
|
import { useNavigation } from './use-navigation';
|
||||||
|
|
||||||
function useExtraMenu() {
|
function useExtraMenu(useRootMenus?: ComputedRef<MenuRecordRaw[]>) {
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
const { navigation } = useNavigation();
|
const { navigation } = useNavigation();
|
||||||
|
|
||||||
const menus = computed(() => accessStore.accessMenus);
|
const menus = computed(() => useRootMenus?.value ?? accessStore.accessMenus);
|
||||||
|
|
||||||
/** 记录当前顶级菜单下哪个子菜单最后激活 */
|
/** 记录当前顶级菜单下哪个子菜单最后激活 */
|
||||||
const defaultSubMap = new Map<string, string>();
|
const defaultSubMap = new Map<string, string>();
|
||||||
@ -22,6 +22,9 @@ function useExtraMenu() {
|
|||||||
const extraMenus = ref<MenuRecordRaw[]>([]);
|
const extraMenus = ref<MenuRecordRaw[]>([]);
|
||||||
const sidebarExtraVisible = ref<boolean>(false);
|
const sidebarExtraVisible = ref<boolean>(false);
|
||||||
const extraActiveMenu = ref('');
|
const extraActiveMenu = ref('');
|
||||||
|
const parentLevel = computed(() =>
|
||||||
|
preferences.app.layout === 'header-mixed-nav' ? 1 : 0,
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选择混合菜单事件
|
* 选择混合菜单事件
|
||||||
@ -29,7 +32,7 @@ function useExtraMenu() {
|
|||||||
*/
|
*/
|
||||||
const handleMixedMenuSelect = async (menu: MenuRecordRaw) => {
|
const handleMixedMenuSelect = async (menu: MenuRecordRaw) => {
|
||||||
extraMenus.value = menu?.children ?? [];
|
extraMenus.value = menu?.children ?? [];
|
||||||
extraActiveMenu.value = menu.parents?.[0] ?? menu.path;
|
extraActiveMenu.value = menu.parents?.[parentLevel.value] ?? menu.path;
|
||||||
const hasChildren = extraMenus.value.length > 0;
|
const hasChildren = extraMenus.value.length > 0;
|
||||||
|
|
||||||
sidebarExtraVisible.value = hasChildren;
|
sidebarExtraVisible.value = hasChildren;
|
||||||
@ -53,10 +56,8 @@ function useExtraMenu() {
|
|||||||
menu: MenuRecordRaw,
|
menu: MenuRecordRaw,
|
||||||
rootMenu?: MenuRecordRaw,
|
rootMenu?: MenuRecordRaw,
|
||||||
) => {
|
) => {
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
extraMenus.value = rootMenu?.children ?? extraRootMenus.value ?? [];
|
extraMenus.value = rootMenu?.children ?? extraRootMenus.value ?? [];
|
||||||
extraActiveMenu.value = menu.parents?.[0] ?? menu.path;
|
extraActiveMenu.value = menu.parents?.[parentLevel.value] ?? menu.path;
|
||||||
|
|
||||||
if (preferences.sidebar.expandOnHover) {
|
if (preferences.sidebar.expandOnHover) {
|
||||||
sidebarExtraVisible.value = extraMenus.value.length > 0;
|
sidebarExtraVisible.value = extraMenus.value.length > 0;
|
||||||
@ -67,23 +68,23 @@ function useExtraMenu() {
|
|||||||
* 侧边菜单鼠标移出事件
|
* 侧边菜单鼠标移出事件
|
||||||
*/
|
*/
|
||||||
const handleSideMouseLeave = () => {
|
const handleSideMouseLeave = () => {
|
||||||
// const { findMenu, rootMenu, rootMenuPath } = findRootMenuByPath(
|
|
||||||
// menus.value,
|
|
||||||
// route.path,
|
|
||||||
// );
|
|
||||||
calcExtraMenus(route.path);
|
|
||||||
if (preferences.sidebar.expandOnHover) {
|
if (preferences.sidebar.expandOnHover) {
|
||||||
sidebarExtraVisible.value = extraMenus.value.length > 0;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sidebarExtraVisible.value = false;
|
|
||||||
|
const { findMenu, rootMenu, rootMenuPath } = findRootMenuByPath(
|
||||||
|
menus.value,
|
||||||
|
route.path,
|
||||||
|
);
|
||||||
|
extraActiveMenu.value = rootMenuPath ?? findMenu?.path ?? '';
|
||||||
|
extraMenus.value = rootMenu?.children ?? [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMenuMouseEnter = (menu: MenuRecordRaw) => {
|
const handleMenuMouseEnter = (menu: MenuRecordRaw) => {
|
||||||
if (!preferences.sidebar.expandOnHover) {
|
if (!preferences.sidebar.expandOnHover) {
|
||||||
const { findMenu } = findRootMenuByPath(menus.value, menu.path);
|
const { findMenu } = findRootMenuByPath(menus.value, menu.path);
|
||||||
extraMenus.value = findMenu?.children ?? [];
|
extraMenus.value = findMenu?.children ?? [];
|
||||||
extraActiveMenu.value = menu.parents?.[0] ?? menu.path;
|
extraActiveMenu.value = menu.parents?.[parentLevel.value] ?? menu.path;
|
||||||
sidebarExtraVisible.value = extraMenus.value.length > 0;
|
sidebarExtraVisible.value = extraMenus.value.length > 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -93,22 +94,12 @@ function useExtraMenu() {
|
|||||||
const { findMenu, rootMenu, rootMenuPath } = findRootMenuByPath(
|
const { findMenu, rootMenu, rootMenuPath } = findRootMenuByPath(
|
||||||
menus.value,
|
menus.value,
|
||||||
currentPath,
|
currentPath,
|
||||||
|
parentLevel.value,
|
||||||
);
|
);
|
||||||
if (preferences.app.layout === 'header-mixed-nav') {
|
|
||||||
const subExtra = findRootMenuByPath(
|
|
||||||
rootMenu?.children ?? [],
|
|
||||||
currentPath,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
extraRootMenus.value = subExtra.rootMenu?.children ?? [];
|
|
||||||
extraActiveMenu.value = subExtra.rootMenuPath ?? '';
|
|
||||||
extraMenus.value = subExtra.rootMenu?.children ?? [];
|
|
||||||
} else {
|
|
||||||
extraRootMenus.value = rootMenu?.children ?? [];
|
extraRootMenus.value = rootMenu?.children ?? [];
|
||||||
if (rootMenuPath) defaultSubMap.set(rootMenuPath, currentPath);
|
if (rootMenuPath) defaultSubMap.set(rootMenuPath, currentPath);
|
||||||
extraActiveMenu.value = rootMenuPath ?? findMenu?.path ?? '';
|
extraActiveMenu.value = rootMenuPath ?? findMenu?.path ?? '';
|
||||||
extraMenus.value = rootMenu?.children ?? [];
|
extraMenus.value = rootMenu?.children ?? [];
|
||||||
}
|
|
||||||
if (preferences.sidebar.expandOnHover) {
|
if (preferences.sidebar.expandOnHover) {
|
||||||
sidebarExtraVisible.value = extraMenus.value.length > 0;
|
sidebarExtraVisible.value = extraMenus.value.length > 0;
|
||||||
}
|
}
|
||||||
|
@ -69,10 +69,6 @@ function useMixedMenu() {
|
|||||||
return (route?.meta?.activePath as string) ?? route.path;
|
return (route?.meta?.activePath as string) ?? route.path;
|
||||||
});
|
});
|
||||||
|
|
||||||
const mixedSidebarActive = computed(() => {
|
|
||||||
return mixedRootMenuPath.value || sidebarActive.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 头部菜单激活路径
|
* 头部菜单激活路径
|
||||||
*/
|
*/
|
||||||
@ -160,7 +156,6 @@ function useMixedMenu() {
|
|||||||
headerMenus,
|
headerMenus,
|
||||||
sidebarActive,
|
sidebarActive,
|
||||||
sidebarMenus,
|
sidebarMenus,
|
||||||
mixedSidebarActive,
|
|
||||||
mixHeaderMenus,
|
mixHeaderMenus,
|
||||||
mixExtraMenus,
|
mixExtraMenus,
|
||||||
sidebarVisible,
|
sidebarVisible,
|
||||||
|
Loading…
Reference in New Issue
Block a user