From 1585271e378bb5a4343d46cc7e01d52adf49783b Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 24 Aug 2025 16:16:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=20TransferQueueDialog=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=BC=98=E5=8C=96=20SSE=20=E7=9B=91=E5=90=AC=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/dialog/TransferQueueDialog.vue | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/components/dialog/TransferQueueDialog.vue b/src/components/dialog/TransferQueueDialog.vue index 6a5244ab..50a47ad2 100644 --- a/src/components/dialog/TransferQueueDialog.vue +++ b/src/components/dialog/TransferQueueDialog.vue @@ -45,6 +45,9 @@ const progressActive = ref(false) // 活动标签 const activeTab = ref('') +// 定时器引用 +const queueTimer = ref(null) + // 状态标签 const stateDict: { [key: string]: string } = { 'waiting': t('dialog.transferQueue.waitingState'), @@ -89,6 +92,16 @@ async function get_transfer_queue() { dataList.value = await api.get('transfer/queue') if (dataList.value.length > 0) { if (!activeTab.value || activeTasks.value?.length == 0) activeTab.value = dataList.value[0].media.title_year || '' + + // 如果有数据且SSE未启动,则启动SSE监听 + if (!progressActive.value) { + startLoadingProgress() + } + } else { + // 如果没有数据,停止SSE监听 + if (progressActive.value) { + stopLoadingProgress() + } } } catch (error) { console.error(error) @@ -214,12 +227,36 @@ function stopLoadingProgress() { stopCurrentFileProgress() } -onMounted(() => { +// 启动定时获取队列 +function startQueueTimer() { + // 清除可能存在的定时器 + if (queueTimer.value) { + clearInterval(queueTimer.value) + } + + // 立即执行一次 get_transfer_queue() - startLoadingProgress() + + // 设置3秒定时器 + queueTimer.value = setInterval(() => { + get_transfer_queue() + }, 3000) +} + +// 停止定时获取队列 +function stopQueueTimer() { + if (queueTimer.value) { + clearInterval(queueTimer.value) + queueTimer.value = null + } +} + +onMounted(() => { + startQueueTimer() }) onUnmounted(() => { + stopQueueTimer() stopLoadingProgress() })