Commit c31d21be by vben

feat(other): The menu supports jumping to external links and fixing some known problems

1 parent 399334ac
Showing 43 changed files with 332 additions and 91 deletions
...@@ -26,17 +26,18 @@ ...@@ -26,17 +26,18 @@
"dependencies": { "dependencies": {
"@vben-core/design": "workspace:*", "@vben-core/design": "workspace:*",
"@vben-core/design-tokens": "workspace:*", "@vben-core/design-tokens": "workspace:*",
"@vben-core/toolkit": "workspace:*",
"@vben-core/typings": "workspace:*", "@vben-core/typings": "workspace:*",
"@vben/common-ui": "workspace:*", "@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*", "@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*", "@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*", "@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*", "@vben/locales": "workspace:*",
"@vben/preference": "workspace:*", "@vben/preference": "workspace:*",
"@vben/stores": "workspace:*", "@vben/stores": "workspace:*",
"@vben/utils": "workspace:*",
"ant-design-vue": "^4.2.1", "ant-design-vue": "^4.2.1",
"axios": "^1.6.8", "axios": "^1.7.1",
"dayjs": "^1.11.11", "dayjs": "^1.11.11",
"vue": "^3.4.27", "vue": "^3.4.27",
"vue-router": "^4.3.2" "vue-router": "^4.3.2"
......
<script lang="ts" setup> <script lang="ts" setup>
import type { NotificationItem } from '@vben/common-ui'; import type { NotificationItem } from '@vben/common-ui';
import { openWindow } from '@vben-core/toolkit';
import { Notification, UserDropdown } from '@vben/common-ui'; import { Notification, UserDropdown } from '@vben/common-ui';
import { import {
IcRoundCreditScore, IcRoundCreditScore,
...@@ -14,6 +12,7 @@ import { BasicLayout } from '@vben/layouts'; ...@@ -14,6 +12,7 @@ import { BasicLayout } from '@vben/layouts';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { preference } from '@vben/preference'; import { preference } from '@vben/preference';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { openWindow } from '@vben/utils';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
......
import type { ExRouteRecordRaw, MenuRecordRaw } from '@vben-core/typings'; import type { ExRouteRecordRaw, MenuRecordRaw } from '@vben-core/typings';
import { filterTree, mapTree, traverseTreeValues } from '@vben-core/toolkit';
import type { RouteRecordRaw, Router } from 'vue-router'; import type { RouteRecordRaw, Router } from 'vue-router';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { filterTree, mapTree, traverseTreeValues } from '@vben/utils';
import { dynamicRoutes } from '../routes'; import { dynamicRoutes } from '../routes';
...@@ -120,6 +120,7 @@ async function generatorMenus( ...@@ -120,6 +120,7 @@ async function generatorMenus(
hideChildrenInMenu = false, hideChildrenInMenu = false,
icon, icon,
orderNo, orderNo,
target,
title = '', title = '',
} = meta || {}; } = meta || {};
...@@ -138,7 +139,7 @@ async function generatorMenus( ...@@ -138,7 +139,7 @@ async function generatorMenus(
}); });
} }
// 隐藏子菜单 // 隐藏子菜单
const resultPath = hideChildrenInMenu ? redirect : path; const resultPath = hideChildrenInMenu ? redirect : target || path;
return { return {
badge, badge,
badgeType, badgeType,
......
import { startProgress, stopProgress } from '@vben-core/toolkit';
import type { Router } from 'vue-router'; import type { Router } from 'vue-router';
import { preference } from '@vben/preference'; import { preference } from '@vben/preference';
import { startProgress, stopProgress } from '@vben/utils';
import { configAccessGuard } from './access'; import { configAccessGuard } from './access';
......
import { traverseTreeValues } from '@vben-core/toolkit';
import type { RouteRecordName, RouteRecordRaw } from 'vue-router'; import type { RouteRecordName, RouteRecordRaw } from 'vue-router';
import { traverseTreeValues } from '@vben/utils';
import { createRouter, createWebHashHistory } from 'vue-router'; import { createRouter, createWebHashHistory } from 'vue-router';
import { createRouteGuard } from './guard'; import { createRouteGuard } from './guard';
......
...@@ -4,6 +4,7 @@ import { builtinRoutes } from './builtin'; ...@@ -4,6 +4,7 @@ import { builtinRoutes } from './builtin';
import { Layout } from './layout'; import { Layout } from './layout';
import { nestedRoutes } from './modules/nested'; import { nestedRoutes } from './modules/nested';
import { outsideRoutes } from './modules/outside'; import { outsideRoutes } from './modules/outside';
import { vbenRoutes } from './modules/vben';
/** 动态路由 */ /** 动态路由 */
const dynamicRoutes: RouteRecordRaw[] = [ const dynamicRoutes: RouteRecordRaw[] = [
...@@ -31,30 +32,7 @@ const dynamicRoutes: RouteRecordRaw[] = [ ...@@ -31,30 +32,7 @@ const dynamicRoutes: RouteRecordRaw[] = [
}, },
...nestedRoutes, ...nestedRoutes,
...outsideRoutes, ...outsideRoutes,
// 关于 ...vbenRoutes,
{
component: Layout,
meta: {
hideChildrenInMenu: true,
icon: 'https://cdn.jsdelivr.net/gh/vbenjs/vben-cdn-static@0.1.2/vben-admin/admin-logo.png',
keepAlive: false,
title: '关于',
},
name: 'AboutLayout',
path: '/about',
redirect: '/about/index',
children: [
{
name: 'About',
path: 'index',
component: () => import('@/views/about/index.vue'),
meta: {
keepAlive: false,
title: '关于',
},
},
],
},
]; ];
/** 排除在主框架外的路由,这些路由没有菜单和顶部及其他框架内容 */ /** 排除在主框架外的路由,这些路由没有菜单和顶部及其他框架内容 */
......
import type { RouteRecordRaw } from 'vue-router';
import { VBEN_GITHUB_URL } from '@vben/constants';
import { $t } from '@vben/locales/helper';
import { preference } from '@vben/preference';
import { IFrameView, Layout } from '@/router/routes/layout';
export const vbenRoutes: RouteRecordRaw[] = [
{
component: Layout,
meta: {
icon: preference.logo,
title: 'Vben Admin',
},
name: 'AboutLayout',
path: '/vben-admin',
redirect: '/vben-admin/about',
children: [
{
name: 'About',
path: 'about',
component: () => import('@/views/about/index.vue'),
meta: {
icon: 'mdi:creative-commons',
title: $t('page.about'),
},
},
{
name: 'AboutDocument',
path: 'document',
component: () => import('@/views/about/index.vue'),
meta: {
icon: 'mdi:flame-circle',
title: $t('page.document'),
},
},
{
name: 'Github',
path: 'github',
component: IFrameView,
meta: {
icon: 'mdi:github',
target: VBEN_GITHUB_URL,
title: 'Github',
},
},
],
},
];
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.3.0", "@eslint/js": "^9.3.0",
"@types/eslint": "^8.56.10", "@types/eslint": "^8.56.10",
"@typescript-eslint/eslint-plugin": "^7.9.0", "@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.9.0", "@typescript-eslint/parser": "^7.10.0",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-comments": "^3.2.0",
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
"eslint-plugin-unused-imports": "^3.2.0", "eslint-plugin-unused-imports": "^3.2.0",
"eslint-plugin-vitest": "^0.5.4", "eslint-plugin-vitest": "^0.5.4",
"eslint-plugin-vue": "^9.26.0", "eslint-plugin-vue": "^9.26.0",
"globals": "^15.2.0", "globals": "^15.3.0",
"jsonc-eslint-parser": "^2.4.0", "jsonc-eslint-parser": "^2.4.0",
"vue-eslint-parser": "^9.4.2" "vue-eslint-parser": "^9.4.2"
} }
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
"./*": "./*" "./*": "./*"
}, },
"dependencies": { "dependencies": {
"@iconify/json": "^2.2.211", "@iconify/json": "^2.2.212",
"@iconify/tailwind": "^1.1.1", "@iconify/tailwind": "^1.1.1",
"@tailwindcss/forms": "^0.5.7", "@tailwindcss/forms": "^0.5.7",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
"html-minifier-terser": "^7.2.0", "html-minifier-terser": "^7.2.0",
"resolve.exports": "^2.0.2", "resolve.exports": "^2.0.2",
"vite-plugin-lib-inject-css": "^2.1.1", "vite-plugin-lib-inject-css": "^2.1.1",
"vite-plugin-vue-devtools": "^7.2.0" "vite-plugin-vue-devtools": "^7.2.1"
}, },
"devDependencies": { "devDependencies": {
"@types/html-minifier-terser": "^7.0.2", "@types/html-minifier-terser": "^7.0.2",
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
"test": "vitest" "test": "vitest"
}, },
"devDependencies": { "devDependencies": {
"@changesets/cli": "^2.27.2", "@changesets/cli": "^2.27.3",
"@ls-lint/ls-lint": "^2.2.3", "@ls-lint/ls-lint": "^2.2.3",
"@types/jsdom": "^21.1.6", "@types/jsdom": "^21.1.6",
"@types/node": "^20.12.12", "@types/node": "^20.12.12",
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
"node": ">=18.7.0", "node": ">=18.7.0",
"pnpm": ">=8.5.0" "pnpm": ">=8.5.0"
}, },
"packageManager": "pnpm@9.1.1", "packageManager": "pnpm@9.1.2",
"pnpm": { "pnpm": {
"overrides": { "overrides": {
"@ctrl/tinycolor": "4.1.0", "@ctrl/tinycolor": "4.1.0",
......
...@@ -81,6 +81,10 @@ declare module 'vue-router' { ...@@ -81,6 +81,10 @@ declare module 'vue-router' {
*/ */
orderNo?: number; orderNo?: number;
/** /**
* 外链-跳转路径
*/
target?: string;
/**
* 标题名称 * 标题名称
*/ */
title: string; title: string;
......
...@@ -100,12 +100,7 @@ onBeforeUnmount(() => { ...@@ -100,12 +100,7 @@ onBeforeUnmount(() => {
</VbenTooltip> </VbenTooltip>
<div v-show="!showTooltip" :class="[e('content')]"> <div v-show="!showTooltip" :class="[e('content')]">
<VbenMenuBadge v-bind="props" /> <VbenMenuBadge v-bind="props" />
<VbenIcon <VbenIcon :class="nsMenu.e('icon')" :icon="icon" fallback />
v-if="isTopLevelMenuItem"
:class="nsMenu.e('icon')"
:icon="icon"
fallback
/>
<slot></slot> <slot></slot>
<slot name="title"></slot> <slot name="title"></slot>
......
<script lang="ts" setup> <script lang="ts" setup>
import { IcRoundMoreHoriz } from '@vben-core/iconify'; import { IcRoundMoreHoriz } from '@vben-core/iconify';
import { useNamespace } from '@vben-core/toolkit'; import { isHttpUrl, useNamespace } from '@vben-core/toolkit';
import { UseResizeObserverReturn, useResizeObserver } from '@vueuse/core'; import { UseResizeObserverReturn, useResizeObserver } from '@vueuse/core';
import { import {
...@@ -241,7 +241,10 @@ function handleMenuItemClick(data: MenuItemClicked) { ...@@ -241,7 +241,10 @@ function handleMenuItemClick(data: MenuItemClicked) {
if (!path || !parentPaths) { if (!path || !parentPaths) {
return; return;
} }
if (!isHttpUrl(path)) {
activePath.value = path; activePath.value = path;
}
emit('select', path, parentPaths); emit('select', path, parentPaths);
} }
......
...@@ -86,7 +86,7 @@ const iconArrowStyle = computed(() => { ...@@ -86,7 +86,7 @@ const iconArrowStyle = computed(() => {
<slot></slot> <slot></slot>
<VbenIcon <VbenIcon
v-if="isTopLevelMenuSubmenu && !isMenuMore" v-if="!isMenuMore"
:class="nsMenu.e('icon')" :class="nsMenu.e('icon')"
:icon="icon" :icon="icon"
fallback fallback
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
--menu-item-collapse-margin-y: 4px; --menu-item-collapse-margin-y: 4px;
--menu-item-collapse-margin-x: 0px; --menu-item-collapse-margin-x: 0px;
--menu-item-radius: 0px; --menu-item-radius: 0px;
--menu-item-indent: 24px; --menu-item-indent: 16px;
--menu-font-size: 14px; --menu-font-size: 14px;
--menu-dark-background: 0deg 0% 100% / 10%; --menu-dark-background: 0deg 0% 100% / 10%;
--menu-light-background: 192deg 1% 93%; --menu-light-background: 192deg 1% 93%;
......
<script lang="ts" setup> <script lang="ts" setup>
import { Icon } from '@vben-core/iconify'; import { VbenIcon } from '@vben-core/shadcn-ui';
import type { IBreadcrumb } from './interface'; import type { IBreadcrumb } from './interface';
...@@ -32,7 +32,7 @@ function handleClick(path?: string) { ...@@ -32,7 +32,7 @@ function handleClick(path?: string) {
<li> <li>
<a href="javascript:void 0" @click.stop="handleClick(item.path)"> <a href="javascript:void 0" @click.stop="handleClick(item.path)">
<span class="flex-center h-full"> <span class="flex-center h-full">
<Icon <VbenIcon
v-if="item.icon && showIcon" v-if="item.icon && showIcon"
class="mr-1 size-5 flex-shrink-0" class="mr-1 size-5 flex-shrink-0"
:icon="item.icon" :icon="item.icon"
......
<script lang="ts" setup> <script lang="ts" setup>
import { IcRoundKeyboardArrowDown, Icon } from '@vben-core/iconify'; import { IcRoundKeyboardArrowDown } from '@vben-core/iconify';
import { VbenIcon } from '@vben-core/shadcn-ui';
import { import {
Breadcrumb, Breadcrumb,
...@@ -49,7 +50,7 @@ function handleClick(path?: string) { ...@@ -49,7 +50,7 @@ function handleClick(path?: string) {
<div v-if="item.items?.length ?? 0 > 0"> <div v-if="item.items?.length ?? 0 > 0">
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger class="flex items-center gap-1"> <DropdownMenuTrigger class="flex items-center gap-1">
<Icon <VbenIcon
v-if="item.icon && showIcon" v-if="item.icon && showIcon"
class="size-5" class="size-5"
:icon="item.icon" :icon="item.icon"
...@@ -74,21 +75,26 @@ function handleClick(path?: string) { ...@@ -74,21 +75,26 @@ function handleClick(path?: string) {
href="javascript:void 0" href="javascript:void 0"
@click.stop="handleClick(item.path)" @click.stop="handleClick(item.path)"
> >
<Icon <div class="flex-center">
<VbenIcon
v-if="item.icon && showIcon" v-if="item.icon && showIcon"
class="size-4" class="mr-1 size-4"
:class="{ 'size-5': item.isHome }" :class="{ 'size-5': item.isHome }"
:icon="item.icon" :icon="item.icon"
/> />
{{ item.title }} {{ item.title }}
</div>
</BreadcrumbLink> </BreadcrumbLink>
<BreadcrumbPage v-else> <BreadcrumbPage v-else>
<Icon <div class="flex-center">
<VbenIcon
v-if="item.icon && showIcon" v-if="item.icon && showIcon"
class="size-4" class="mr-1 size-4"
:class="{ 'size-5': item.isHome }"
:icon="item.icon" :icon="item.icon"
/> />
{{ item.title }} {{ item.title }}
</div>
</BreadcrumbPage> </BreadcrumbPage>
</BreadcrumbItem> </BreadcrumbItem>
<BreadcrumbSeparator <BreadcrumbSeparator
......
...@@ -29,7 +29,7 @@ const props = withDefaults(defineProps<Props>(), { ...@@ -29,7 +29,7 @@ const props = withDefaults(defineProps<Props>(), {
const emit = defineEmits<{ close: [string]; unPushPin: [TabItem] }>(); const emit = defineEmits<{ close: [string]; unPushPin: [TabItem] }>();
const gap = 7; const gap = 6;
const active = defineModel<string>('active'); const active = defineModel<string>('active');
const { b, e, is } = useNamespace('tabs-ui'); const { b, e, is } = useNamespace('tabs-ui');
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
@include b('tabs-ui') { @include b('tabs-ui') {
--tabs-background: hsl(var(--color-background)); --tabs-background: hsl(var(--color-background));
--tabs-gap: 8px; --tabs-gap: 10px;
--tabs-divider: hsl(var(--color-border)); --tabs-divider: hsl(var(--color-border));
--tabs-hover: hsl(var(--color-heavy)); --tabs-hover: hsl(var(--color-heavy));
--tabs-active-background: hsl(var(--color-primary) / 15%); --tabs-active-background: hsl(var(--color-primary) / 15%);
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
color: hsl(var(--color-muted-foreground)); color: hsl(var(--color-muted-foreground));
cursor: pointer; cursor: pointer;
user-select: none; user-select: none;
// mask-image: linear-gradient(to right, #000 calc(100% - 0px), transparent);
@include is('active') { @include is('active') {
z-index: 1; z-index: 1;
...@@ -49,10 +48,10 @@ ...@@ -49,10 +48,10 @@
background-color: var(--tabs-active-background); background-color: var(--tabs-active-background);
} }
// .#{$namespace}-tab-background__before, .#{$namespace}-tab-background__before,
// .#{$namespace}-tab-background__after { .#{$namespace}-tab-background__after {
// fill: var(--tabs-active-background); fill: var(--tabs-active-background);
// } }
} }
@include e('content') { @include e('content') {
...@@ -95,7 +94,7 @@ ...@@ -95,7 +94,7 @@
height: 100%; height: 100%;
font-size: 12px; font-size: 12px;
border-radius: 50%; border-radius: 50%;
// transition: all 0.15s ease; transition: all 0.15s ease;
&:hover { &:hover {
color: hsl(var(--color-foreground)); color: hsl(var(--color-foreground));
...@@ -185,15 +184,15 @@ ...@@ -185,15 +184,15 @@
height: 100%; height: 100%;
margin: 0 7px; margin: 0 7px;
&::before { // &::before {
position: absolute; // position: absolute;
top: 20%; // top: 20%;
right: 100%; // right: 100%;
width: 1px; // width: 1px;
height: 60%; // height: 60%;
content: ''; // content: '';
background-color: var(--tabs-divider); // background-color: var(--tabs-divider);
} // }
// &::after { // &::after {
// position: absolute; // position: absolute;
......
<script lang="ts" setup> <script lang="ts" setup>
import { VbenAdminLayout } from '@vben-core/layout-ui'; import { VbenAdminLayout } from '@vben-core/layout-ui';
import { VbenBackTop, VbenLogo } from '@vben-core/shadcn-ui'; import { VbenBackTop, VbenLogo } from '@vben-core/shadcn-ui';
import { mapTree } from '@vben-core/toolkit';
import { MenuRecordRaw } from '@vben-core/typings';
import { PreferenceWidget } from '@vben/common-ui'; import { PreferenceWidget } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { preference, updatePreference, usePreference } from '@vben/preference'; import { preference, updatePreference, usePreference } from '@vben/preference';
import { computed } from 'vue'; import { computed } from 'vue';
...@@ -80,6 +83,15 @@ const { ...@@ -80,6 +83,15 @@ const {
sideMenus, sideMenus,
sideVisible, sideVisible,
} = useMixedMenu(); } = useMixedMenu();
function wrapperMenus(menus: MenuRecordRaw[]) {
return mapTree(menus, (item) => {
return {
...item,
name: $t(item.name),
};
});
}
</script> </script>
<template> <template>
...@@ -154,7 +166,7 @@ const { ...@@ -154,7 +166,7 @@ const {
:rounded="isMenuRounded" :rounded="isMenuRounded"
mode="horizontal" mode="horizontal"
:theme="headerMenuTheme" :theme="headerMenuTheme"
:menus="headerMenus" :menus="wrapperMenus(headerMenus)"
:default-active="headerActive" :default-active="headerActive"
@select="handleMenuSelect" @select="handleMenuSelect"
/> />
...@@ -175,7 +187,7 @@ const { ...@@ -175,7 +187,7 @@ const {
:collapse-show-title="preference.sideCollapseShowTitle" :collapse-show-title="preference.sideCollapseShowTitle"
:collapse="preference.sideCollapse" :collapse="preference.sideCollapse"
:theme="theme" :theme="theme"
:menus="sideMenus" :menus="wrapperMenus(sideMenus)"
:default-active="sideActive" :default-active="sideActive"
@select="handleMenuSelect" @select="handleMenuSelect"
/> />
...@@ -195,7 +207,7 @@ const { ...@@ -195,7 +207,7 @@ const {
<template #side-extra> <template #side-extra>
<LayoutExtraMenu <LayoutExtraMenu
:rounded="isMenuRounded" :rounded="isMenuRounded"
:menus="extraMenus" :menus="wrapperMenus(extraMenus)"
:collapse="preference.sideExtraCollapse" :collapse="preference.sideExtraCollapse"
:theme="theme" :theme="theme"
/> />
......
...@@ -3,7 +3,9 @@ import type { MenuRecordRaw } from '@vben-core/typings'; ...@@ -3,7 +3,9 @@ import type { MenuRecordRaw } from '@vben-core/typings';
import { Menu, MenuProps } from '@vben-core/menu-ui'; import { Menu, MenuProps } from '@vben-core/menu-ui';
import { useRoute, useRouter } from 'vue-router'; import { useRoute } from 'vue-router';
import { useNavigation } from './use-navigation';
interface Props extends MenuProps { interface Props extends MenuProps {
collspae?: boolean; collspae?: boolean;
...@@ -13,10 +15,10 @@ interface Props extends MenuProps { ...@@ -13,10 +15,10 @@ interface Props extends MenuProps {
defineProps<Props>(); defineProps<Props>();
const route = useRoute(); const route = useRoute();
const router = useRouter(); const { navigation } = useNavigation();
function handleSelect(key: string) { async function handleSelect(key: string) {
router.push(key); await navigation(key);
} }
</script> </script>
......
...@@ -3,17 +3,18 @@ import type { MenuRecordRaw } from '@vben-core/typings'; ...@@ -3,17 +3,18 @@ import type { MenuRecordRaw } from '@vben-core/typings';
import { preference } from '@vben/preference'; import { preference } from '@vben/preference';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute } from 'vue-router';
import { findRootMenuByPath } from './helper'; import { findRootMenuByPath } from './helper';
import { useNavigation } from './use-navigation';
function useExtraMenu() { function useExtraMenu() {
const accessStore = useAccessStore(); const accessStore = useAccessStore();
const { navigation } = useNavigation();
const menus = computed(() => accessStore.getAccessMenus); const menus = computed(() => accessStore.getAccessMenus);
const route = useRoute(); const route = useRoute();
const router = useRouter();
const extraMenus = ref<MenuRecordRaw[]>([]); const extraMenus = ref<MenuRecordRaw[]>([]);
const extraVisible = ref<boolean>(false); const extraVisible = ref<boolean>(false);
const extraActiveMenu = ref(''); const extraActiveMenu = ref('');
...@@ -22,14 +23,14 @@ function useExtraMenu() { ...@@ -22,14 +23,14 @@ function useExtraMenu() {
* 选择混合菜单事件 * 选择混合菜单事件
* @param menu * @param menu
*/ */
const handleMixedMenuSelect = (menu: MenuRecordRaw) => { const handleMixedMenuSelect = async (menu: MenuRecordRaw) => {
extraMenus.value = menu?.children ?? []; extraMenus.value = menu?.children ?? [];
extraActiveMenu.value = menu.parents?.[0] ?? menu.path; extraActiveMenu.value = menu.parents?.[0] ?? menu.path;
const hasChildren = extraMenus.value.length > 0; const hasChildren = extraMenus.value.length > 0;
extraVisible.value = hasChildren; extraVisible.value = hasChildren;
if (!hasChildren) { if (!hasChildren) {
router.push(menu.path); await navigation(menu.path);
} }
}; };
......
...@@ -3,15 +3,15 @@ import type { MenuRecordRaw } from '@vben-core/typings'; ...@@ -3,15 +3,15 @@ import type { MenuRecordRaw } from '@vben-core/typings';
import { preference, usePreference } from '@vben/preference'; import { preference, usePreference } from '@vben/preference';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onBeforeMount, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute } from 'vue-router';
import { findRootMenuByPath } from './helper'; import { findRootMenuByPath } from './helper';
import { useNavigation } from './use-navigation';
function useMixedMenu() { function useMixedMenu() {
const accessStore = useAccessStore(); const accessStore = useAccessStore();
const { navigation } = useNavigation();
const route = useRoute(); const route = useRoute();
const router = useRouter();
const splitSideMenus = ref<MenuRecordRaw[]>([]); const splitSideMenus = ref<MenuRecordRaw[]>([]);
const rootMenuPath = ref<string>(''); const rootMenuPath = ref<string>('');
...@@ -75,7 +75,7 @@ function useMixedMenu() { ...@@ -75,7 +75,7 @@ function useMixedMenu() {
*/ */
const handleMenuSelect = (key: string, mode?: string) => { const handleMenuSelect = (key: string, mode?: string) => {
if (!isMixedNav.value || mode === 'vertical') { if (!isMixedNav.value || mode === 'vertical') {
router.push(key); navigation(key);
return; return;
} }
...@@ -83,7 +83,7 @@ function useMixedMenu() { ...@@ -83,7 +83,7 @@ function useMixedMenu() {
rootMenuPath.value = rootMenu?.path ?? ''; rootMenuPath.value = rootMenu?.path ?? '';
splitSideMenus.value = rootMenu?.children ?? []; splitSideMenus.value = rootMenu?.children ?? [];
if (splitSideMenus.value.length === 0) { if (splitSideMenus.value.length === 0) {
router.push(key); navigation(key);
} }
}; };
......
import { isHttpUrl, openWindow } from '@vben-core/toolkit';
import { useRouter } from 'vue-router';
function useNavigation() {
const router = useRouter();
const navigation = async (path: string) => {
if (isHttpUrl(path)) {
openWindow(path, { target: '_blank' });
} else {
await router.push(path);
}
};
return { navigation };
}
export { useNavigation };
...@@ -12,7 +12,12 @@ import { ...@@ -12,7 +12,12 @@ import {
MdiPinOff, MdiPinOff,
} from '@vben-core/iconify'; } from '@vben-core/iconify';
import { filterTree } from '@vben-core/toolkit'; import { filterTree } from '@vben-core/toolkit';
import type {
RouteLocationNormalized,
RouteRecordNormalized,
} from 'vue-router';
import { $t } from '@vben/locales';
import { storeToRefs, useAccessStore, useTabsStore } from '@vben/stores'; import { storeToRefs, useAccessStore, useTabsStore } from '@vben/stores';
import { computed, watch } from 'vue'; import { computed, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
...@@ -39,6 +44,9 @@ function useTabs() { ...@@ -39,6 +44,9 @@ function useTabs() {
const affixTabs = filterTree(router.getRoutes(), (route) => { const affixTabs = filterTree(router.getRoutes(), (route) => {
return !!route.meta?.affixTab; return !!route.meta?.affixTab;
}); });
affixTabs.forEach((tab) => {
Object.assign(tab, wrapperTabLocale(tab));
});
tabsStore.setAffixTabs(affixTabs); tabsStore.setAffixTabs(affixTabs);
}; };
...@@ -52,6 +60,18 @@ function useTabs() { ...@@ -52,6 +60,18 @@ function useTabs() {
await tabsStore.closeTabByKey(key, router); await tabsStore.closeTabByKey(key, router);
}; };
function wrapperTabLocale(
tab: RouteLocationNormalized | RouteRecordNormalized,
) {
return {
...tab,
meta: {
...tab.meta,
title: $t(tab.meta.title as string),
},
};
}
watch( watch(
() => accessMenus.value, () => accessMenus.value,
() => { () => {
...@@ -63,7 +83,7 @@ function useTabs() { ...@@ -63,7 +83,7 @@ function useTabs() {
watch( watch(
() => route.path, () => route.path,
() => { () => {
tabsStore.addTab(route); tabsStore.addTab(wrapperTabLocale(route) as RouteLocationNormalized);
}, },
{ immediate: true }, { immediate: true },
); );
......
...@@ -4,6 +4,7 @@ import type { IBreadcrumb } from '@vben-core/shadcn-ui'; ...@@ -4,6 +4,7 @@ import type { IBreadcrumb } from '@vben-core/shadcn-ui';
import { VbenBackgroundBreadcrumb, VbenBreadcrumb } from '@vben-core/shadcn-ui'; import { VbenBackgroundBreadcrumb, VbenBreadcrumb } from '@vben-core/shadcn-ui';
import { BreadcrumbStyle } from '@vben-core/typings'; import { BreadcrumbStyle } from '@vben-core/typings';
import { $t } from '@vben/locales';
import { computed } from 'vue'; import { computed } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
...@@ -43,7 +44,7 @@ const breadcrumbs = computed((): IBreadcrumb[] => { ...@@ -43,7 +44,7 @@ const breadcrumbs = computed((): IBreadcrumb[] => {
resultBreadcrumb.push({ resultBreadcrumb.push({
icon: icon as string, icon: icon as string,
path: path || route.path, path: path || route.path,
title: (title || name) as string, title: $t((title || name) as string),
// items: children.map((child) => { // items: children.map((child) => {
// return { // return {
// icon: child?.meta?.icon as string, // icon: child?.meta?.icon as string,
......
import { defineBuildConfig } from 'unbuild';
export default defineBuildConfig({
clean: true,
declaration: true,
entries: ['src/index'],
});
{
"name": "@vben/constants",
"version": "1.0.0",
"type": "module",
"license": "MIT",
"homepage": "https://github.com/vbenjs/vue-vben-admin",
"repository": {
"type": "git",
"url": "git+https://github.com/vbenjs/vue-vben-admin.git",
"directory": "packages/constants"
},
"bugs": {
"url": "https://github.com/vbenjs/vue-vben-admin/issues"
},
"scripts": {
"build": "pnpm unbuild",
"stub": "pnpm unbuild --stub"
},
"files": [
"dist"
],
"sideEffects": [
"**/*.css"
],
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"imports": {
"#*": "./src/*"
},
"exports": {
".": {
"development": "./src/index.ts",
"types": "./src/index.ts",
"default": "./dist/index.mjs"
}
},
"publishConfig": {
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
}
}
}
}
export * from './vben';
export const VBEN_GITHUB_URL = 'https://github.com/vbenjs/vue-vben-admin';
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@vben/tsconfig/library.json",
"include": ["src"]
}
...@@ -5,6 +5,7 @@ export default defineBuildConfig({ ...@@ -5,6 +5,7 @@ export default defineBuildConfig({
declaration: true, declaration: true,
entries: [ entries: [
'src/index', 'src/index',
'src/helper',
{ {
builder: 'mkdist', builder: 'mkdist',
input: './src/langs', input: './src/langs',
......
...@@ -35,6 +35,11 @@ ...@@ -35,6 +35,11 @@
}, },
"./langs/*": { "./langs/*": {
"default": "./dist/langs/*" "default": "./dist/langs/*"
},
"./helper": {
"development": "./src/helper.ts",
"types": "./src/helper.ts",
"default": "./dist/helper.mjs"
} }
}, },
"publishConfig": { "publishConfig": {
......
/**
* 没有任何实际作用,只用于 IDE 对I18的提示
*/
function $t(key: string) {
return key;
}
export { $t };
...@@ -149,3 +149,7 @@ authentication: ...@@ -149,3 +149,7 @@ authentication:
send-code: Get Security code send-code: Get Security code
send-text: "Reacquire in {0}s" send-text: "Reacquire in {0}s"
third-party-login: Or continue with third-party-login: Or continue with
page:
about: About
document: Document
...@@ -148,3 +148,7 @@ authentication: ...@@ -148,3 +148,7 @@ authentication:
send-code: 获取验证码 send-code: 获取验证码
send-text: "{0}秒后重新获取" send-text: "{0}秒后重新获取"
third-party-login: 其他登录方式 third-party-login: 其他登录方式
page:
about: 关于
document: 文档
import { defineBuildConfig } from 'unbuild';
export default defineBuildConfig({
clean: true,
declaration: true,
entries: ['src/index'],
});
{
"name": "@vben/utils",
"version": "1.0.0",
"type": "module",
"license": "MIT",
"homepage": "https://github.com/vbenjs/vue-vben-admin",
"repository": {
"type": "git",
"url": "git+https://github.com/vbenjs/vue-vben-admin.git",
"directory": "packages/utils"
},
"bugs": {
"url": "https://github.com/vbenjs/vue-vben-admin/issues"
},
"scripts": {
"build": "pnpm unbuild",
"stub": "pnpm unbuild --stub"
},
"files": [
"dist"
],
"sideEffects": [
"**/*.css"
],
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"imports": {
"#*": "./src/*"
},
"exports": {
".": {
"development": "./src/index.ts",
"types": "./src/index.ts",
"default": "./dist/index.mjs"
}
},
"publishConfig": {
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
}
}
},
"dependencies": {
"@vben-core/toolkit": "workspace:*"
}
}
export * from '@vben-core/toolkit';
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@vben/tsconfig/library.json",
"include": ["src"]
}
...@@ -85,6 +85,10 @@ ...@@ -85,6 +85,10 @@
"path": "packages/business/layouts", "path": "packages/business/layouts",
}, },
{ {
"name": "@vben/constants",
"path": "packages/constants",
},
{
"name": "@vben/hooks", "name": "@vben/hooks",
"path": "packages/hooks", "path": "packages/hooks",
}, },
...@@ -105,6 +109,10 @@ ...@@ -105,6 +109,10 @@
"path": "packages/stores", "path": "packages/stores",
}, },
{ {
"name": "@vben/utils",
"path": "packages/utils",
},
{
"name": "@vben/vsh", "name": "@vben/vsh",
"path": "scripts/vsh", "path": "scripts/vsh",
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!