fix: 视频任务逐商品完成后刷新列表

This commit is contained in:
QiuSW
2026-09-30 09:06:20 +08:00
parent 309e3eeb11
commit 5447e3f63a
+29 -3
View File
@@ -552,6 +552,30 @@ const taskPercent = computed(() => {
return total > 0 ? Math.round((Number(taskProgress.value.done || 0) / total) * 100) : 0
})
let taskPollTimer = 0
let taskListRefreshPending = false
let taskListRefreshPromise = null
function refreshTaskListAfterProgress() {
taskListRefreshPending = true
if (!taskListRefreshPromise) {
taskListRefreshPromise = (async () => {
while (taskListRefreshPending) {
taskListRefreshPending = false
await search(false)
}
})().finally(() => {
taskListRefreshPromise = null
if (taskListRefreshPending) refreshTaskListAfterProgress()
})
}
return taskListRefreshPromise
}
async function refreshTaskListAtFinish() {
// 等待进度事件触发的查询,避免它晚于最终查询返回并覆盖最终状态。
while (taskListRefreshPromise) await taskListRefreshPromise
await search(false)
}
function formatElapsed(seconds) {
const value = Math.max(0, Number(seconds || 0))
@@ -637,7 +661,7 @@ function applyTaskProgress(progress) {
async function refreshTaskProgress() {
try {
applyTaskProgress(await GetVideoTaskProgress())
onTaskProgress(await GetVideoTaskProgress())
} catch (err) {
// 轮询只是事件漏收时的兜底,不重复弹错打断使用者。
console.warn('读取批量任务进度失败', err)
@@ -683,13 +707,15 @@ async function stopVideoTask() {
}
function onTaskProgress(progress) {
const completedMore = Number(progress?.done || 0) > Number(taskProgress.value.done || 0)
applyTaskProgress(progress)
if (completedMore) refreshTaskListAfterProgress()
}
async function onTaskFinished(progress) {
applyTaskProgress(progress)
taskStopping.value = false
await search(false)
await refreshTaskListAtFinish()
if (progress?.state === 'stopped') {
message.warning(`任务已停止,已处理 ${progress.done || 0}/${progress.total || 0}`)
} else {
@@ -710,7 +736,7 @@ function goToSettings() {
async function onTaskLoginRequired(progress) {
applyTaskProgress(progress)
taskStopping.value = false
await search(false)
await refreshTaskListAtFinish()
const riskSuspected = progress?.stopReason === 'risk_suspected'
const riskBlocked = progress?.stopReason === 'risk_blocked'
dialog.warning({