Skip to content

Commit

Permalink
feat(menu): add mixSideTrigger setting
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 1, 2021
1 parent 799a694 commit 0419a07
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Wip

### ✨ Features

- 新增`mixSideTrigger`配置。用于配置左侧混合模式菜单打开方式。可选`hover`,默认`click`

## 2.0.0-rc.15 (2020-12-31)

### ✨ 表格破坏性更新
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/setting/useMenuSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const getSplit = computed(() => unref(getMenuSetting).split);

const getMenuBgColor = computed(() => unref(getMenuSetting).bgColor);

const getMixSideTrigger = computed(() => unref(getMenuSetting).mixSideTrigger);

const getCanDrag = computed(() => unref(getMenuSetting).canDrag);

const getAccordion = computed(() => unref(getMenuSetting).accordion);
Expand Down Expand Up @@ -145,5 +147,6 @@ export function useMenuSetting() {
getIsMixMode,
getIsMixSidebar,
getCloseMixSidebarOnChange,
getMixSideTrigger,
};
}
33 changes: 30 additions & 3 deletions src/layouts/default/sider/MixSider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
open: openMenu,
},
]"
v-bind="getMenuEvents"
>
<AppLogo :showTitle="false" :class="`${prefixCls}-logo`" />
<ScrollContainer>
Expand All @@ -23,7 +24,7 @@
]"
v-for="item in menuModules"
:key="item.path"
@click="hanldeModuleClick(item.path)"
v-bind="getItemEvents(item)"
>
<MenuTag :item="item" :showTitle="false" :isHorizontal="false" />
<g-icon
Expand Down Expand Up @@ -112,6 +113,7 @@
getCanDrag,
getCloseMixSidebarOnChange,
getMenuTheme,
getMixSideTrigger,
} = useMenuSetting();
const { title } = useGlobSetting();
Expand All @@ -125,6 +127,16 @@
}
);
const getMenuEvents = computed(() => {
return unref(getMixSideTrigger) === 'hover'
? {
onMouseleave: () => {
openMenu.value = false;
},
}
: {};
});
const getShowDragBar = computed(() => unref(getCanDrag));
onMounted(async () => {
Expand All @@ -139,11 +151,13 @@
}
});
async function hanldeModuleClick(path: string) {
async function hanldeModuleClick(path: string, hover = false) {
const children = await getChildrenMenus(path);
if (unref(activePath) === path) {
openMenu.value = !unref(openMenu);
if (!hover) {
openMenu.value = !unref(openMenu);
}
if (!unref(openMenu)) {
setActive();
}
Expand Down Expand Up @@ -178,6 +192,17 @@
setActive();
}
function getItemEvents(item: Menu) {
if (unref(getMixSideTrigger) === 'hover') {
return {
onMouseenter: () => hanldeModuleClick(item.path, true),
};
}
return {
onClick: () => hanldeModuleClick(item.path),
};
}
return {
t,
prefixCls,
Expand All @@ -194,6 +219,8 @@
title,
openMenu,
getMenuTheme,
getItemEvents,
getMenuEvents,
};
},
});
Expand Down
2 changes: 2 additions & 0 deletions src/settings/projectSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const setting: ProjectConfig = {
accordion: true,
// Switch page to close menu
closeMixSidebarOnChange: false,
// Module opening method ‘click’ |'hover'
mixSideTrigger: 'hover',
},

// Multi-label
Expand Down
1 change: 1 addition & 0 deletions src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface MenuSetting {
accordion: boolean;
closeMixSidebarOnChange: boolean;
collapsedShowTitle: boolean;
mixSideTrigger: 'click' | 'hover';
}

export interface MultiTabsSetting {
Expand Down

0 comments on commit 0419a07

Please sign in to comment.