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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,9 @@
import type { RouteRecordNormalized } from 'vue-router'; import type { RouteRecordNormalized } from 'vue-router';
import { isHttpUrl, openRouteInNewWindow, openWindow } from '@vben/utils';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { isHttpUrl, openRouteInNewWindow, openWindow } from '@vben/utils';
function useNavigation() { function useNavigation() {
const router = useRouter(); const router = useRouter();
const routes = router.getRoutes(); 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 }; export { useNavigation };