fix(admin): 校正侧栏箭头与折叠标志并整理子菜单

This commit is contained in:
2026-12-01 18:16:35 +08:00
parent 6ca42f5312
commit bfaf51796d
15 changed files with 499 additions and 30 deletions
@@ -1,7 +1,14 @@
<template>
<div class="fold h-full cursor-pointer flex items-center px-2" @click="toggleCollapsed">
<button
type="button"
class="fold h-full cursor-pointer flex items-center px-2"
:aria-label="isCollapsed ? '展开菜单' : '收起菜单'"
:title="isCollapsed ? '展开菜单' : '收起菜单'"
:aria-expanded="!isCollapsed"
@click="toggleCollapsed"
>
<icon :name="`local-icon-${isCollapsed ? 'expand' : 'collapse'}`" :size="18" />
</div>
</button>
</template>
<script setup lang="ts">
@@ -9,8 +16,5 @@ import useAppStore from '@/stores/modules/app'
const appStore = useAppStore()
const isCollapsed = computed(() => appStore.isCollapsed)
// 折叠展开菜单
const toggleCollapsed = () => {
appStore.toggleCollapsed()
}
const toggleCollapsed = () => appStore.toggleCollapsed()
</script>
@@ -3,14 +3,7 @@
<div class="navbar">
<div class="flex-1 flex">
<div class="navbar-item">
<el-tooltip
class="box-item"
effect="dark"
:content="isCollapsed ? '展开菜单' : '收起菜单'"
placement="bottom"
>
<fold />
</el-tooltip>
<fold />
</div>
<div class="navbar-item">
<el-tooltip class="box-item" effect="dark" content="刷新" placement="bottom">
@@ -84,7 +77,6 @@ import UserDropDown from './user-drop-down.vue'
const liveNative = import.meta.env.MODE === 'live-native'
const appStore = useAppStore()
const isMobile = computed(() => appStore.isMobile)
const isCollapsed = computed(() => appStore.isCollapsed)
const settingStore = useSettingStore()
const { isFullscreen } = useFullscreen()
</script>
@@ -1,12 +1,12 @@
<template>
<div class="logo" @click="handleClick">
<image-contain :width="szie" :height="szie" :src="config.web_logo" />
<image-contain class="logo-mark" :width="size" :height="size" :src="config.web_logo" />
<transition name="title-width">
<div
v-show="showTitle"
class="logo-title overflow-hidden whitespace-nowrap"
:class="{ 'text-white': theme == ThemeEnum.DARK }"
:style="{ left: `${szie + 16}px` }"
:style="{ left: `${size + 16}px` }"
>
<overflow-tooltip
:content="title || config.web_name"
@@ -25,7 +25,7 @@ import { ThemeEnum } from '@/enums/appEnums'
import useAppStore from '@/stores/modules/app'
defineProps({
szie: { type: Number, default: 34 },
size: { type: Number, default: 34 },
title: { type: String },
theme: { type: String },
showTitle: { type: Boolean, default: true }
@@ -66,4 +66,17 @@ const handleClick = () => {
opacity: 0;
}
}
:root[data-admin-ui='v2'] .logo {
// Let the menu, not the intrinsic width of the configured name, size the sidebar.
contain: inline-size;
.logo-mark {
flex: none;
:deep(.el-image__inner) { object-fit: contain; }
}
.logo-title {
flex: 1;
min-width: 0;
}
}
</style>
@@ -1,27 +1,32 @@
<template>
<template v-if="!route.meta?.hidden">
<app-link v-if="!hasShowChild" :to="menuTarget">
<el-menu-item :index="routePath">
<app-link v-if="!hasShowChild" :to="menuTarget" :class="{ 'admin-nav-link': art }">
<el-menu-item :index="routePath" :aria-label="art ? routeMeta?.title : undefined">
<icon
class="menu-item-icon"
:size="16"
:size="art ? 20 : 16"
v-if="routeMeta?.icon"
:name="routeMeta?.icon"
/>
<i v-else-if="art" class="menu-item-icon admin-nav-icon--empty" aria-hidden="true"
:data-initial="titleInitial" />
<template #title>
<span>{{ routeMeta?.title }}</span>
<span class="menu-name" :title="art ? routeMeta?.title : undefined">{{ routeMeta?.title }}</span>
</template>
</el-menu-item>
</app-link>
<el-sub-menu v-else :index="routePath" :popper-class="popperClass">
<el-sub-menu v-else :index="routePath" :popper-class="popperClass"
:aria-label="art ? routeMeta?.title : undefined">
<template #title>
<icon
class="menu-item-icon"
:size="16"
:size="art ? 20 : 16"
v-if="routeMeta?.icon"
:name="routeMeta?.icon"
/>
<span>{{ routeMeta?.title }}</span>
<i v-else-if="art" class="menu-item-icon admin-nav-icon--empty" aria-hidden="true"
:data-initial="titleInitial" />
<span class="menu-name" :title="art ? routeMeta?.title : undefined">{{ routeMeta?.title }}</span>
</template>
<menu-item
v-for="item in route?.children"
@@ -29,6 +34,7 @@
:route="item"
:route-path="resolvePath(item.path)"
:popper-class="popperClass"
:art="art"
/>
</el-sub-menu>
</template>
@@ -44,6 +50,7 @@ interface Props {
route: RouteRecordRaw
routePath: string
popperClass: string
art?: boolean
}
const props = defineProps<Props>()
@@ -56,6 +63,7 @@ const hasShowChild = computed(() => {
const routeMeta = computed(() => {
return props.route.meta
})
const titleInitial = computed(() => Array.from(String(routeMeta.value?.title || '').trim())[0])
const resolvePath = (path: string) => {
// The online preview uses generated absolute item IDs to preserve arbitrary
@@ -1,7 +1,7 @@
<template>
<div
class="menu flex-1 min-h-0"
:class="[themeClass, { 'menu--classic': classic }]"
:class="[themeClass, classic ? 'menu--classic' : 'admin-nav-tree']"
:style="isCollapsed ? '' : `--aside-width: ${width}px`"
>
<el-scrollbar>
@@ -18,7 +18,8 @@
:key="route.path"
:route="route"
:route-path="route.path"
:popper-class="themeClass"
:art="!classic"
:popper-class="popperClass"
/>
</el-menu>
</el-scrollbar>
@@ -61,6 +62,10 @@ defineEmits(['select'])
const route = useRoute()
const activeMenu = computed<string>(() => route.meta?.activeMenu || route.path)
const themeClass = computed(() => `theme-${props.theme}`)
// Teleported flyouts do not inherit the palette from .side.
const popperClass = computed(() =>
props.classic ? themeClass.value : `admin-nav-popper side--${props.theme}`
)
</script>
<style lang="scss" scoped>
@@ -1,5 +1,5 @@
<template>
<div class="side" :class="'side--' + sideTheme" :style="sideStyle">
<div class="side" :class="['side--' + sideTheme, { 'side--collapsed': isCollapsed }]" :style="sideStyle">
<side-logo v-if="settingStore.showLogo" :show-title="!isCollapsed" :theme="sideTheme" />
<div v-else-if="settingStore.adminUi === 'v2'" class="admin-nav-heading" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" width="24" height="24">
@@ -70,4 +70,18 @@ const handleSelect = () => {
@apply border-r border-br-light h-full flex flex-col;
background-color: var(--side-dark-color, var(--el-bg-color));
}
// The menu sets the rail width. Center either mark within that same content
// box (excluding the sidebar border), without the expanded header's 22px inset.
:root[data-admin-ui='v2'] .side--collapsed {
> :is(.logo, .admin-nav-heading) {
justify-content: center;
padding-inline: 0;
gap: 0;
}
// v-show keeps the name mounted during its leave transition.
:deep(.logo-title) {
display: none;
}
}
</style>
+95
View File
@@ -0,0 +1,95 @@
// SidebarSubmenu.vue / theme.scss (Art Design Pro f3aaf58): inline and flyout
// rows share the label/icon geometry, but not the indent or selection style.
:root[data-admin-ui='v2'] {
:is(.side .admin-nav-tree, .admin-nav-popper.el-menu--popup-container) {
--nav-arrow-width: 13px;
--nav-arrow-gap: 8px;
--nav-row-end: var(--el-menu-base-level-padding);
.admin-nav-link { display: block; }
.menu-name {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.menu-item-icon {
display: inline-flex;
align-items: center;
justify-content: center;
flex: none;
width: 20px;
height: 20px;
margin-right: 8px;
&.admin-nav-icon--empty { width: 0; }
}
.el-sub-menu > .el-sub-menu__title {
padding-right: calc(var(--nav-row-end) + var(--nav-arrow-width) + var(--nav-arrow-gap));
// Element's width: inherit otherwise copies the *row* width onto
// this absolutely positioned icon. Leave its native rotation intact.
> .el-sub-menu__icon-arrow {
position: absolute;
right: var(--nav-row-end);
top: 50%;
width: var(--nav-arrow-width);
height: var(--nav-arrow-width);
margin: calc(var(--nav-arrow-width) / -2) 0 0;
font-size: var(--nav-arrow-width);
pointer-events: none;
}
}
}
.side .menu.admin-nav-tree {
// Element supplies --el-menu-level at each actual submenu; text-only
// rows keep Art's empty icon wrapper margin, not an invented glyph.
.el-menu--vertical:not(.el-menu--collapse) {
--el-menu-base-level-padding: 20px;
--el-menu-level-padding: 20px;
}
.el-menu--collapse {
> .el-sub-menu > .el-sub-menu__title,
> .admin-nav-link > .el-menu-item > .el-menu-tooltip__trigger {
padding: 0;
justify-content: center;
> .menu-item-icon { margin: 0; }
// Keep even a custom top-level route without an icon identifiable.
> .admin-nav-icon--empty {
width: 20px;
font: 500 14px/1 var(--el-font-family);
&::before { content: attr(data-initial); }
}
}
}
}
// The first flyout lives under body; deeper flyouts may live in that popper.
// Space the direct entries, not the li inside each router-link.
.admin-nav-popper.el-menu--popup-container > .el-menu--popup {
width: max-content;
min-width: min(200px, calc(100vw - 32px));
max-width: min(320px, calc(100vw - 32px));
padding: 8px;
background: var(--zyt-nav-bg);
> :not(:last-child) { margin-bottom: 5px; }
.el-menu-item, .el-sub-menu__title {
height: 40px;
line-height: 40px;
margin: 0;
border: 0;
border-radius: 6px;
color: var(--zyt-nav-text);
}
.menu-item-icon { margin: 0 5px 0 0; color: var(--zyt-nav-icon); }
.el-menu-item:hover, .el-sub-menu__title:hover, .el-menu-item.is-active {
color: var(--art-gray-900);
background: var(--art-gray-200);
}
}
&.dark .admin-nav-popper.el-menu--popup-container > .el-menu--popup .el-menu-item.is-active {
background: #292a2e;
}
}
+1
View File
@@ -4,3 +4,4 @@
@import 'tailwind.css';
@import 'public.scss';
@import 'admin-v2.scss';
@import 'admin-nav-tree.scss';