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
This commit is contained in:
admin
2026-01-23 15:55:27 +08:00
parent 2074d4fb78
commit 5120ed8af0

View File

@@ -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);
}
});