Skip to content

Commit 384c5d7

Browse files
wyc001122王泳超
and
王泳超
authored
fix: 布局为双列菜单或者水平模式下, 一级菜单高亮问题 (vbenjs#5870)
Co-authored-by: 王泳超 <[email protected]>
1 parent b0ad08d commit 384c5d7

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

packages/@core/ui-kit/menu-ui/src/components/menu.vue

-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
2424
import { useNamespace } from '@vben-core/composables';
2525
import { Ellipsis } from '@vben-core/icons';
26-
import { isHttpUrl } from '@vben-core/shared/utils';
2726
2827
import { useResizeObserver } from '@vueuse/core';
2928
@@ -248,9 +247,6 @@ function handleMenuItemClick(data: MenuItemClicked) {
248247
if (!path || !parentPaths) {
249248
return;
250249
}
251-
if (!isHttpUrl(path)) {
252-
activePath.value = path;
253-
}
254250
255251
emit('select', path, parentPaths);
256252
}

packages/effects/layouts/src/basic/menu/use-extra-menu.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useNavigation } from './use-navigation';
1313

1414
function useExtraMenu(useRootMenus?: ComputedRef<MenuRecordRaw[]>) {
1515
const accessStore = useAccessStore();
16-
const { navigation } = useNavigation();
16+
const { navigation, willOpenedByWindow } = useNavigation();
1717

1818
const menus = computed(() => useRootMenus?.value ?? accessStore.accessMenus);
1919

@@ -33,11 +33,15 @@ function useExtraMenu(useRootMenus?: ComputedRef<MenuRecordRaw[]>) {
3333
* @param menu
3434
*/
3535
const handleMixedMenuSelect = async (menu: MenuRecordRaw) => {
36-
extraMenus.value = menu?.children ?? [];
37-
extraActiveMenu.value = menu.parents?.[parentLevel.value] ?? menu.path;
38-
const hasChildren = extraMenus.value.length > 0;
36+
const _extraMenus = menu?.children ?? [];
37+
const hasChildren = _extraMenus.length > 0;
38+
39+
if (!willOpenedByWindow(menu.path)) {
40+
extraMenus.value = _extraMenus ?? [];
41+
extraActiveMenu.value = menu.parents?.[parentLevel.value] ?? menu.path;
42+
sidebarExtraVisible.value = hasChildren;
43+
}
3944

40-
sidebarExtraVisible.value = hasChildren;
4145
if (!hasChildren) {
4246
await navigation(menu.path);
4347
} else if (preferences.sidebar.autoActivateChild) {

packages/effects/layouts/src/basic/menu/use-mixed-menu.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { findRootMenuByPath } from '@vben/utils';
1010
import { useNavigation } from './use-navigation';
1111

1212
function useMixedMenu() {
13-
const { navigation } = useNavigation();
13+
const { navigation, willOpenedByWindow } = useNavigation();
1414
const accessStore = useAccessStore();
1515
const route = useRoute();
1616
const splitSideMenus = ref<MenuRecordRaw[]>([]);
@@ -89,11 +89,15 @@ function useMixedMenu() {
8989
navigation(key);
9090
return;
9191
}
92-
9392
const rootMenu = menus.value.find((item) => item.path === key);
94-
rootMenuPath.value = rootMenu?.path ?? '';
95-
splitSideMenus.value = rootMenu?.children ?? [];
96-
if (splitSideMenus.value.length === 0) {
93+
const _splitSideMenus = rootMenu?.children ?? [];
94+
95+
if (!willOpenedByWindow(key)) {
96+
rootMenuPath.value = rootMenu?.path ?? '';
97+
splitSideMenus.value = _splitSideMenus;
98+
}
99+
100+
if (_splitSideMenus.length === 0) {
97101
navigation(key);
98102
} else if (rootMenu && preferences.sidebar.autoActivateChild) {
99103
navigation(

packages/effects/layouts/src/basic/menu/use-navigation.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ function useNavigation() {
2929
}
3030
};
3131

32-
return { navigation };
32+
const willOpenedByWindow = (path: string) => {
33+
const route = routeMetaMap.get(path);
34+
const { openInNewWindow = false } = route?.meta ?? {};
35+
if (isHttpUrl(path)) {
36+
return true;
37+
} else if (openInNewWindow) {
38+
return true;
39+
} else {
40+
return false;
41+
}
42+
};
43+
44+
return { navigation, willOpenedByWindow };
3345
}
3446

3547
export { useNavigation };

0 commit comments

Comments
 (0)