fix: 菜单响应式隐藏时宽度计算错误 (#1945)

Co-authored-by: zeozhou <zeozhou@tencent.com>
This commit is contained in:
You 2022-06-16 19:04:07 +08:00 committed by JinMao
parent 4723f61b88
commit 821efa09da
4 changed files with 18 additions and 7 deletions

View File

@ -101,8 +101,12 @@ export function useMenuSetting() {
});
const getMiniWidthNumber = computed(() => {
const { collapsedShowTitle } = appStore.getMenuSetting;
return collapsedShowTitle ? SIDE_BAR_SHOW_TIT_MINI_WIDTH : SIDE_BAR_MINI_WIDTH;
const { collapsedShowTitle, siderHidden } = appStore.getMenuSetting;
return siderHidden
? 0
: collapsedShowTitle
? SIDE_BAR_SHOW_TIT_MINI_WIDTH
: SIDE_BAR_MINI_WIDTH;
});
const getCalcContentWidth = computed(() => {

View File

@ -1,26 +1,30 @@
import type { Ref } from 'vue';
import { computed, unref, onMounted, nextTick, ref } from 'vue';
import { computed, unref, onMounted, nextTick } from 'vue';
import { TriggerEnum } from '/@/enums/menuEnum';
import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
import { useDebounceFn } from '@vueuse/core';
import { useAppStore } from '/@/store/modules/app';
/**
* Handle related operations of menu events
*/
export function useSiderEvent() {
const brokenRef = ref(false);
const appStore = useAppStore();
const { getMiniWidthNumber } = useMenuSetting();
const getCollapsedWidth = computed(() => {
return unref(brokenRef) ? 0 : unref(getMiniWidthNumber);
return unref(getMiniWidthNumber);
});
function onBreakpointChange(broken: boolean) {
brokenRef.value = broken;
appStore.setProjectConfig({
menuSetting: {
siderHidden: broken,
},
});
}
return { getCollapsedWidth, onBreakpointChange };

View File

@ -83,6 +83,8 @@ const setting: ProjectConfig = {
fixed: true,
// Menu collapse
collapsed: false,
// When sider hide because of the responsive layout
siderHidden: false,
// Whether to display the menu name when folding the menu
collapsedShowTitle: false,
// Whether it can be dragged

1
types/config.d.ts vendored
View File

@ -16,6 +16,7 @@ export interface MenuSetting {
bgColor: string;
fixed: boolean;
collapsed: boolean;
siderHidden: boolean;
canDrag: boolean;
show: boolean;
hidden: boolean;