update: 升级vben5.5.9到5.7.0

This commit is contained in:
2026-09-22 17:09:46 +08:00
parent 345e4a31f8
commit 802f72cd9e
766 changed files with 28468 additions and 15447 deletions
@@ -1,26 +0,0 @@
import { defineBuildConfig } from 'unbuild';
export default defineBuildConfig({
clean: true,
declaration: true,
entries: [
{
builder: 'mkdist',
input: './src',
pattern: ['**/*'],
},
{
builder: 'mkdist',
input: './src',
loaders: ['vue'],
pattern: ['**/*.vue'],
},
{
builder: 'mkdist',
format: 'esm',
input: './src',
loaders: ['js'],
pattern: ['**/*.ts'],
},
],
});
@@ -1,6 +1,6 @@
{
"name": "@vben-core/menu-ui",
"version": "5.5.9",
"version": "5.7.0",
"homepage": "https://github.com/vbenjs/vue-vben-admin",
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
"repository": {
@@ -11,7 +11,7 @@
"license": "MIT",
"type": "module",
"scripts": {
"build": "pnpm unbuild",
"build": "pnpm exec tsdown",
"prepublishOnly": "npm run build"
},
"files": [
@@ -22,27 +22,36 @@
],
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"development": "./src/index.ts",
"production": "./src/index.ts",
"default": "./dist/index.mjs"
}
},
"publishConfig": {
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
}
}
},
"dependencies": {
"@vben-core/composables": "workspace:*",
"@vben-core/design": "workspace:*",
"@vben-core/icons": "workspace:*",
"@vben-core/shadcn-ui": "workspace:*",
"@vben-core/shared": "workspace:*",
"@vben-core/typings": "workspace:*",
"@vueuse/core": "catalog:",
"qs": "catalog:",
"vue": "catalog:"
},
"devDependencies": {
"@types/qs": "catalog:",
"unplugin-vue": "catalog:"
}
}
@@ -1 +0,0 @@
export { default } from '@vben/tailwind-config/postcss';
@@ -16,7 +16,7 @@ withDefaults(defineProps<Props>(), {
<span
:class="dotClass"
:style="dotStyle"
class="absolute inline-flex h-full w-full animate-ping rounded-full opacity-75"
class="absolute inline-flex size-full animate-ping rounded-full opacity-75"
>
</span>
<span
@@ -49,7 +49,7 @@ const badgeStyle = computed(() => {
v-else
:class="badgeClass"
:style="badgeStyle"
class="text-primary-foreground flex-center rounded-xl px-1.5 py-0.5 text-[10px]"
class="flex-center rounded-xl px-1.5 py-0.5 text-[10px] text-primary-foreground"
>
{{ badge }}
</div>
@@ -5,6 +5,9 @@ import { computed, onBeforeUnmount, onMounted, reactive, useSlots } from 'vue';
import { useNamespace } from '@vben-core/composables';
import { VbenIcon, VbenTooltip } from '@vben-core/shadcn-ui';
import { isHttpUrl } from '@vben-core/shared/utils';
import qs from 'qs';
import { MenuBadge } from '../components';
import { useMenu, useMenuContext, useSubMenuContext } from '../hooks';
@@ -31,6 +34,8 @@ const menuIcon = computed(() =>
active.value ? props.activeIcon || props.icon : props.icon,
);
const isHttp = computed(() => isHttpUrl(item.parentPaths.at(-1)));
const isTopLevelMenuItem = computed(
() => parentMenu.value?.type.name === 'Menu',
);
@@ -54,6 +59,7 @@ const item: MenuItemRegistered = reactive({
active,
parentPaths: parentPaths.value,
path: props.path || '',
query: props.query,
});
/**
@@ -81,42 +87,52 @@ onBeforeUnmount(() => {
});
</script>
<template>
<li
:class="[
rootMenu.theme,
b(),
is('active', active),
is('disabled', disabled),
is('collapse-show-title', collapseShowTitle),
]"
role="menuitem"
@click.stop="handleClick"
<router-link
v-slot="{ href }"
custom
:to="
(item.parentPaths.at(-1) ?? '') +
(item?.query ? `?${qs.stringify(item?.query)}` : '')
"
>
<VbenTooltip
v-if="showTooltip"
:content-class="[rootMenu.theme]"
side="right"
<a
:href="isHttp ? item.parentPaths.at(-1) : href"
:class="[
rootMenu.theme,
b(),
is('active', active),
is('disabled', disabled),
is('collapse-show-title', collapseShowTitle),
]"
role="menuitem"
@click.prevent.stop="handleClick"
>
<template #trigger>
<div :class="[nsMenu.be('tooltip', 'trigger')]">
<VbenIcon :class="nsMenu.e('icon')" :icon="menuIcon" fallback />
<slot></slot>
<span v-if="collapseShowTitle" :class="nsMenu.e('name')">
<slot name="title"></slot>
</span>
</div>
</template>
<slot name="title"></slot>
</VbenTooltip>
<div v-show="!showTooltip" :class="[e('content')]">
<MenuBadge
v-if="rootMenu.props.mode !== 'horizontal'"
class="right-2"
v-bind="props"
/>
<VbenIcon :class="nsMenu.e('icon')" :icon="menuIcon" />
<slot></slot>
<slot name="title"></slot>
</div>
</li>
<VbenTooltip
v-if="showTooltip"
:content-class="[rootMenu.theme]"
side="right"
>
<template #trigger>
<div :class="[nsMenu.be('tooltip', 'trigger')]">
<VbenIcon :class="nsMenu.e('icon')" :icon="menuIcon" fallback />
<slot></slot>
<span v-if="collapseShowTitle" :class="nsMenu.e('name')">
<slot name="title"></slot>
</span>
</div>
</template>
<slot name="title"></slot>
</VbenTooltip>
<div v-show="!showTooltip" :class="[e('content')]">
<MenuBadge
v-if="rootMenu.props.mode !== 'horizontal'"
class="right-2"
v-bind="props"
/>
<VbenIcon :class="nsMenu.e('icon')" :icon="menuIcon" />
<slot></slot>
<slot name="title"></slot>
</div>
</a>
</router-link>
</template>
@@ -212,15 +212,15 @@ const enableScroll = computed(
() => props.scrollToActive && props.mode === 'vertical' && !props.collapse,
);
const { scrollToActiveItem } = useMenuScroll(activePath, {
useMenuScroll(activePath, {
enable: enableScroll,
delay: 320,
});
// 监听 activePath 变化,自动滚动到激活项
watch(activePath, () => {
scrollToActiveItem();
});
// watch(activePath, () => {
// scrollToActiveItem();
// });
// 默认展开菜单
function initMenu() {
@@ -351,14 +351,14 @@ function getActivePaths() {
role="menu"
>
<template v-if="mode === 'horizontal' && getSlot.showSlotMore">
<template v-for="item in getSlot.slotDefault" :key="item.key">
<template v-for="(item, index) in getSlot.slotDefault" :key="index">
<component :is="item" />
</template>
<SubMenu is-sub-menu-more path="sub-menu-more">
<template #title>
<Ellipsis class="size-4" />
</template>
<template v-for="item in getSlot.slotMore" :key="item.key">
<template v-for="(item, index) in getSlot.slotMore" :key="index">
<component :is="item" />
</template>
</SubMenu>
@@ -388,7 +388,7 @@ $namespace: vben;
padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
margin: 0 var(--menu-item-margin-x) var(--menu-item-margin-y)
var(--menu-item-margin-x);
font-size: var(--menu-font-size);
font-size: var(--menu-font-size) !important;
color: var(--menu-item-color);
white-space: nowrap;
text-decoration: none;
@@ -433,6 +433,7 @@ $namespace: vben;
max-width: var(--menu-title-width);
overflow: hidden;
text-overflow: ellipsis;
font-size: var(--menu-font-size) !important;
white-space: nowrap;
opacity: 1;
}
@@ -444,7 +445,7 @@ $namespace: vben;
.#{$namespace}-menu__popup-container,
.#{$namespace}-menu {
--menu-title-width: 140px;
--menu-item-icon-size: 16px;
--menu-item-icon-size: var(--font-size-base, 16px);
--menu-item-height: 38px;
--menu-item-padding-y: 21px;
--menu-item-padding-x: 12px;
@@ -458,38 +459,37 @@ $namespace: vben;
--menu-item-collapse-margin-x: 0px;
--menu-item-radius: 0px;
--menu-item-indent: 16px;
--menu-font-size: 14px;
&.is-dark {
--menu-background-color: hsl(var(--menu));
// --menu-submenu-opened-background-color: hsl(var(--menu-opened-dark));
--menu-item-background-color: var(--menu-background-color);
--menu-item-color: hsl(var(--foreground) / 80%);
--menu-item-background-color: var(--menu-background-color);
--menu-item-hover-color: hsl(var(--accent-foreground));
--menu-item-hover-background-color: hsl(var(--accent));
--menu-item-active-color: hsl(var(--accent-foreground));
--menu-item-active-background-color: hsl(var(--accent));
--menu-submenu-hover-color: hsl(var(--foreground));
--menu-submenu-hover-background-color: hsl(var(--accent));
--menu-submenu-active-color: hsl(var(--foreground));
--menu-submenu-active-background-color: transparent;
--menu-submenu-background-color: var(--menu-background-color);
--menu-submenu-hover-color: hsl(var(--accent-foreground));
--menu-submenu-hover-background-color: hsl(var(--accent));
--menu-submenu-active-color: hsl(var(--accent-foreground));
--menu-submenu-active-background-color: transparent;
}
&.is-light {
--menu-background-color: hsl(var(--menu));
// --menu-submenu-opened-background-color: hsl(var(--menu-opened));
--menu-item-color: hsl(var(--accent-foreground));
--menu-item-background-color: var(--menu-background-color);
--menu-item-color: hsl(var(--foreground));
--menu-item-hover-color: var(--menu-item-color);
--menu-item-hover-background-color: hsl(var(--accent));
--menu-item-active-color: hsl(var(--primary));
--menu-item-active-background-color: hsl(var(--primary) / 15%);
--menu-submenu-background-color: var(--menu-background-color);
--menu-submenu-hover-color: hsl(var(--primary));
--menu-submenu-hover-background-color: hsl(var(--accent));
--menu-submenu-active-color: hsl(var(--primary));
--menu-submenu-active-background-color: transparent;
--menu-submenu-background-color: var(--menu-background-color);
}
&.is-rounded {
@@ -518,25 +518,33 @@ $namespace: vben;
--menu-background-color: transparent;
&.is-dark {
--menu-background-color: hsl(var(--menu));
--menu-item-color: hsl(var(--foreground) / 80%);
--menu-item-background-color: var(--menu-background-color);
--menu-item-hover-color: hsl(var(--accent-foreground));
--menu-item-hover-background-color: hsl(var(--accent));
--menu-item-active-color: hsl(var(--accent-foreground));
--menu-item-active-background-color: hsl(var(--accent));
--menu-submenu-active-color: hsl(var(--foreground));
--menu-submenu-active-background-color: hsl(var(--accent));
--menu-submenu-background-color: var(--menu-background-color);
--menu-submenu-hover-color: hsl(var(--accent-foreground));
--menu-submenu-hover-background-color: hsl(var(--accent));
--menu-submenu-active-color: hsl(var(--accent-foreground));
--menu-submenu-active-background-color: hsl(var(--accent));
}
&.is-light {
--menu-background-color: hsl(var(--menu));
--menu-item-color: hsl(var(--accent-foreground));
--menu-item-background-color: var(--menu-background-color);
--menu-item-hover-color: var(--menu-item-color);
--menu-item-hover-background-color: hsl(var(--accent));
--menu-item-active-color: hsl(var(--primary));
--menu-item-active-background-color: hsl(var(--primary) / 15%);
--menu-item-hover-background-color: hsl(var(--accent));
--menu-item-hover-color: hsl(var(--primary));
--menu-submenu-active-color: hsl(var(--primary));
--menu-submenu-active-background-color: hsl(var(--primary) / 15%);
--menu-submenu-background-color: var(--menu-background-color);
--menu-submenu-hover-color: hsl(var(--primary));
--menu-submenu-hover-background-color: hsl(var(--accent));
--menu-submenu-active-color: hsl(var(--primary));
--menu-submenu-active-background-color: hsl(var(--primary) / 15%);
}
}
}
@@ -752,7 +760,7 @@ $namespace: vben;
}
.#{$namespace}-menu__icon {
display: block;
font-size: 20px !important;
font-size: calc(var(--font-size-base, 16px) * 1.25) !important;
transition: all 0.25s ease;
}
@@ -760,7 +768,7 @@ $namespace: vben;
display: inline-flex;
margin-top: 8px;
margin-bottom: 0;
font-size: 12px;
font-size: calc(var(--font-size-base, 16px) * 0.75);
font-weight: 400;
line-height: normal;
transition: all 0.25s ease;
@@ -785,7 +793,7 @@ $namespace: vben;
width: 100%;
height: 100%;
padding: 0 var(--menu-item-padding-x);
font-size: var(--menu-font-size);
font-size: var(--menu-font-size) !important;
line-height: var(--menu-item-height);
}
}
@@ -812,9 +820,14 @@ $namespace: vben;
.#{$namespace}-sub-menu-content {
height: var(--menu-item-height);
font-size: var(--menu-font-size) !important;
@include menu-item;
* {
font-size: inherit !important;
}
&__icon-arrow {
position: absolute;
top: 50%;
@@ -857,9 +870,8 @@ $namespace: vben;
padding-right: 12px !important;
}
// &:not(.is-active):hover {
&:hover {
color: var(--menu-submenu-hover-color);
&:not(.is-active):hover {
//color: var(--menu-submenu-hover-color);
text-decoration: none;
cursor: pointer;
background: var(--menu-submenu-hover-background-color) !important;
@@ -57,10 +57,10 @@ function menuIcon(menu: MenuRecordRaw) {
</template>
</ul>
</template>
<style lang="scss" scoped>
$namespace: vben;
<style scoped>
@reference "@vben/tailwind-config/theme";
.#{$namespace}-normal-menu {
.vben-normal-menu {
--menu-item-margin-y: 4px;
--menu-item-margin-x: 0px;
--menu-item-padding-y: 9px;
@@ -68,94 +68,95 @@ $namespace: vben;
--menu-item-radius: 0px;
height: calc(100% - 4px);
}
&.is-rounded {
--menu-item-radius: 6px;
--menu-item-margin-x: 8px;
}
.vben-normal-menu.is-rounded {
--menu-item-radius: 6px;
--menu-item-margin-x: 8px;
}
&.is-dark {
.#{$namespace}-normal-menu__item {
@apply text-foreground/80;
// color: hsl(var(--foreground) / 80%);
.vben-normal-menu.is-dark .vben-normal-menu__item {
@apply text-foreground/80;
}
&:not(.is-active):hover {
@apply text-foreground;
}
.vben-normal-menu.is-dark .vben-normal-menu__item:not(.is-active):hover {
@apply text-foreground;
}
&.is-active {
.#{$namespace}-normal-menu__name,
.#{$namespace}-normal-menu__icon {
@apply text-foreground;
}
}
}
}
.vben-normal-menu.is-dark
.vben-normal-menu__item.is-active
.vben-normal-menu__name,
.vben-normal-menu.is-dark
.vben-normal-menu__item.is-active
.vben-normal-menu__icon {
@apply text-foreground;
}
&.is-collapse {
.#{$namespace}-normal-menu__name {
width: 0;
height: 0;
margin-top: 0;
overflow: hidden;
opacity: 0;
}
.vben-normal-menu.is-collapse .vben-normal-menu__name {
width: 0;
height: 0;
margin-top: 0;
overflow: hidden;
opacity: 0;
}
.#{$namespace}-normal-menu__icon {
font-size: 20px;
}
}
.vben-normal-menu.is-collapse .vben-normal-menu__icon {
font-size: calc(var(--font-size-base, 16px) * 1.25);
}
&__item {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
// max-width: 64px;
// max-height: 64px;
padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
margin: var(--menu-item-margin-y) var(--menu-item-margin-x);
color: hsl(var(--foreground) / 90%);
cursor: pointer;
border-radius: var(--menu-item-radius);
transition:
background 0.15s ease,
padding 0.15s ease,
border-color 0.15s ease;
.vben-normal-menu__item {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
&.is-active {
@apply text-primary bg-primary dark:bg-accent;
/* max-width: 64px; */
.#{$namespace}-normal-menu__name,
.#{$namespace}-normal-menu__icon {
@apply text-primary-foreground font-semibold;
}
}
/* max-height: 64px; */
padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
margin: var(--menu-item-margin-y) var(--menu-item-margin-x);
color: hsl(var(--foreground) / 90%);
cursor: pointer;
border-radius: var(--menu-item-radius);
transition:
background 0.15s ease,
padding 0.15s ease,
border-color 0.15s ease;
}
&:not(.is-active):hover {
@apply dark:bg-accent text-primary bg-heavy dark:text-foreground;
}
.vben-normal-menu__item.is-active {
@apply bg-primary text-primary dark:bg-accent;
}
&:hover {
.#{$namespace}-normal-menu__icon {
transform: scale(1.2);
}
}
}
.vben-normal-menu__item.is-active .vben-normal-menu__name,
.vben-normal-menu__item.is-active .vben-normal-menu__icon {
@apply text-primary-foreground font-semibold;
}
&__icon {
max-height: 20px;
font-size: 20px;
transition: all 0.25s ease;
}
.vben-normal-menu__item:not(.is-active):hover {
@apply bg-heavy text-primary dark:bg-accent dark:text-foreground;
}
&__name {
margin-top: 8px;
margin-bottom: 0;
font-size: 12px;
font-weight: 400;
transition: all 0.25s ease;
}
.vben-normal-menu__item:hover .vben-normal-menu__icon {
transform: scale(1.2);
}
.vben-normal-menu__icon {
@apply max-h-5;
font-size: calc(var(--font-size-base, 16px) * 1.25);
transition: all 0.25s ease;
}
.vben-normal-menu__name {
@apply mt-2;
width: 100%;
margin-bottom: 0;
font-size: calc(var(--font-size-base, 16px) * 0.75);
font-weight: 400;
text-align: center;
transition: all 0.25s ease;
}
</style>
@@ -209,7 +209,8 @@ onBeforeUnmount(() => {
is(rootMenu.theme, true),
opened ? '' : 'hidden',
'overflow-auto',
'max-h-[calc(var(--radix-hover-card-content-available-height)-20px)]',
'max-h-[calc(var(--reka-hover-card-content-available-height)-20px)]',
mode === 'horizontal' ? 'is-horizontal' : '',
]"
:content-props="contentProps"
:open="true"
@@ -20,7 +20,7 @@ export function useMenuScroll(
if (!isEnabled) return;
const activeElement = document.querySelector(
`aside li[role=menuitem].is-active`,
`aside a[role=menuitem].is-active`,
);
if (activeElement) {
activeElement.scrollIntoView({
@@ -4,7 +4,6 @@ import type { MenuRecordRaw } from '@vben-core/typings';
import { computed } from 'vue';
import { MenuBadge, MenuItem, SubMenu as SubMenuComp } from './components';
// eslint-disable-next-line import/no-self-import
import SubMenu from './sub-menu.vue';
interface Props {
@@ -41,6 +40,7 @@ const hasChildren = computed(() => {
:badge-variants="menu.badgeVariants"
:icon="menu.icon"
:path="menu.path"
:query="menu.query"
>
<template #title>
<span>{{ menu.name }}</span>
@@ -1,6 +1,10 @@
import type { Component, Ref } from 'vue';
import type { MenuRecordBadgeRaw, ThemeModeType } from '@vben-core/typings';
import type {
MenuRecordBadgeRaw,
Recordable,
ThemeModeType,
} from '@vben-core/typings';
interface MenuProps {
/**
@@ -91,12 +95,17 @@ interface MenuItemProps extends MenuRecordBadgeRaw {
* @zh_CN menuitem 名称
*/
path: string;
/**
* @zh_CN 菜单所携带的参数
*/
query?: Recordable<any>;
}
interface MenuItemRegistered {
active: boolean;
parentPaths: string[];
path: string;
query?: Recordable<any>;
}
interface MenuItemClicked {
@@ -1 +0,0 @@
export { default } from '@vben/tailwind-config';
@@ -0,0 +1,21 @@
import { defineConfig } from 'tsdown';
import Vue from 'unplugin-vue/rolldown';
export default defineConfig({
clean: true,
deps: {
skipNodeModulesBundle: true,
},
dts: {
vue: true,
},
entry: ['src/index.ts'],
format: ['esm'],
outExtensions: () => ({
dts: '.d.ts',
js: '.mjs',
}),
platform: 'neutral',
plugins: [Vue({ isProduction: true })],
unbundle: true,
});