Files
filecodebox/src/components/common/SentRecordDetailModal.vue
T
orion cd06a5580e 🐛 修复详情披露与滚动锁所有权
修复记录详情中的渐进式二维码与 wget 展示,并确保详情切换时重置披露状态。为滚动锁引入按所有者释放机制,避免重复或错误释放解锁仍打开的抽屉。

- 二维码和 wget 命令默认折叠,改为可操作的显示控件
- 详情关闭按钮保持 44px 触控目标,嵌套对话框 Escape 不穿透
- 增加 scrollLock mocked document 回归测试
- 已通过类型检查、架构检查、生产构建和 Node 测试
2026-09-11 08:55:28 +08:00

274 lines
11 KiB
Vue

<template>
<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
class="w-full max-w-2xl overflow-hidden rounded-[24px] shadow-2xl transform transition-all duration-200 ease-out sm:rounded-[30px]"
:class="[isDarkMode ? 'bg-gray-900 bg-opacity-70' : 'bg-white bg-opacity-95']"
>
<div
class="border-b px-3 py-3 sm:px-6 sm:py-4"
:class="[isDarkMode ? 'border-gray-800' : 'border-gray-100']"
>
<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
type="button"
aria-label="关闭文件详情"
@click="emit('close')"
class="min-h-11 min-w-11 rounded-[30px] p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-gray-800 sm:p-2"
>
<XIcon
class="w-4 h-4 sm:w-5 sm:h-5"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
/>
</button>
</div>
</div>
<div class="p-3 sm:p-5 lg:p-6">
<div
class="mb-3 rounded-[20px] p-3 sm:mb-5 sm:rounded-[24px] sm:p-4"
:class="[isDarkMode ? 'bg-gray-800 bg-opacity-50' : 'bg-gray-50 bg-opacity-95']"
>
<div class="flex items-center mb-3 sm:mb-4">
<div class="rounded-[20px] p-2 sm:rounded-[24px] sm:p-3" :class="[isDarkMode ? 'bg-gray-800' : 'bg-white']">
<FileIcon
class="w-5 h-5 sm:w-6 sm:h-6"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
</div>
<div class="ml-3 sm:ml-4 min-w-0 flex-1">
<h4
class="font-medium text-sm sm:text-base break-words"
:title="record.filename"
:class="[isDarkMode ? 'text-white' : 'text-gray-900']"
>
{{ record.filename }}
</h4>
<p
class="text-xs sm:text-sm truncate"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
>
{{ record.size }} · {{ record.date }}
</p>
</div>
</div>
<div class="grid grid-cols-2 gap-3 sm:gap-4">
<div class="flex items-center min-w-0">
<ClockIcon
class="w-3.5 h-3.5 sm:w-4 sm:h-4 mr-1.5 sm:mr-2 flex-shrink-0"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
/>
<span
class="text-xs sm:text-sm truncate"
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']"
>
{{ record.expiration }}
</span>
</div>
<div class="flex items-center min-w-0">
<ShieldCheckIcon
class="w-3.5 h-3.5 sm:w-4 sm:h-4 mr-1.5 sm:mr-2 flex-shrink-0"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
/>
<span
class="text-xs sm:text-sm truncate"
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']"
>
安全加密
</span>
</div>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6">
<div class="space-y-3 sm:space-y-4">
<div class="bg-gradient-to-br from-indigo-500 to-purple-600 rounded-xl p-4 sm:p-5 text-white">
<div class="flex items-center justify-between mb-3 sm:mb-4">
<h4 class="font-medium text-sm sm:text-base">取件码</h4>
<button
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>
</div>
<p class="text-2xl sm:text-3xl font-bold tracking-wider text-center break-all">
{{ record.retrieveCode }}
</p>
</div>
<div
class="rounded-xl p-3 sm:p-4"
:class="[isDarkMode ? 'bg-gray-800 bg-opacity-50' : 'bg-gray-50 bg-opacity-95']"
>
<div class="flex items-center justify-between mb-2 sm:mb-3">
<h4
class="font-medium text-sm sm:text-base flex items-center min-w-0"
:class="[isDarkMode ? 'text-white' : 'text-gray-900']"
>
<TerminalIcon class="w-4 h-4 sm:w-5 sm:h-5 mr-1.5 sm:mr-2 text-indigo-500 flex-shrink-0" />
<span class="truncate">wget下载</span>
</h4>
<button
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"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
/>
</button>
</div>
<p
v-if="!showWget"
class="text-xs sm:text-sm font-mono break-all line-clamp-2"
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']"
>
<button type="button" class="min-h-11 rounded-[30px] px-3 text-left hover:bg-gray-200 dark:hover:bg-gray-700" @click="showWget = true">显示 wget 命令</button>
</p>
<p v-else class="text-xs sm:text-sm font-mono break-all" :class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']">{{ wgetCommand }}</p>
</div>
</div>
<div
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']"
>
<button
type="button"
class="bg-white p-3 sm:p-4 rounded-lg shadow-sm mb-3 sm:mb-4"
aria-label="取件二维码"
@click="showQr = !showQr"
>
<span v-if="!showQr" class="flex h-[140px] w-[140px] items-center justify-center text-sm text-gray-500 sm:h-[160px] sm:w-[160px]">显示二维码</span>
<QRCode v-else :value="qrValue" :size="140" level="M" class="sm:w-[160px] sm:h-[160px]" />
</button>
<p
class="text-xs sm:text-sm truncate max-w-full"
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
>
扫描二维码快速取件
</p>
</div>
</div>
</div>
<div
class="px-4 sm:px-6 py-3 sm:py-4 border-t"
:class="[isDarkMode ? 'border-gray-800' : 'border-gray-100']"
>
<button
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>
</div>
</div>
</div>
</transition>
</template>
<script setup lang="ts">
import { computed, defineAsyncComponent, inject, nextTick, onBeforeUnmount, ref, watch } from 'vue'
import {
ClipboardCopyIcon,
ClockIcon,
FileIcon,
ShieldCheckIcon,
TerminalIcon,
XIcon
} from 'lucide-vue-next'
import { useI18n } from 'vue-i18n'
import type { SentFileRecord } from '@/types'
import { buildAbsoluteUrl } from '@/utils/share-url'
import { lockBodyScroll, unlockBodyScroll } from './scrollLock'
const props = defineProps<{
record: SentFileRecord | null
getQRCodeValue: (record: SentFileRecord) => string
}>()
const emit = defineEmits<{
close: []
'copy-code': [record: SentFileRecord]
'copy-link': [record: SentFileRecord]
'copy-wget': [record: SentFileRecord]
}>()
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
let scrollLockOwner: ReturnType<typeof lockBodyScroll> | null = null
const showQr = ref(false)
const showWget = ref(false)
const wgetCommand = computed(() => `wget ${buildAbsoluteUrl(`/share/select?code=${props.record?.retrieveCode ?? ''}`)} -O "${props.record?.filename ?? ''}"`)
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 (scrollLockOwner) {
unlockBodyScroll(scrollLockOwner)
scrollLockOwner = null
}
showQr.value = false
showWget.value = false
if (record) {
returnFocusElement = document.activeElement instanceof HTMLElement ? document.activeElement : null
scrollLockOwner = lockBodyScroll(); await nextTick(); modalRef.value?.focus()
} else {
await nextTick(); returnFocusElement?.focus(); returnFocusElement = null
}
}, { immediate: true })
onBeforeUnmount(() => { unlockBodyScroll(scrollLockOwner); scrollLockOwner = null; returnFocusElement = null })
</script>
<style scoped>
.fade-enter-active,
.fade-leave-active {
transition:
opacity 0.3s ease,
transform 0.3s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: translateY(10px);
}
</style>