✨ 优化发送记录详情无障碍与抽屉滚动锁
提升发送记录详情在移动端和键盘操作下的可用性,并避免抽屉或详情弹层打开时背景页面滚动。 - 增加详情弹层的焦点管理、Tab 循环、Escape 关闭与焦点返回 - 保留长文件名完整可见,强化复制按钮与关闭按钮的无障碍标签和触控尺寸 - 提取支持嵌套计数与卸载恢复的 body 滚动锁,应用于详情弹层和侧边抽屉 - 已完成 git diff --check;类型检查因依赖未安装而无法运行
This commit is contained in:
1 parent
c2f0bf1675
commit
5ffee48d80
3 files changed
+80
-14
No files matched your search
@@ -2,6 +2,12 @@
|
|||||||
<transition name="fade">
|
<transition name="fade">
|
||||||
<div
|
<div
|
||||||
v-if="record"
|
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"
|
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
|
<div
|
||||||
@@ -14,13 +20,16 @@
|
|||||||
>
|
>
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<h3
|
<h3
|
||||||
|
:id="modalTitleId"
|
||||||
class="text-base font-semibold sm:text-xl"
|
class="text-base font-semibold sm:text-xl"
|
||||||
:class="[isDarkMode ? 'text-white' : 'text-gray-900']"
|
:class="[isDarkMode ? 'text-white' : 'text-gray-900']"
|
||||||
>
|
>
|
||||||
{{ t('send.fileDetails') }}
|
{{ t('send.fileDetails') }}
|
||||||
</h3>
|
</h3>
|
||||||
<button
|
<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"
|
class="rounded-[30px] p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-gray-800 sm:p-2"
|
||||||
>
|
>
|
||||||
<XIcon
|
<XIcon
|
||||||
@@ -45,7 +54,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ml-3 sm:ml-4 min-w-0 flex-1">
|
<div class="ml-3 sm:ml-4 min-w-0 flex-1">
|
||||||
<h4
|
<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']"
|
:class="[isDarkMode ? 'text-white' : 'text-gray-900']"
|
||||||
>
|
>
|
||||||
{{ record.filename }}
|
{{ record.filename }}
|
||||||
@@ -92,8 +102,10 @@
|
|||||||
<div class="flex items-center justify-between mb-3 sm:mb-4">
|
<div class="flex items-center justify-between mb-3 sm:mb-4">
|
||||||
<h4 class="font-medium text-sm sm:text-base">取件码</h4>
|
<h4 class="font-medium text-sm sm:text-base">取件码</h4>
|
||||||
<button
|
<button
|
||||||
@click="$emit('copy-code', record)"
|
type="button"
|
||||||
class="p-1.5 sm:p-2 rounded-full hover:bg-white/10 transition-colors"
|
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" />
|
<ClipboardCopyIcon class="w-4 h-4 sm:w-5 sm:h-5" />
|
||||||
</button>
|
</button>
|
||||||
@@ -116,8 +128,10 @@
|
|||||||
<span class="truncate">wget下载</span>
|
<span class="truncate">wget下载</span>
|
||||||
</h4>
|
</h4>
|
||||||
<button
|
<button
|
||||||
@click="$emit('copy-wget', record)"
|
type="button"
|
||||||
class="p-1.5 sm:p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors flex-shrink-0"
|
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
|
<ClipboardCopyIcon
|
||||||
class="w-4 h-4 sm:w-5 sm:h-5"
|
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="text-xs sm:text-sm font-mono break-all line-clamp-2"
|
||||||
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']"
|
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']"
|
||||||
>
|
>
|
||||||
点击复制wget命令
|
点击复制 wget 命令
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -138,9 +152,13 @@
|
|||||||
class="rounded-xl p-4 sm:p-5 flex flex-col items-center"
|
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']"
|
: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]" />
|
<QRCode :value="qrValue" :size="140" level="M" class="sm:w-[160px] sm:h-[160px]" />
|
||||||
</div>
|
</button>
|
||||||
<p
|
<p
|
||||||
class="text-xs sm:text-sm truncate max-w-full"
|
class="text-xs sm:text-sm truncate max-w-full"
|
||||||
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
|
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
|
||||||
@@ -156,8 +174,9 @@
|
|||||||
:class="[isDarkMode ? 'border-gray-800' : 'border-gray-100']"
|
:class="[isDarkMode ? 'border-gray-800' : 'border-gray-100']"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@click="$emit('copy-link', record)"
|
type="button"
|
||||||
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"
|
@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>
|
</button>
|
||||||
@@ -168,7 +187,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, defineAsyncComponent, inject } from 'vue'
|
import { computed, defineAsyncComponent, inject, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
||||||
import {
|
import {
|
||||||
ClipboardCopyIcon,
|
ClipboardCopyIcon,
|
||||||
ClockIcon,
|
ClockIcon,
|
||||||
@@ -180,13 +199,14 @@ import {
|
|||||||
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import type { SentFileRecord } from '@/types'
|
import type { SentFileRecord } from '@/types'
|
||||||
|
import { lockBodyScroll, unlockBodyScroll } from './scrollLock'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
record: SentFileRecord | null
|
record: SentFileRecord | null
|
||||||
getQRCodeValue: (record: SentFileRecord) => string
|
getQRCodeValue: (record: SentFileRecord) => string
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
defineEmits<{
|
const emit = defineEmits<{
|
||||||
close: []
|
close: []
|
||||||
'copy-code': [record: SentFileRecord]
|
'copy-code': [record: SentFileRecord]
|
||||||
'copy-link': [record: SentFileRecord]
|
'copy-link': [record: SentFileRecord]
|
||||||
@@ -197,6 +217,29 @@ const { t } = useI18n()
|
|||||||
const isDarkMode = inject('isDarkMode')
|
const isDarkMode = inject('isDarkMode')
|
||||||
const QRCode = defineAsyncComponent(() => import('qrcode.vue'))
|
const QRCode = defineAsyncComponent(() => import('qrcode.vue'))
|
||||||
const qrValue = computed(() => (props.record ? props.getQRCodeValue(props.record) : ''))
|
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>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -46,9 +46,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { inject, nextTick, ref, watch } from 'vue'
|
import { inject, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
||||||
import { XIcon } from 'lucide-vue-next'
|
import { XIcon } from 'lucide-vue-next'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import { lockBodyScroll, unlockBodyScroll } from './scrollLock'
|
||||||
|
|
||||||
const props = defineProps<{ visible: boolean; title: string }>()
|
const props = defineProps<{ visible: boolean; title: string }>()
|
||||||
const emit = defineEmits<{ close: [] }>()
|
const emit = defineEmits<{ close: [] }>()
|
||||||
@@ -83,17 +84,20 @@ watch(
|
|||||||
() => props.visible,
|
() => props.visible,
|
||||||
async (visible) => {
|
async (visible) => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
|
lockBodyScroll()
|
||||||
returnFocusElement = document.activeElement instanceof HTMLElement ? document.activeElement : null
|
returnFocusElement = document.activeElement instanceof HTMLElement ? document.activeElement : null
|
||||||
await nextTick()
|
await nextTick()
|
||||||
const first = drawerRef.value?.querySelector<HTMLElement>(focusableSelector)
|
const first = drawerRef.value?.querySelector<HTMLElement>(focusableSelector)
|
||||||
;(first || drawerRef.value)?.focus()
|
;(first || drawerRef.value)?.focus()
|
||||||
} else {
|
} else {
|
||||||
|
unlockBodyScroll()
|
||||||
await nextTick()
|
await nextTick()
|
||||||
returnFocusElement?.focus()
|
returnFocusElement?.focus()
|
||||||
returnFocusElement = null
|
returnFocusElement = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
onBeforeUnmount(() => unlockBodyScroll())
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
let lockCount = 0
|
||||||
|
let previousOverflow = ''
|
||||||
|
|
||||||
|
export function lockBodyScroll(): void {
|
||||||
|
if (lockCount === 0) {
|
||||||
|
previousOverflow = document.body.style.overflow
|
||||||
|
document.body.style.overflow = 'hidden'
|
||||||
|
}
|
||||||
|
lockCount += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unlockBodyScroll(): void {
|
||||||
|
if (lockCount === 0) return
|
||||||
|
lockCount -= 1
|
||||||
|
if (lockCount === 0) {
|
||||||
|
document.body.style.overflow = previousOverflow
|
||||||
|
previousOverflow = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user