From 5120ed8af0840b69127392e3e88a218dd9476882 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 23 Jan 2026 15:55:27 +0800 Subject: [PATCH] Fix background upload stopping issue - Remove duplicate uploadprogress event listeners that were conflicting - Simplify progress calculation logic to avoid jumping - Ensure Dropzone continues processing queue after modal close - Fix BackgroundUploadManager event binding to prevent conflicts - Add proper progress synchronization between modal and background views --- static/app.js | 53 +++++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/static/app.js b/static/app.js index 9a9332c..09abe4f 100644 --- a/static/app.js +++ b/static/app.js @@ -94,6 +94,13 @@ // 绑定事件监听 this.bindDropzoneEvents(); + + // 确保Dropzone继续处理上传队列 + setTimeout(() => { + if (dropzone.getQueuedFiles().length > 0) { + dropzone.processQueue(); + } + }, 100); } bindDropzoneEvents() { @@ -101,15 +108,7 @@ const dz = this.dropzoneInstance; - dz.on('uploadprogress', (file, progress, bytesSent, totalBytesSent, totalBytes) => { - let chunkInfo = null; - if (file.totalChunks > 1) { - const currentChunk = (file.upload && file.upload.chunk) || 0; - chunkInfo = `${currentChunk + 1}/${file.totalChunks}`; - } - this.updateProgress(file._dzFileId, progress, chunkInfo); - }); - + // 监听成功和错误事件 dz.on('success', (file, response) => { this.completeUpload(file._dzFileId); }); @@ -569,6 +568,8 @@ this.on('uploadprogress', function(file, progress, bytesSent, totalBytesSent, totalBytes) { var fileId = file._dzFileId; + + // 更新悬浮窗中的进度 var progressEl = document.getElementById('progress-' + fileId); var percentEl = document.getElementById('percent-' + fileId); var chunksEl = document.getElementById('chunks-' + fileId); @@ -595,38 +596,10 @@ percentEl.textContent = Math.round(progress) + '%'; } } - }); - this.on('uploadprogress', function(file, progress, bytesSent, totalBytesSent, totalBytes) { - var fileId = file._dzFileId; - var progressEl = document.getElementById('progress-' + fileId); - var percentEl = document.getElementById('percent-' + fileId); - var chunksEl = document.getElementById('chunks-' + fileId); - - file._uploadProgress = progress; - - if (file.totalChunks > 1) { - var currentChunk = file.upload.chunk || 0; - var chunkProgress = (currentChunk / file.totalChunks) * 100; - var currentChunkProgress = (progress / 100) * (100 / file.totalChunks); - var totalProgress = chunkProgress + currentChunkProgress; - - if (progressEl) { - progressEl.style.width = Math.min(totalProgress, 100) + '%'; - } - if (percentEl) { - percentEl.textContent = Math.round(Math.min(totalProgress, 100)) + '%'; - } - if (chunksEl) { - chunksEl.textContent = (currentChunk + 1) + '/' + file.totalChunks; - } - } else { - if (progressEl) { - progressEl.style.width = progress + '%'; - } - if (percentEl) { - percentEl.textContent = Math.round(progress) + '%'; - } + // 同步到后台管理器 + if (backgroundManager) { + backgroundManager.updateProgress(fileId, totalProgress, file.totalChunks > 1 ? `${(file.upload.chunk || 0) + 1}/${file.totalChunks}` : null); } });