diff --git a/src/components/dialog/ReorganizeDialog.vue b/src/components/dialog/ReorganizeDialog.vue index b0e75b35..2da58d44 100644 --- a/src/components/dialog/ReorganizeDialog.vue +++ b/src/components/dialog/ReorganizeDialog.vue @@ -188,6 +188,11 @@ async function handleTransferLog(logid: number, background: boolean = false) { // 使用SSE监听加载进度 function startLoadingProgress() { + // 在创建新连接之前,先确保任何可能存在的旧连接都被关闭了,防止因快速重复点击而产生孤儿连接。 + if (progressEventSource.value) { + progressEventSource.value.close() + } + progressText.value = t('dialog.reorganize.processing') progressEventSource.value = new EventSource(`${import.meta.env.VITE_API_BASE_URL}system/progress/filetransfer`) progressEventSource.value.onmessage = event => { @@ -197,6 +202,13 @@ function startLoadingProgress() { progressValue.value = progress.value } } + + // 发生错误时,也确保连接被关闭,避免重试等意外行为 + progressEventSource.value.onerror = () => { + if (progressEventSource.value) { + progressEventSource.value.close() + } + } } // 停止监听加载进度