🐛 fix(frontend): 修复上传进度与取件详情弹窗
This commit is contained in:
1 parent
da54bf40c9
commit
988ae2429d
5 files changed
+40
-121
No files matched your search
@@ -1,110 +1,26 @@
|
|||||||
<template>
|
<template>
|
||||||
<transition name="fade">
|
<BaseModal :show="visible" :title="t('fileDetail.title')" size="md" @close="$emit('close')">
|
||||||
<div
|
<div v-if="record" class="space-y-4 text-sm">
|
||||||
v-if="visible"
|
<div class="flex items-start gap-3">
|
||||||
class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"
|
<FileIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" />
|
||||||
@click.self="$emit('close')"
|
<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
|
|
||||||
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>
|
||||||
<div class="flex items-center">
|
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
<CalendarIcon
|
<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>
|
||||||
class="w-6 h-6 mr-3 flex-shrink-0"
|
<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>
|
||||||
: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>
|
||||||
<div class="flex items-center">
|
<div class="border-t pt-4" :class="isDarkMode ? 'border-gray-700' : 'border-gray-200'">
|
||||||
<HardDriveIcon
|
<BaseButton v-if="record.filename === 'Text'" @click="$emit('preview-content')">{{ t('fileDetail.previewContent') }}</BaseButton>
|
||||||
class="w-6 h-6 mr-3 flex-shrink-0"
|
<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>
|
||||||
: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>
|
||||||
<div class="flex items-center">
|
<div class="flex flex-col items-center gap-2 rounded-2xl p-4" :class="isDarkMode ? 'bg-gray-900/30' : 'bg-white/40'">
|
||||||
<DownloadIcon
|
<h4 class="font-semibold">{{ t('fileDetail.qrCode') }}</h4>
|
||||||
class="w-6 h-6 mr-3"
|
<div class="rounded-xl bg-white p-2"><QRCode :value="getQRCodeValue(record)" :size="128" level="M" /></div>
|
||||||
:class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']"
|
<p class="text-xs opacity-70">{{ t('fileDetail.scanQrCode') }}</p>
|
||||||
/>
|
|
||||||
<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>
|
||||||
</div>
|
<template #footer><BaseButton variant="secondary" @click="$emit('close')">{{ t('common.close') }}</BaseButton></template>
|
||||||
|
</BaseModal>
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</transition>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -112,6 +28,8 @@ import { defineAsyncComponent, inject } from 'vue'
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { FileIcon, CalendarIcon, HardDriveIcon, DownloadIcon } from 'lucide-vue-next'
|
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 type { ReceivedFileRecord } from '@/types'
|
||||||
import { buildDownloadUrl, buildReceivedRecordQrValue } from '@/utils/share-url'
|
import { buildDownloadUrl, buildReceivedRecordQrValue } from '@/utils/share-url'
|
||||||
|
|
||||||
@@ -139,15 +57,3 @@ const getQRCodeValue = (record: ReceivedFileRecord) => {
|
|||||||
return buildReceivedRecordQrValue(record)
|
return buildReceivedRecordQrValue(record)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.fade-enter-active,
|
|
||||||
.fade-leave-active {
|
|
||||||
transition: opacity 0.2s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.fade-enter-from,
|
|
||||||
.fade-leave-to {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -27,6 +27,8 @@ export function useSendFlow() {
|
|||||||
const expirationMethod = ref(config.value.expireStyle[0] || 'day')
|
const expirationMethod = ref(config.value.expireStyle[0] || 'day')
|
||||||
const expirationValue = ref('1')
|
const expirationValue = ref('1')
|
||||||
const uploadProgress = ref(0)
|
const uploadProgress = ref(0)
|
||||||
|
const uploadedBytes = ref(0)
|
||||||
|
const totalBytes = ref(0)
|
||||||
const showDrawer = ref(false)
|
const showDrawer = ref(false)
|
||||||
const selectedRecord = ref<SentFileRecord | null>(null)
|
const selectedRecord = ref<SentFileRecord | null>(null)
|
||||||
const isSubmitting = ref(false)
|
const isSubmitting = ref(false)
|
||||||
@@ -62,7 +64,9 @@ export function useSendFlow() {
|
|||||||
notify: (message, type) => alertStore.showAlert(message, type),
|
notify: (message, type) => alertStore.showAlert(message, type),
|
||||||
translate: t,
|
translate: t,
|
||||||
onProgress: (progress) => {
|
onProgress: (progress) => {
|
||||||
uploadProgress.value = progress
|
uploadProgress.value = progress.percentage
|
||||||
|
uploadedBytes.value = progress.loaded
|
||||||
|
totalBytes.value = progress.total
|
||||||
},
|
},
|
||||||
onFinalizing: () => { isFinalizing.value = true },
|
onFinalizing: () => { isFinalizing.value = true },
|
||||||
onHashCalculated: (hash) => {
|
onHashCalculated: (hash) => {
|
||||||
@@ -285,6 +289,8 @@ export function useSendFlow() {
|
|||||||
alertStore.showAlert(getErrorMessage(error, t('send.messages.sendFailed')), 'error')
|
alertStore.showAlert(getErrorMessage(error, t('send.messages.sendFailed')), 'error')
|
||||||
} finally {
|
} finally {
|
||||||
uploadProgress.value = 0
|
uploadProgress.value = 0
|
||||||
|
uploadedBytes.value = 0
|
||||||
|
totalBytes.value = 0
|
||||||
isSubmitting.value = false
|
isSubmitting.value = false
|
||||||
isFinalizing.value = false
|
isFinalizing.value = false
|
||||||
}
|
}
|
||||||
@@ -319,6 +325,8 @@ export function useSendFlow() {
|
|||||||
expirationMethod,
|
expirationMethod,
|
||||||
expirationValue,
|
expirationValue,
|
||||||
uploadProgress,
|
uploadProgress,
|
||||||
|
uploadedBytes,
|
||||||
|
totalBytes,
|
||||||
showDrawer,
|
showDrawer,
|
||||||
selectedRecord,
|
selectedRecord,
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type UseSendSubmitOptions = {
|
|||||||
getMaxFileSize: () => number
|
getMaxFileSize: () => number
|
||||||
notify: (message: string, type: AlertType) => void
|
notify: (message: string, type: AlertType) => void
|
||||||
translate: Translate
|
translate: Translate
|
||||||
onProgress: (progress: number) => void
|
onProgress: (progress: UploadProgress) => void
|
||||||
onFinalizing: () => void
|
onFinalizing: () => void
|
||||||
onHashCalculated: (hash: string) => void
|
onHashCalculated: (hash: string) => void
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
|
|||||||
onHashCalculated: options.onHashCalculated,
|
onHashCalculated: options.onHashCalculated,
|
||||||
onFinalizing: options.onFinalizing,
|
onFinalizing: options.onFinalizing,
|
||||||
onProgress: (progress: UploadProgress) => {
|
onProgress: (progress: UploadProgress) => {
|
||||||
options.onProgress(progress.percentage)
|
options.onProgress(progress)
|
||||||
},
|
},
|
||||||
messages: {
|
messages: {
|
||||||
initFailed: options.translate('send.messages.initChunkUploadFailed'),
|
initFailed: options.translate('send.messages.initChunkUploadFailed'),
|
||||||
@@ -68,7 +68,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
|
|||||||
expireValue,
|
expireValue,
|
||||||
expireStyle: expireStyle as ExpireStyle,
|
expireStyle: expireStyle as ExpireStyle,
|
||||||
onProgress: (progress) => {
|
onProgress: (progress) => {
|
||||||
options.onProgress(progress.percentage)
|
options.onProgress(progress)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { waitForUploadCompletion, isTransientCompletionError } from './upload-co
|
|||||||
import type { ApiResponse, ChunkUploadInitResponse, FileUploadResponse, UploadProgress } from '@/types'
|
import type { ApiResponse, ChunkUploadInitResponse, FileUploadResponse, UploadProgress } from '@/types'
|
||||||
import { calculateFileHash } from '@/utils/file-processing'
|
import { calculateFileHash } from '@/utils/file-processing'
|
||||||
|
|
||||||
const CHUNK_SIZE = 5 * 1024 * 1024
|
export const CHUNK_SIZE = 100 * 1024 * 1024
|
||||||
|
|
||||||
type ChunkedUploadOptions = {
|
type ChunkedUploadOptions = {
|
||||||
expireValue: number
|
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>> {
|
async function finishUpload(file: File, options: ChunkedUploadOptions): Promise<ApiResponse<ChunkedUploadResult>> {
|
||||||
const session = pendingCompletion.get(file)!
|
const session = pendingCompletion.get(file)!
|
||||||
|
options.onProgress?.({loaded:file.size,total:file.size,percentage:99})
|
||||||
options.onFinalizing?.()
|
options.onFinalizing?.()
|
||||||
try {
|
try {
|
||||||
const response = await waitForUploadCompletion(() => FileService.completeChunkUpload(session.uploadId, {
|
const response = await waitForUploadCompletion(() => FileService.completeChunkUpload(session.uploadId, {
|
||||||
@@ -55,7 +56,6 @@ export const uploadChunkedFile = async (
|
|||||||
const fileHash = await calculateFileHash(file)
|
const fileHash = await calculateFileHash(file)
|
||||||
options.onHashCalculated?.(fileHash)
|
options.onHashCalculated?.(fileHash)
|
||||||
|
|
||||||
const chunks = Math.ceil(file.size / CHUNK_SIZE)
|
|
||||||
const initResponse = await FileService.initChunkUpload({
|
const initResponse = await FileService.initChunkUpload({
|
||||||
file_name: file.name,
|
file_name: file.name,
|
||||||
file_size: file.size,
|
file_size: file.size,
|
||||||
@@ -77,13 +77,16 @@ export const uploadChunkedFile = async (
|
|||||||
throw new Error(options.messages?.initFailed || 'Init chunk upload failed')
|
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 || [])
|
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++) {
|
for (let index = 0; index < chunks; index++) {
|
||||||
if (uploadedChunks.has(index)) {
|
if (uploadedChunks.has(index)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = index * CHUNK_SIZE
|
const start = index * chunkSize
|
||||||
const end = Math.min(start + CHUNK_SIZE, file.size)
|
const end = Math.min(start + CHUNK_SIZE, file.size)
|
||||||
const chunk = file.slice(start, end)
|
const chunk = file.slice(start, end)
|
||||||
const chunkResponse = await FileService.uploadChunk(
|
const chunkResponse = await FileService.uploadChunk(
|
||||||
@@ -91,7 +94,7 @@ export const uploadChunkedFile = async (
|
|||||||
index,
|
index,
|
||||||
new Blob([chunk], { type: file.type }),
|
new Blob([chunk], { type: file.type }),
|
||||||
(progress) => {
|
(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)
|
const percentage = Math.round(((completedBytes + progress.loaded) * 100) / file.size)
|
||||||
options.onProgress?.({
|
options.onProgress?.({
|
||||||
loaded: completedBytes + progress.loaded,
|
loaded: completedBytes + progress.loaded,
|
||||||
|
|||||||
@@ -481,6 +481,8 @@ export interface ChunkUploadInitRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ChunkUploadInitResponse {
|
export interface ChunkUploadInitResponse {
|
||||||
|
chunk_size?: number
|
||||||
|
total_chunks?: number
|
||||||
code?: string
|
code?: string
|
||||||
name?: string
|
name?: string
|
||||||
upload_id?: string
|
upload_id?: string
|
||||||
|
|||||||
Reference in new issue
Block a user