fix: fix the top menu adaptive failure

This commit is contained in:
vben
2020-10-19 22:56:10 +08:00
parent 5737e478f6
commit 2f12556d26
7 changed files with 72 additions and 24 deletions

View File

@@ -45,7 +45,8 @@ export default defineComponent({
menuState,
toRef(props, 'items'),
toRef(props, 'flatItems'),
toRef(props, 'isAppMenu')
toRef(props, 'isAppMenu'),
toRef(props, 'mode')
);
const getOpenKeys = computed(() => {

View File

@@ -1,3 +1,4 @@
import { MenuModeEnum } from '/@/enums/menuEnum';
import type { Menu as MenuType } from '/@/router/types';
import type { MenuState } from './types';
import type { Ref } from 'vue';
@@ -10,7 +11,8 @@ export function useOpenKeys(
menuState: MenuState,
menus: Ref<MenuType[]>,
flatMenusRef: Ref<MenuType[]>,
isAppMenu: Ref<boolean>
isAppMenu: Ref<boolean>,
mode: Ref<MenuModeEnum>
) {
/**
* @description:设置展开
@@ -28,21 +30,25 @@ export function useOpenKeys(
}
function handleOpenChange(openKeys: string[]) {
const rootSubMenuKeys: string[] = [];
for (const { children, path } of unref(menus)) {
if (children && children.length > 0) {
rootSubMenuKeys.push(path);
}
}
if (!menuStore.getCollapsedState || !unref(isAppMenu)) {
const latestOpenKey = openKeys.find((key) => menuState.openKeys.indexOf(key) === -1);
if (rootSubMenuKeys.indexOf(latestOpenKey as string) === -1) {
menuState.openKeys = openKeys;
} else {
menuState.openKeys = latestOpenKey ? [latestOpenKey] : [];
}
if (unref(mode) === MenuModeEnum.HORIZONTAL) {
menuState.openKeys = openKeys;
} else {
menuState.collapsedOpenKeys = openKeys;
const rootSubMenuKeys: string[] = [];
for (const { children, path } of unref(menus)) {
if (children && children.length > 0) {
rootSubMenuKeys.push(path);
}
}
if (!menuStore.getCollapsedState || !unref(isAppMenu)) {
const latestOpenKey = openKeys.find((key) => menuState.openKeys.indexOf(key) === -1);
if (rootSubMenuKeys.indexOf(latestOpenKey as string) === -1) {
menuState.openKeys = openKeys;
} else {
menuState.openKeys = latestOpenKey ? [latestOpenKey] : [];
}
} else {
menuState.collapsedOpenKeys = openKeys;
}
}
}
return { setOpenKeys, resetKeys, handleOpenChange };

View File

@@ -217,7 +217,11 @@ export default defineComponent({
const uuid = buildUUID();
emit('register', modalMethods, uuid);
return () => (
<Modal onCancel={handleCancel} {...{ ...attrs, ...props, ...unref(getProps) }}>
<Modal
onCancel={handleCancel}
{...{ ...attrs, ...props, ...unref(getProps) }}
getContainer={() => document.querySelector('.default-layout__main')}
>
{{
...extendSlots(slots, ['default']),
default: () => renderContent(),