Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: autoActivateChild support more layout mode #5148

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/effects/layouts/src/basic/layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const {

const {
handleMenuSelect,
handleMenuOpen,
headerActive,
headerMenus,
sidebarActive,
Expand Down Expand Up @@ -260,6 +261,7 @@ const headerSlots = computed(() => {
:rounded="isMenuRounded"
:theme="sidebarTheme"
mode="vertical"
@open="handleMenuOpen"
@select="handleMenuSelect"
/>
</template>
Expand Down
6 changes: 6 additions & 0 deletions packages/effects/layouts/src/basic/menu/menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ const props = withDefaults(defineProps<Props>(), {
});

const emit = defineEmits<{
open: [string, string[]];
select: [string, string?];
}>();

function handleMenuSelect(key: string) {
emit('select', key, props.mode);
}

function handleMenuOpen(key: string, path: string[]) {
emit('open', key, path);
}
</script>

<template>
Expand All @@ -32,6 +37,7 @@ function handleMenuSelect(key: string) {
:mode="mode"
:rounded="rounded"
:theme="theme"
@open="handleMenuOpen"
@select="handleMenuSelect"
/>
</template>
25 changes: 24 additions & 1 deletion packages/effects/layouts/src/basic/menu/use-mixed-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function useMixedMenu() {
const route = useRoute();
const splitSideMenus = ref<MenuRecordRaw[]>([]);
const rootMenuPath = ref<string>('');

/** 记录当前顶级菜单下哪个子菜单最后激活 */
const defaultSubMap = new Map<string, string>();
const { isMixedNav } = usePreferences();

const needSplit = computed(
Expand Down Expand Up @@ -86,6 +87,25 @@ function useMixedMenu() {
splitSideMenus.value = rootMenu?.children ?? [];
if (splitSideMenus.value.length === 0) {
navigation(key);
} else if (rootMenu && preferences.sidebar.autoActivateChild) {
navigation(
defaultSubMap.has(rootMenu.path)
? (defaultSubMap.get(rootMenu.path) as string)
: rootMenu.path,
);
}
};

/**
* 侧边菜单展开事件
* @param key 路由路径
* @param parentsPath 父级路径
*/
const handleMenuOpen = (key: string, parentsPath: string[]) => {
if (parentsPath.length <= 1 && preferences.sidebar.autoActivateChild) {
navigation(
defaultSubMap.has(key) ? (defaultSubMap.get(key) as string) : key,
);
}
};

Expand All @@ -107,6 +127,8 @@ function useMixedMenu() {
(path) => {
const currentPath = (route?.meta?.activePath as string) ?? path;
calcSideMenus(currentPath);
if (rootMenuPath.value)
defaultSubMap.set(rootMenuPath.value, currentPath);
},
{ immediate: true },
);
Expand All @@ -118,6 +140,7 @@ function useMixedMenu() {

return {
handleMenuSelect,
handleMenuOpen,
headerActive,
headerMenus,
sidebarActive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ const sidebarExpandOnHover = defineModel<boolean>('sidebarExpandOnHover');
<SwitchItem
v-model="sidebarAutoActivateChild"
:disabled="
!sidebarEnable || currentLayout !== 'sidebar-mixed-nav' || disabled
!sidebarEnable ||
!['sidebar-mixed-nav', 'mixed-nav', 'sidebar-nav'].includes(
currentLayout as string,
) ||
disabled
"
:tip="$t('preferences.sidebar.autoActivateChildTip')"
>
Expand Down
Loading