feat(admin): 优化窄屏工作标签及键盘导航

This commit is contained in:
2026-12-01 18:19:18 +08:00
parent bfaf51796d
commit 878376a7fc
4 changed files with 283 additions and 29 deletions
@@ -1,25 +1,28 @@
<template>
<div class="app-tabs pl-4 flex bg-body">
<div class="flex-1 min-w-0">
<div class="app-tabs pl-4 flex bg-body" :class="{ 'work-tabs--art': art }">
<div class="work-tabs__lane flex-1 min-w-0">
<el-tabs
:model-value="currentTab"
:closable="tabsLists.length > 1"
@tab-change="handleChange"
@tab-remove="removeTab($event)"
@tab-remove="closeTab"
>
<template v-for="item in tabsLists" :key="item.fullPath">
<el-tab-pane :label="item.title" :name="item.fullPath"></el-tab-pane>
</template>
<el-tab-pane v-for="item in tabsLists" :key="item.fullPath" :name="item.fullPath" :label="item.title">
<template #label>
<span class="work-tabs__label" :title="item.title">{{ item.title }}</span>
</template>
</el-tab-pane>
</el-tabs>
</div>
<el-dropdown @command="handleCommand">
<span class="flex items-center px-3">
<icon :size="16" name="el-icon-arrow-down" />
</span>
<el-dropdown ref="actionsMenu" class="work-tabs__actions" :trigger="art ? 'click' : 'hover'" @command="handleCommand">
<button ref="actionsButton" class="work-tabs__trigger flex items-center px-3" type="button"
aria-label="标签页操作" title="标签页操作" @keydown.esc.stop.prevent="dismissActions">
<icon :size="art ? 20 : 16" name="el-icon-arrow-down" />
</button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="closeCurrent"> 关闭当前 </el-dropdown-item>
<el-dropdown-item command="closeOther"> 关闭其他 </el-dropdown-item>
<el-dropdown-menu @keydown.esc.capture.stop.prevent="dismissActions">
<el-dropdown-item command="closeCurrent" :disabled="!canCloseCurrent">关闭当前</el-dropdown-item>
<el-dropdown-item command="closeOther" :disabled="!canCloseCurrent">关闭其他</el-dropdown-item>
<el-dropdown-item command="closeAll"> 关闭全部 </el-dropdown-item>
</el-dropdown-menu>
</template>
@@ -28,29 +31,48 @@
</template>
<script setup lang="ts">
import type { DropdownInstance } from 'element-plus'
import useMultipleTabs from '@/hooks/useMultipleTabs'
import { useWatchRoute } from '@/hooks/useWatchRoute'
import useTabsStore, { getRouteParams } from '@/stores/modules/multipleTabs'
import { getRouteParams } from '@/stores/modules/multipleTabs'
import useSettingStore from '@/stores/modules/setting'
const router = useRouter()
const tabsStore = useTabsStore()
const settings = useSettingStore()
const actionsMenu = ref<DropdownInstance>()
const actionsButton = ref<HTMLButtonElement>()
const dismissActions = () => {
actionsMenu.value?.handleClose()
actionsButton.value?.focus()
}
const art = computed(() => settings.adminUi === 'v2')
const { removeOtherTab, addTab, removeAllTab, removeTab, tabsLists, currentTab } = useMultipleTabs()
useWatchRoute(() => {
addTab()
})
const handleChange = (fullPath: any) => {
const tabItem = tabsStore.tasMap[fullPath]
router.push(getRouteParams(tabItem))
const canCloseCurrent = computed(() =>
tabsLists.value.length > 1 && tabsLists.value.some(tab => tab.fullPath === currentTab.value)
)
const handleChange = (fullPath: string | number) => {
// Removal or a route refresh may notify ElTabs after the pane disappeared.
if (fullPath === currentTab.value) return
const tab = tabsLists.value.find(item => item.fullPath === fullPath)
if (tab) router.push(getRouteParams(tab))
}
const closeTab = (fullPath: string | number) => {
if (tabsLists.value.length > 1 && tabsLists.value.some(item => item.fullPath === fullPath)) {
removeTab(fullPath)
}
}
const handleCommand = (command: any) => {
const handleCommand = (command: string) => {
switch (command) {
case 'closeCurrent':
removeTab()
if (canCloseCurrent.value) removeTab()
break
case 'closeOther':
removeOtherTab()
if (canCloseCurrent.value) removeOtherTab()
break
case 'closeAll':
removeAllTab()
@@ -121,4 +143,53 @@ const handleCommand = (command: any) => {
}
}
}
// ArtWorkTab separates its scrolling 32px chips from a fixed 32px action
// button. Keep Element's tablist, scroll arrows, Delete key and roving focus.
.app-tabs.work-tabs--art {
min-width: 0;
align-items: flex-start;
column-gap: 6px;
.work-tabs__lane { container-type: inline-size; }
.work-tabs__label {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
:deep(.el-tabs__item) {
max-width: min(220px, 50vw);
// Leave room for Element's two scroll arrows even on a narrow lane.
max-width: min(220px, calc(100cqi - 52px));
padding: 0 10px !important;
&.is-closable { padding-inline: 12px 8px !important; }
&:focus-visible { outline: 2px solid var(--zyt-primary); outline-offset: -2px; }
.is-icon-close {
flex: 0 0 18px;
width: 18px;
height: 18px;
margin-left: 2px;
font-size: 10px;
color: var(--art-gray-600);
&:hover { background: var(--zyt-hover); color: var(--zyt-ink); }
}
}
.work-tabs__actions { flex: none; }
.work-tabs__trigger {
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
padding: 0;
border: 1px solid var(--zyt-card-border);
border-radius: calc(var(--zyt-radius) / 2.5);
background: var(--zyt-surface);
color: var(--art-gray-700);
cursor: pointer;
&:hover { background: var(--zyt-hover); }
&:focus-visible { outline: 2px solid var(--zyt-primary); outline-offset: -2px; }
}
}
</style>
+2 -8
View File
@@ -55,14 +55,8 @@ const getComponentName = (route: RouteLocationNormalized) => {
return route.matched.at(-1)?.components?.default?.name
}
export const getRouteParams = (tabItem: TabItem) => {
const { params, path, query } = tabItem
return {
params: params || {},
path,
query: query || {}
}
}
// fullPath already includes resolved dynamic params, encoded query, and fragment.
export const getRouteParams = (tabItem: TabItem) => tabItem.fullPath
const useTabsStore = defineStore({
id: 'tabs',