From 8b0d90cdc356f0ac258b9b9dc1d5076dad5f71ba Mon Sep 17 00:00:00 2001 From: keven Date: Tue, 23 Sep 2025 00:02:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(front):=20=E4=BC=98=E5=8C=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E8=BF=9B=E5=BA=A6=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E8=BF=9B=E6=96=87=E4=BB=B6ID=E5=92=8C?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E9=98=9F=E5=88=97=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E6=9C=89=E6=95=88=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/File/FileUploadProgressView.vue | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/front/components/Home/File/FileUploadProgressView.vue b/front/components/Home/File/FileUploadProgressView.vue index 57de203..12df6ad 100644 --- a/front/components/Home/File/FileUploadProgressView.vue +++ b/front/components/Home/File/FileUploadProgressView.vue @@ -122,8 +122,9 @@ const { error, execute, isLoading } = useAsyncState( await Promise.all( times(batchNum.value, async (i: number) => { const file = sample(taskList) - const fileId = file?.fileId as string - const task = get(file?.queue, '0') + const { fileId, queue } = file || {} + if (!fileId) return + const task = get(queue, '0') if (!task) return const { taskId, index, queueType, taskType, retry } = task || {} if (procressTaskList.value.has(taskId)) return @@ -243,10 +244,12 @@ const handleCreate = async (fileId: string) => { const handleChunk = async (fileId: string) => { const uploadfile = uploadfiles.value.find((item) => item.fileId === fileId) if (!uploadfile?.file) return - uploadfile.procressType = 'upload' const { chunkLength } = uploadfile.uploadInfo || {} + if (!chunkLength) return + + uploadfile.procressType = 'upload' const tasks = shuffle( - times(chunkLength as number, (i: number) => ({ taskType: 'upload' as const, queueType: 'async' as const, taskId: nanoid(), index: i })) + times(chunkLength, (i: number) => ({ taskType: 'upload' as const, queueType: 'async' as const, taskId: nanoid(), index: i })) ) uploadfile.queue.push(...tasks) } @@ -254,6 +257,10 @@ const handleChunk = async (fileId: string) => { const handleUpload = async (fileId: string, index: number) => { const uploadfile = uploadfiles.value.find((item) => item.fileId === fileId) if (!uploadfile?.file) return + const { id, uploadInfo } = uploadfile || {} + const { chunkLength, ChunkSize } = uploadInfo || {} + if (!ChunkSize || !id) return + if (uploadfile.procressType !== 'upload') uploadfile.procressType = 'upload' let chunkInfo = uploadfile.uploadInfo?.chunks?.[index] if (!chunkInfo) { @@ -262,14 +269,12 @@ const handleUpload = async (fileId: string, index: number) => { createdAt: dayjs().unix(), } } - const { id, uploadInfo } = uploadfile || {} - const { chunkLength, ChunkSize } = uploadInfo || {} - const chunk = await getFileChunk(uploadfile.file, index, ChunkSize as number) + const chunk = await getFileChunk(uploadfile.file, index * ChunkSize, ChunkSize) const formData = new FormData() formData.append('file', new Blob([chunk])) formData.append('index', (index + 1).toString()) - formData.append('id', id as string) + formData.append('id', id) const res = await $fetch<{ code: number }>('/api/file/slice', {