🐛 fix(frontend): 修复上传进度与取件详情弹窗

This commit is contained in:
orion committed 2026-09-18 15:38:44 +08:00
1 parent da54bf40c9
commit 988ae2429d
5 files changed
+43 -124

No files matched your search

+22 -116
View File
@@ -1,110 +1,26 @@
<template>
<transition name="fade">
<div
v-if="visible"
class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"
@click.self="$emit('close')"
>
<div
class="fcb-surface w-full max-w-md mx-3 overflow-hidden rounded-[24px] shadow-2xl transform transition-all duration-200 ease-out backdrop-filter backdrop-blur-lg sm:mx-4 sm:rounded-[30px]"
:class="[isDarkMode ? 'bg-gray-800 bg-opacity-70' : 'bg-white bg-opacity-95']"
>
<h3
class="mb-4 truncate px-4 pt-4 text-xl font-bold sm:mb-5 sm:px-6 sm:pt-6 sm:text-2xl"
:class="[isDarkMode ? 'text-white' : 'text-gray-800']"
>
{{ t('fileDetail.title') }}
</h3>
<div class="space-y-3 px-4 sm:space-y-4 sm:px-6" v-if="record">
<div class="flex items-center">
<FileIcon
class="w-6 h-6 mr-3 flex-shrink-0"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"
class="truncate flex-grow"
>
<span class="font-medium">{{ t('fileRecord.filename') }}:</span>{{ record.filename }}
</p>
</div>
<div class="flex items-center">
<CalendarIcon
class="w-6 h-6 mr-3 flex-shrink-0"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"
class="truncate flex-grow"
>
<span class="font-medium">{{ t('fileRecord.date') }}:</span>{{ record.date }}
</p>
</div>
<div class="flex items-center">
<HardDriveIcon
class="w-6 h-6 mr-3 flex-shrink-0"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p
:class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']"
class="truncate flex-grow"
>
<span class="font-medium">{{ t('fileRecord.size') }}:</span>{{ record.size }}
</p>
</div>
<div class="flex items-center">
<DownloadIcon
class="w-6 h-6 mr-3"
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
/>
<p :class="[isDarkMode ? 'text-gray-300' : 'text-gray-800']">
<span class="font-medium">{{ t('fileDetail.content') }}:</span>
</p>
<div v-if="record.filename === 'Text'" class="ml-2">
<button
@click="$emit('preview-content')"
class="fcb-action rounded-[30px] bg-indigo-600 px-4 py-2 text-white transition duration-200 hover:bg-indigo-700"
>
{{ t('fileDetail.previewContent') }}
</button>
</div>
<div v-else>
<a
:href="getDownloadUrl(record)"
target="_blank"
rel="noopener noreferrer"
class="rounded-[30px] bg-indigo-600 px-4 py-2 text-white transition duration-200 hover:bg-indigo-700"
>
{{ t('fileDetail.download') }}
</a>
</div>
</div>
</div>
<div class="mt-5 flex flex-col items-center px-4 sm:mt-6 sm:px-6" v-if="record">
<h4
class="text-lg font-semibold mb-3"
:class="[isDarkMode ? 'text-white' : 'text-gray-800']"
>
{{ t('fileDetail.qrCode') }}
</h4>
<div class="bg-white p-2 rounded-lg shadow-md">
<QRCode :value="getQRCodeValue(record)" :size="128" level="M" />
</div>
<p class="mt-2 text-sm" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']">
{{ t('fileDetail.scanQrCode') }}
</p>
</div>
<button
@click="$emit('close')"
class="fcb-action mt-6 w-full rounded-[30px] bg-gradient-to-r from-indigo-500 to-purple-600 px-5 py-3 font-medium text-white transition duration-200 transform hover:from-indigo-600 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50 sm:mt-8 sm:px-6"
>
{{ t('common.close') }}
</button>
<BaseModal :show="visible" :title="t('fileDetail.title')" size="md" @close="$emit('close')">
<div v-if="record" class="space-y-4 text-sm">
<div class="flex items-start gap-3">
<FileIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" />
<div class="min-w-0"><p class="text-xs opacity-70">{{ t('fileRecord.filename') }}</p><p class="mt-1 break-all font-medium leading-6">{{ record.filename }}</p></div>
</div>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<div class="flex items-start gap-3"><CalendarIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" /><div class="min-w-0"><p class="text-xs opacity-70">{{ t('fileRecord.date') }}</p><p class="mt-1 break-words leading-6">{{ record.date }}</p></div></div>
<div class="flex items-start gap-3"><HardDriveIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" /><div><p class="text-xs opacity-70">{{ t('fileRecord.size') }}</p><p class="mt-1 leading-6">{{ record.size }}</p></div></div>
</div>
<div class="border-t pt-4" :class="isDarkMode ? 'border-gray-700' : 'border-gray-200'">
<BaseButton v-if="record.filename === 'Text'" @click="$emit('preview-content')">{{ t('fileDetail.previewContent') }}</BaseButton>
<a v-else :href="getDownloadUrl(record)" target="_blank" rel="noopener noreferrer" class="fcb-action fcb-button-primary inline-flex min-h-11 items-center gap-2 rounded-[30px] px-4 py-2 font-medium"><DownloadIcon class="h-4 w-4" aria-hidden="true" />{{ t('fileDetail.download') }}</a>
</div>
<div class="flex flex-col items-center gap-2 rounded-2xl p-4" :class="isDarkMode ? 'bg-gray-900/30' : 'bg-white/40'">
<h4 class="font-semibold">{{ t('fileDetail.qrCode') }}</h4>
<div class="rounded-xl bg-white p-2"><QRCode :value="getQRCodeValue(record)" :size="128" level="M" /></div>
<p class="text-xs opacity-70">{{ t('fileDetail.scanQrCode') }}</p>
</div>
</div>
</transition>
<template #footer><BaseButton variant="secondary" @click="$emit('close')">{{ t('common.close') }}</BaseButton></template>
</BaseModal>
</template>
<script setup lang="ts">
@@ -112,6 +28,8 @@ import { defineAsyncComponent, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import { FileIcon, CalendarIcon, HardDriveIcon, DownloadIcon } from 'lucide-vue-next'
import BaseModal from './BaseModal.vue'
import BaseButton from './BaseButton.vue'
import type { ReceivedFileRecord } from '@/types'
import { buildDownloadUrl, buildReceivedRecordQrValue } from '@/utils/share-url'
@@ -139,15 +57,3 @@ const getQRCodeValue = (record: ReceivedFileRecord) => {
return buildReceivedRecordQrValue(record)
}
</script>
<style scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.2s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
</style>
+9 -1
View File
@@ -27,6 +27,8 @@ export function useSendFlow() {
const expirationMethod = ref(config.value.expireStyle[0] || 'day')
const expirationValue = ref('1')
const uploadProgress = ref(0)
const uploadedBytes = ref(0)
const totalBytes = ref(0)
const showDrawer = ref(false)
const selectedRecord = ref<SentFileRecord | null>(null)
const isSubmitting = ref(false)
@@ -62,7 +64,9 @@ export function useSendFlow() {
notify: (message, type) => alertStore.showAlert(message, type),
translate: t,
onProgress: (progress) => {
uploadProgress.value = progress
uploadProgress.value = progress.percentage
uploadedBytes.value = progress.loaded
totalBytes.value = progress.total
},
onFinalizing: () => { isFinalizing.value = true },
onHashCalculated: (hash) => {
@@ -285,6 +289,8 @@ export function useSendFlow() {
alertStore.showAlert(getErrorMessage(error, t('send.messages.sendFailed')), 'error')
} finally {
uploadProgress.value = 0
uploadedBytes.value = 0
totalBytes.value = 0
isSubmitting.value = false
isFinalizing.value = false
}
@@ -319,6 +325,8 @@ export function useSendFlow() {
expirationMethod,
expirationValue,
uploadProgress,
uploadedBytes,
totalBytes,
showDrawer,
selectedRecord,
isSubmitting,
+3 -3
View File
@@ -12,7 +12,7 @@ type UseSendSubmitOptions = {
getMaxFileSize: () => number
notify: (message: string, type: AlertType) => void
translate: Translate
onProgress: (progress: number) => void
onProgress: (progress: UploadProgress) => void
onFinalizing: () => void
onHashCalculated: (hash: string) => void
}
@@ -49,7 +49,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
onHashCalculated: options.onHashCalculated,
onFinalizing: options.onFinalizing,
onProgress: (progress: UploadProgress) => {
options.onProgress(progress.percentage)
options.onProgress(progress)
},
messages: {
initFailed: options.translate('send.messages.initChunkUploadFailed'),
@@ -68,7 +68,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
expireValue,
expireStyle: expireStyle as ExpireStyle,
onProgress: (progress) => {
options.onProgress(progress.percentage)
options.onProgress(progress)
}
})
+7 -4
View File
@@ -3,7 +3,7 @@ import { waitForUploadCompletion, isTransientCompletionError } from './upload-co
import type { ApiResponse, ChunkUploadInitResponse, FileUploadResponse, UploadProgress } from '@/types'
import { calculateFileHash } from '@/utils/file-processing'
const CHUNK_SIZE = 5 * 1024 * 1024
export const CHUNK_SIZE = 100 * 1024 * 1024
type ChunkedUploadOptions = {
expireValue: number
@@ -26,6 +26,7 @@ const pendingCompletion = new WeakMap<File, { uploadId: string; expireValue: num
async function finishUpload(file: File, options: ChunkedUploadOptions): Promise<ApiResponse<ChunkedUploadResult>> {
const session = pendingCompletion.get(file)!
options.onProgress?.({loaded:file.size,total:file.size,percentage:99})
options.onFinalizing?.()
try {
const response = await waitForUploadCompletion(() => FileService.completeChunkUpload(session.uploadId, {
@@ -55,7 +56,6 @@ export const uploadChunkedFile = async (
const fileHash = await calculateFileHash(file)
options.onHashCalculated?.(fileHash)
const chunks = Math.ceil(file.size / CHUNK_SIZE)
const initResponse = await FileService.initChunkUpload({
file_name: file.name,
file_size: file.size,
@@ -77,13 +77,16 @@ export const uploadChunkedFile = async (
throw new Error(options.messages?.initFailed || 'Init chunk upload failed')
}
const chunkSize = initDetail.chunk_size || CHUNK_SIZE
const chunks = Math.ceil(file.size / chunkSize)
const uploadedChunks = new Set(initDetail.uploaded_chunks || [])
options.onProgress?.({loaded:calculateCompletedBytes(uploadedChunks,chunkSize,file.size),total:file.size,percentage:0})
for (let index = 0; index < chunks; index++) {
if (uploadedChunks.has(index)) {
continue
}
const start = index * CHUNK_SIZE
const start = index * chunkSize
const end = Math.min(start + CHUNK_SIZE, file.size)
const chunk = file.slice(start, end)
const chunkResponse = await FileService.uploadChunk(
@@ -91,7 +94,7 @@ export const uploadChunkedFile = async (
index,
new Blob([chunk], { type: file.type }),
(progress) => {
const completedBytes = calculateCompletedBytes(uploadedChunks, CHUNK_SIZE, file.size)
const completedBytes = calculateCompletedBytes(uploadedChunks, chunkSize, file.size)
const percentage = Math.round(((completedBytes + progress.loaded) * 100) / file.size)
options.onProgress?.({
loaded: completedBytes + progress.loaded,
+2
View File
@@ -481,6 +481,8 @@ export interface ChunkUploadInitRequest {
}
export interface ChunkUploadInitResponse {
chunk_size?: number
total_chunks?: number
code?: string
name?: string
upload_id?: string