fix(admin): unify sidebar collapse motion

This commit is contained in:
2026-07-24 00:42:34 +08:00
parent 3aed4005f7
commit 3dc456e22c
+75 -55
View File
@@ -125,6 +125,7 @@ const filteredImages = computed(() => {
const selectedManagedCount = computed(() => selectedImageIds.value.size) const selectedManagedCount = computed(() => selectedImageIds.value.size)
const displayUsername = computed(() => authStore.profile?.username || authStore.user?.email || '管理员') const displayUsername = computed(() => authStore.profile?.username || authStore.user?.email || '管理员')
const userEmail = computed(() => authStore.user?.email || '未绑定邮箱') const userEmail = computed(() => authStore.user?.email || '未绑定邮箱')
const displayInitial = computed(() => displayUsername.value.slice(0, 1).toUpperCase())
watch(imageFilter, () => { watch(imageFilter, () => {
setSelectedImageIds([]) setSelectedImageIds([])
@@ -491,56 +492,54 @@ onMounted(loadAdminData)
<template> <template>
<div class="min-h-screen bg-[linear-gradient(180deg,#f8fafc_0%,#eef6ff_55%,#f8fafc_100%)]"> <div class="min-h-screen bg-[linear-gradient(180deg,#f8fafc_0%,#eef6ff_55%,#f8fafc_100%)]">
<div <div
class="min-h-screen w-full transition-[grid-template-columns] duration-200 lg:grid" class="min-h-screen w-full transition-[grid-template-columns] duration-200 ease-out lg:grid"
:class="sidebarCollapsed :class="sidebarCollapsed
? 'lg:grid-cols-[88px_minmax(0,1fr)]' ? 'lg:grid-cols-[88px_minmax(0,1fr)]'
: 'lg:grid-cols-[280px_minmax(0,1fr)]'" : 'lg:grid-cols-[280px_minmax(0,1fr)]'"
> >
<aside <aside
class="border-b border-slate-200 bg-white/90 px-4 py-4 backdrop-blur lg:sticky lg:top-0 lg:flex lg:h-screen lg:flex-col lg:border-b-0 lg:border-r lg:py-5" class="relative border-b border-slate-200 bg-white/90 px-4 py-4 backdrop-blur lg:sticky lg:top-0 lg:flex lg:h-screen lg:flex-col lg:border-b-0 lg:border-r lg:px-5 lg:py-5"
:class="sidebarCollapsed ? 'lg:px-3' : 'lg:px-5'"
> >
<div <div class="flex items-center">
class="flex items-start justify-between gap-3"
:class="sidebarCollapsed ? 'lg:flex-col lg:items-center' : 'lg:items-center'"
>
<div class="flex min-w-0 items-center gap-3"> <div class="flex min-w-0 items-center gap-3">
<span class="flex h-10 w-10 shrink-0 items-center justify-center border border-sky-200 bg-sky-50 text-sky-800 shadow-[3px_3px_0_0_rgba(14,165,233,0.12)]"> <span class="flex h-10 w-10 shrink-0 items-center justify-center border border-sky-200 bg-sky-50 text-sky-800 shadow-[3px_3px_0_0_rgba(14,165,233,0.12)]">
<NIcon size="22"><Shield /></NIcon> <NIcon size="22"><Shield /></NIcon>
</span> </span>
<span class="min-w-0" :class="sidebarCollapsed ? 'lg:hidden' : ''"> <span
<span class="block text-xs font-semibold uppercase tracking-[0.2em] text-sky-700">Admin Console</span> class="min-w-0 overflow-hidden whitespace-nowrap transition-[max-width,opacity] duration-200 ease-out"
<span class="mt-1 block truncate text-lg font-bold text-slate-950">管理工作台</span> :class="sidebarCollapsed
? 'lg:max-w-0 lg:opacity-0'
: 'lg:max-w-[168px] lg:opacity-100'"
>
<span class="block whitespace-nowrap text-xs font-semibold uppercase tracking-[0.2em] text-sky-700">Admin Console</span>
<span class="mt-1 block whitespace-nowrap text-lg font-bold text-slate-950">管理工作台</span>
</span> </span>
</div> </div>
<button
type="button"
class="hidden h-9 w-9 shrink-0 items-center justify-center border border-slate-200 bg-white text-slate-500 transition-colors hover:border-teal-200 hover:bg-teal-50 hover:text-teal-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-teal-600 lg:flex"
:aria-label="sidebarCollapsed ? '展开侧边栏' : '折叠侧边栏'"
:aria-expanded="!sidebarCollapsed"
:title="sidebarCollapsed ? '展开侧边栏' : '折叠侧边栏'"
@click="toggleSidebar"
>
<NIcon size="20">
<LayoutSidebarLeftExpand v-if="sidebarCollapsed" />
<LayoutSidebarLeftCollapse v-else />
</NIcon>
</button>
</div> </div>
<button
type="button"
class="hidden h-8 w-8 items-center justify-center border border-slate-200 bg-white text-slate-500 shadow-[3px_3px_0_0_rgba(15,23,42,0.06)] transition-colors hover:border-teal-200 hover:bg-teal-50 hover:text-teal-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-teal-600 lg:absolute lg:-right-4 lg:top-6 lg:z-20 lg:flex"
:aria-label="sidebarCollapsed ? '展开侧边栏' : '折叠侧边栏'"
:aria-expanded="!sidebarCollapsed"
:title="sidebarCollapsed ? '展开侧边栏' : '折叠侧边栏'"
@click="toggleSidebar"
>
<NIcon size="18">
<LayoutSidebarLeftExpand v-if="sidebarCollapsed" />
<LayoutSidebarLeftCollapse v-else />
</NIcon>
</button>
<nav aria-label="后台管理分区" class="mt-4 flex gap-2 overflow-x-auto pb-1 lg:mt-7 lg:block lg:space-y-2 lg:overflow-visible lg:pb-0"> <nav aria-label="后台管理分区" class="mt-4 flex gap-2 overflow-x-auto pb-1 lg:mt-7 lg:block lg:space-y-2 lg:overflow-visible lg:pb-0">
<button <button
v-for="tab in tabs" v-for="tab in tabs"
:key="tab.key" :key="tab.key"
type="button" type="button"
class="group relative flex min-w-[150px] items-center gap-3 border px-3 py-3 text-left transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-teal-600 focus-visible:ring-offset-2 lg:w-full lg:min-w-0" class="group relative flex min-w-[150px] items-center gap-3 overflow-hidden border px-3 py-3 text-left transition-[background-color,border-color,color,box-shadow] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-teal-600 focus-visible:ring-offset-2 lg:w-full lg:min-w-0"
:class="[ :class="activeTab === tab.key
activeTab === tab.key ? 'border-teal-200 bg-teal-50 text-teal-900 shadow-[3px_3px_0_0_rgba(20,184,166,0.14)]'
? 'border-teal-200 bg-teal-50 text-teal-900 shadow-[3px_3px_0_0_rgba(20,184,166,0.14)]' : 'border-transparent bg-white text-slate-600 hover:border-slate-200 hover:bg-slate-50 hover:text-slate-950'"
: 'border-transparent bg-white text-slate-600 hover:border-slate-200 hover:bg-slate-50 hover:text-slate-950',
sidebarCollapsed ? 'lg:justify-center lg:px-0' : '',
]"
:aria-current="activeTab === tab.key ? 'page' : undefined" :aria-current="activeTab === tab.key ? 'page' : undefined"
:aria-label="tab.label" :aria-label="tab.label"
:title="sidebarCollapsed ? tab.label : undefined" :title="sidebarCollapsed ? tab.label : undefined"
@@ -549,8 +548,13 @@ onMounted(loadAdminData)
<NIcon size="22" class="shrink-0"> <NIcon size="22" class="shrink-0">
<component :is="tab.icon" /> <component :is="tab.icon" />
</NIcon> </NIcon>
<span class="min-w-0 flex-1" :class="sidebarCollapsed ? 'lg:hidden' : ''"> <span
<span class="block text-sm font-semibold">{{ tab.label }}</span> class="min-w-0 flex-1 overflow-hidden whitespace-nowrap transition-[max-width,opacity] duration-200 ease-out"
:class="sidebarCollapsed
? 'lg:max-w-0 lg:opacity-0'
: 'lg:max-w-[190px] lg:opacity-100'"
>
<span class="block whitespace-nowrap text-sm font-semibold">{{ tab.label }}</span>
<span class="mt-0.5 hidden truncate text-xs text-slate-500 lg:block">{{ tab.description }}</span> <span class="mt-0.5 hidden truncate text-xs text-slate-500 lg:block">{{ tab.description }}</span>
</span> </span>
<span <span
@@ -574,31 +578,35 @@ onMounted(loadAdminData)
<template #trigger> <template #trigger>
<button <button
type="button" type="button"
class="flex min-h-[46px] min-w-0 flex-1 items-center gap-3 border px-3 py-2 text-left transition-[background-color,border-color,color,box-shadow] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-teal-600 lg:w-full" class="flex h-14 min-w-0 flex-1 items-center gap-3 overflow-hidden border px-3 py-2 text-left transition-[background-color,border-color,color,box-shadow] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-teal-600 lg:w-full"
:class="[ :class="accountMenuOpen
accountMenuOpen ? 'border-teal-200 bg-teal-50 text-teal-800 shadow-[3px_3px_0_0_rgba(20,184,166,0.12)]'
? 'border-teal-200 bg-teal-50 text-teal-800 shadow-[3px_3px_0_0_rgba(20,184,166,0.12)]' : 'border-slate-200 bg-slate-50 text-slate-700 hover:border-teal-200 hover:bg-teal-50 hover:text-teal-800'"
: 'border-slate-200 bg-slate-50 text-slate-700 hover:border-teal-200 hover:bg-teal-50 hover:text-teal-800',
sidebarCollapsed ? 'lg:justify-center lg:px-0' : '',
]"
aria-label="打开管理员账户菜单" aria-label="打开管理员账户菜单"
aria-haspopup="menu" aria-haspopup="menu"
:aria-expanded="accountMenuOpen" :aria-expanded="accountMenuOpen"
:title="sidebarCollapsed ? displayUsername : undefined" :title="sidebarCollapsed ? displayUsername : undefined"
> >
<NIcon size="22" class="shrink-0"><UserCircle /></NIcon> <NIcon size="22" class="shrink-0"><UserCircle /></NIcon>
<span class="min-w-0 flex-1" :class="sidebarCollapsed ? 'lg:hidden' : ''"> <span
class="min-w-0 flex-1 overflow-hidden whitespace-nowrap transition-[max-width,opacity] duration-200 ease-out"
:class="sidebarCollapsed
? 'lg:max-w-0 lg:opacity-0'
: 'lg:max-w-[145px] lg:opacity-100'"
>
<span class="block truncate text-sm font-semibold text-slate-900">{{ displayUsername }}</span> <span class="block truncate text-sm font-semibold text-slate-900">{{ displayUsername }}</span>
<span class="mt-0.5 block text-xs text-slate-500">管理员账户</span> <span class="mt-0.5 block text-xs text-slate-500">管理员账户</span>
</span> </span>
<NIcon <span
v-if="!sidebarCollapsed" class="overflow-hidden transition-[max-width,opacity] duration-200 ease-out"
size="16" :class="sidebarCollapsed
class="shrink-0 transition-transform" ? 'lg:max-w-0 lg:opacity-0'
:class="accountMenuOpen ? 'rotate-180' : ''" : 'lg:max-w-4 lg:opacity-100'"
> >
<ChevronUp /> <NIcon size="16" class="shrink-0 transition-transform" :class="accountMenuOpen ? 'rotate-180' : ''">
</NIcon> <ChevronUp />
</NIcon>
</span>
</button> </button>
</template> </template>
@@ -607,10 +615,16 @@ onMounted(loadAdminData)
role="menu" role="menu"
aria-label="管理员账户" aria-label="管理员账户"
> >
<div class="border-b border-slate-200 bg-[linear-gradient(180deg,#f0fdfa_0%,#ffffff_100%)] px-4 py-3"> <div class="border-b border-slate-200 bg-[linear-gradient(180deg,#f0fdfa_0%,#ffffff_100%)] px-4 py-4">
<p class="text-[11px] font-semibold uppercase tracking-[0.18em] text-teal-700">Administrator</p> <div class="flex items-center gap-3">
<p class="mt-2 truncate text-sm font-semibold text-slate-950">@{{ displayUsername }}</p> <div class="flex h-11 w-11 shrink-0 items-center justify-center border border-teal-200 bg-[linear-gradient(135deg,#ecfeff_0%,#ccfbf1_100%)] text-lg font-bold text-teal-800">
<p class="mt-1 truncate text-xs text-slate-500">{{ userEmail }}</p> {{ displayInitial }}
</div>
<div class="min-w-0">
<p class="truncate text-sm font-semibold text-slate-950">@{{ displayUsername }}</p>
<p class="mt-1 truncate text-xs text-slate-500">{{ userEmail }}</p>
</div>
</div>
</div> </div>
<div class="py-2"> <div class="py-2">
@@ -649,12 +663,18 @@ onMounted(loadAdminData)
</NPopover> </NPopover>
<RouterLink <RouterLink
to="/" to="/"
class="flex h-[46px] shrink-0 items-center justify-center gap-3 border border-slate-200 bg-white px-3 text-sm font-semibold text-slate-700 shadow-[3px_3px_0_0_rgba(15,23,42,0.06)] transition-colors hover:border-sky-200 hover:bg-sky-50 hover:text-sky-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600" class="flex h-[46px] shrink-0 items-center justify-start gap-3 overflow-hidden border border-slate-200 bg-white px-3 text-sm font-semibold text-slate-700 shadow-[3px_3px_0_0_rgba(15,23,42,0.06)] transition-colors hover:border-sky-200 hover:bg-sky-50 hover:text-sky-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600 lg:w-full"
:class="sidebarCollapsed ? 'lg:px-0' : 'lg:w-full'"
title="返回主页" title="返回主页"
> >
<NIcon size="20" class="shrink-0"><Home /></NIcon> <NIcon size="20" class="shrink-0"><Home /></NIcon>
<span :class="sidebarCollapsed ? 'lg:hidden' : ''">返回主页</span> <span
class="overflow-hidden whitespace-nowrap transition-[max-width,opacity] duration-200 ease-out"
:class="sidebarCollapsed
? 'lg:max-w-0 lg:opacity-0'
: 'lg:max-w-[100px] lg:opacity-100'"
>
返回主页
</span>
</RouterLink> </RouterLink>
</div> </div>
</aside> </aside>