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