✨ 优化发送记录详情无障碍与抽屉滚动锁

提升发送记录详情在移动端和键盘操作下的可用性,并避免抽屉或详情弹层打开时背景页面滚动。

- 增加详情弹层的焦点管理、Tab 循环、Escape 关闭与焦点返回
- 保留长文件名完整可见,强化复制按钮与关闭按钮的无障碍标签和触控尺寸
- 提取支持嵌套计数与卸载恢复的 body 滚动锁,应用于详情弹层和侧边抽屉
- 已完成 git diff --check;类型检查因依赖未安装而无法运行
This commit is contained in:
orion committed 2026-09-11 08:48:22 +08:00
1 parent c2f0bf1675
commit 5ffee48d80
3 files changed
+80 -14

No files matched your search

+56 -13
View File
@@ -2,6 +2,12 @@
<transition name="fade">
<div
v-if="record"
ref="modalRef"
role="dialog"
aria-modal="true"
:aria-labelledby="modalTitleId"
tabindex="-1"
@keydown="handleKeydown"
class="fixed inset-0 z-50 flex items-center justify-center overflow-y-auto bg-black/60 p-3 backdrop-blur-sm sm:p-4"
>
<div
@@ -14,13 +20,16 @@
>
<div class="flex items-center justify-between">
<h3
:id="modalTitleId"
class="text-base font-semibold sm:text-xl"
:class="[isDarkMode ? 'text-white' : 'text-gray-900']"
>
{{ t('send.fileDetails') }}
</h3>
<button
@click="$emit('close')"
type="button"
aria-label="关闭文件详情"
@click="emit('close')"
class="rounded-[30px] p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-gray-800 sm:p-2"
>
<XIcon
@@ -45,7 +54,8 @@
</div>
<div class="ml-3 sm:ml-4 min-w-0 flex-1">
<h4
class="font-medium text-sm sm:text-base truncate"
class="font-medium text-sm sm:text-base break-words"
:title="record.filename"
:class="[isDarkMode ? 'text-white' : 'text-gray-900']"
>
{{ record.filename }}
@@ -92,8 +102,10 @@
<div class="flex items-center justify-between mb-3 sm:mb-4">
<h4 class="font-medium text-sm sm:text-base">取件码</h4>
<button
@click="$emit('copy-code', record)"
class="p-1.5 sm:p-2 rounded-full hover:bg-white/10 transition-colors"
type="button"
aria-label="复制取件码"
@click="emit('copy-code', record)"
class="min-h-11 min-w-11 p-1.5 sm:p-2 rounded-full hover:bg-white/10 transition-colors"
>
<ClipboardCopyIcon class="w-4 h-4 sm:w-5 sm:h-5" />
</button>
@@ -116,8 +128,10 @@
<span class="truncate">wget下载</span>
</h4>
<button
@click="$emit('copy-wget', record)"
class="p-1.5 sm:p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors flex-shrink-0"
type="button"
aria-label="复制 wget 命令"
@click="emit('copy-wget', record)"
class="min-h-11 min-w-11 p-1.5 sm:p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors flex-shrink-0"
>
<ClipboardCopyIcon
class="w-4 h-4 sm:w-5 sm:h-5"
@@ -129,7 +143,7 @@
class="text-xs sm:text-sm font-mono break-all line-clamp-2"
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']"
>
点击复制wget命令
点击复制 wget 命令
</p>
</div>
</div>
@@ -138,9 +152,13 @@
class="rounded-xl p-4 sm:p-5 flex flex-col items-center"
:class="[isDarkMode ? 'bg-gray-800 bg-opacity-50' : 'bg-gray-50 bg-opacity-95']"
>
<div class="bg-white p-3 sm:p-4 rounded-lg shadow-sm mb-3 sm:mb-4">
<button
type="button"
class="bg-white p-3 sm:p-4 rounded-lg shadow-sm mb-3 sm:mb-4"
aria-label="取件二维码"
>
<QRCode :value="qrValue" :size="140" level="M" class="sm:w-[160px] sm:h-[160px]" />
</div>
</button>
<p
class="text-xs sm:text-sm truncate max-w-full"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
@@ -156,8 +174,9 @@
:class="[isDarkMode ? 'border-gray-800' : 'border-gray-100']"
>
<button
@click="$emit('copy-link', record)"
class="w-full bg-indigo-600 hover:bg-indigo-700 text-white px-4 sm:px-6 py-2 sm:py-3 rounded-lg text-sm sm:text-base font-medium transition-colors"
type="button"
@click="emit('copy-link', record)"
class="min-h-11 w-full bg-teal-600 hover:bg-teal-700 text-white px-4 sm:px-6 py-2 sm:py-3 rounded-xl text-sm sm:text-base font-medium transition-colors"
>
复制取件链接
</button>
@@ -168,7 +187,7 @@
</template>
<script setup lang="ts">
import { computed, defineAsyncComponent, inject } from 'vue'
import { computed, defineAsyncComponent, inject, nextTick, onBeforeUnmount, ref, watch } from 'vue'
import {
ClipboardCopyIcon,
ClockIcon,
@@ -180,13 +199,14 @@ import {
import { useI18n } from 'vue-i18n'
import type { SentFileRecord } from '@/types'
import { lockBodyScroll, unlockBodyScroll } from './scrollLock'
const props = defineProps<{
record: SentFileRecord | null
getQRCodeValue: (record: SentFileRecord) => string
}>()
defineEmits<{
const emit = defineEmits<{
close: []
'copy-code': [record: SentFileRecord]
'copy-link': [record: SentFileRecord]
@@ -197,6 +217,29 @@ const { t } = useI18n()
const isDarkMode = inject('isDarkMode')
const QRCode = defineAsyncComponent(() => import('qrcode.vue'))
const qrValue = computed(() => (props.record ? props.getQRCodeValue(props.record) : ''))
const modalRef = ref<HTMLElement>()
const modalTitleId = 'sent-record-detail-title'
let returnFocusElement: HTMLElement | null = null
const focusableSelector = 'button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])'
const handleKeydown = (event: KeyboardEvent) => {
if (event.key === 'Escape') { event.preventDefault(); emit('close'); return }
if (event.key !== 'Tab' || !modalRef.value) return
const focusable = [...modalRef.value.querySelectorAll<HTMLElement>(focusableSelector)]
const first = focusable[0]; const last = focusable[focusable.length - 1]
if (first && last && ((event.shiftKey && document.activeElement === first) || (!event.shiftKey && document.activeElement === last))) {
event.preventDefault(); (event.shiftKey ? last : first).focus()
}
}
watch(() => props.record, async (record) => {
if (record) {
returnFocusElement = document.activeElement instanceof HTMLElement ? document.activeElement : null
lockBodyScroll(); await nextTick(); modalRef.value?.focus()
} else {
unlockBodyScroll(); await nextTick(); returnFocusElement?.focus(); returnFocusElement = null
}
}, { immediate: true })
onBeforeUnmount(() => { unlockBodyScroll(); returnFocusElement = null })
</script>
<style scoped>