This commit is contained in:
dap 2025-04-05 14:29:10 +08:00
commit eae24d8d83
6 changed files with 55 additions and 27 deletions

View File

@ -23,7 +23,6 @@ import {
import { useNamespace } from '@vben-core/composables';
import { Ellipsis } from '@vben-core/icons';
import { isHttpUrl } from '@vben-core/shared/utils';
import { useResizeObserver } from '@vueuse/core';
@ -248,9 +247,6 @@ function handleMenuItemClick(data: MenuItemClicked) {
if (!path || !parentPaths) {
return;
}
if (!isHttpUrl(path)) {
activePath.value = path;
}
emit('select', path, parentPaths);
}

View File

@ -55,12 +55,13 @@ withDefaults(defineProps<Props>(), {
:size="logoSize"
class="relative rounded-none bg-transparent"
/>
<span
v-if="!collapsed"
class="text-foreground truncate text-nowrap font-semibold"
>
{{ text }}
</span>
<template v-if="!collapsed">
<slot name="text">
<span class="text-foreground truncate text-nowrap font-semibold">
{{ text }}
</span>
</slot>
</template>
</a>
</div>
</template>

View File

@ -228,7 +228,11 @@ const headerSlots = computed(() => {
:text="preferences.app.name"
:theme="showHeaderNav ? headerTheme : theme"
@click="clickLogo"
/>
>
<template v-if="$slots['logo-text']" #text>
<slot name="logo-text"></slot>
</template>
</VbenLogo>
</template>
<!-- 头部区域 -->
<template #header>
@ -310,7 +314,11 @@ const headerSlots = computed(() => {
v-if="preferences.logo.enable"
:text="preferences.app.name"
:theme="theme"
/>
>
<template v-if="$slots['logo-text']" #text>
<slot name="logo-text"></slot>
</template>
</VbenLogo>
</template>
<template #tabbar>

View File

@ -1,17 +1,19 @@
import type { MenuRecordRaw } from '@vben/types';
import type { ComputedRef } from 'vue';
import type { MenuRecordRaw } from '@vben/types';
import { computed, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { preferences } from '@vben/preferences';
import { useAccessStore } from '@vben/stores';
import { findRootMenuByPath } from '@vben/utils';
import { computed, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useNavigation } from './use-navigation';
function useExtraMenu(useRootMenus?: ComputedRef<MenuRecordRaw[]>) {
const accessStore = useAccessStore();
const { navigation } = useNavigation();
const { navigation, willOpenedByWindow } = useNavigation();
const menus = computed(() => useRootMenus?.value ?? accessStore.accessMenus);
@ -31,11 +33,15 @@ function useExtraMenu(useRootMenus?: ComputedRef<MenuRecordRaw[]>) {
* @param menu
*/
const handleMixedMenuSelect = async (menu: MenuRecordRaw) => {
extraMenus.value = menu?.children ?? [];
extraActiveMenu.value = menu.parents?.[parentLevel.value] ?? menu.path;
const hasChildren = extraMenus.value.length > 0;
const _extraMenus = menu?.children ?? [];
const hasChildren = _extraMenus.length > 0;
if (!willOpenedByWindow(menu.path)) {
extraMenus.value = _extraMenus ?? [];
extraActiveMenu.value = menu.parents?.[parentLevel.value] ?? menu.path;
sidebarExtraVisible.value = hasChildren;
}
sidebarExtraVisible.value = hasChildren;
if (!hasChildren) {
await navigation(menu.path);
} else if (preferences.sidebar.autoActivateChild) {

View File

@ -10,7 +10,7 @@ import { findRootMenuByPath } from '@vben/utils';
import { useNavigation } from './use-navigation';
function useMixedMenu() {
const { navigation } = useNavigation();
const { navigation, willOpenedByWindow } = useNavigation();
const accessStore = useAccessStore();
const route = useRoute();
const splitSideMenus = ref<MenuRecordRaw[]>([]);
@ -89,11 +89,15 @@ function useMixedMenu() {
navigation(key);
return;
}
const rootMenu = menus.value.find((item) => item.path === key);
rootMenuPath.value = rootMenu?.path ?? '';
splitSideMenus.value = rootMenu?.children ?? [];
if (splitSideMenus.value.length === 0) {
const _splitSideMenus = rootMenu?.children ?? [];
if (!willOpenedByWindow(key)) {
rootMenuPath.value = rootMenu?.path ?? '';
splitSideMenus.value = _splitSideMenus;
}
if (_splitSideMenus.length === 0) {
navigation(key);
} else if (rootMenu && preferences.sidebar.autoActivateChild) {
navigation(

View File

@ -1,8 +1,9 @@
import type { RouteRecordNormalized } from 'vue-router';
import { isHttpUrl, openRouteInNewWindow, openWindow } from '@vben/utils';
import { useRouter } from 'vue-router';
import { isHttpUrl, openRouteInNewWindow, openWindow } from '@vben/utils';
function useNavigation() {
const router = useRouter();
const routes = router.getRoutes();
@ -28,7 +29,19 @@ function useNavigation() {
}
};
return { navigation };
const willOpenedByWindow = (path: string) => {
const route = routeMetaMap.get(path);
const { openInNewWindow = false } = route?.meta ?? {};
if (isHttpUrl(path)) {
return true;
} else if (openInNewWindow) {
return true;
} else {
return false;
}
};
return { navigation, willOpenedByWindow };
}
export { useNavigation };