From d9dfd602f9ba737597a176cee2c47aee8a8a0351 Mon Sep 17 00:00:00 2001 From: matevip Date: Sun, 19 Apr 2026 19:35:30 +0800 Subject: [PATCH] fix(wiki): fix progress display and reprocess feedback issues Three root causes for broken progress: 1. JobStageBar was shown whenever a job record existed (even at queued stage), hiding the working SSE-driven progress bar. Fix: only show JobStageBar when job.stage !== queued. 2. SSE connection only opened when hasProcessing was true (status === processing), but reprocess sets status to pending first. Fix: include pending in the hasProcessing check. 3. After reprocess, if processing finished before SSE connected, the status badge stayed on pending forever. Fix: immediately set local status to processing after reprocess API call, clear stale job entries, and add delayed re-fetches (5s/15s) as safety net. Also: clear rawJobs entries on raw.completed/raw.failed SSE events to prevent stale JobStageBar from lingering after processing ends. --- .../Wiki/components/RawMaterialPanel.vue | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/mateclaw-ui/src/views/Wiki/components/RawMaterialPanel.vue b/mateclaw-ui/src/views/Wiki/components/RawMaterialPanel.vue index 74b40d94..c89fd288 100644 --- a/mateclaw-ui/src/views/Wiki/components/RawMaterialPanel.vue +++ b/mateclaw-ui/src/views/Wiki/components/RawMaterialPanel.vue @@ -91,9 +91,9 @@ - + - +
- store.rawMaterials.some(r => r.processingStatus === 'processing') + store.rawMaterials.some(r => r.processingStatus === 'processing' || r.processingStatus === 'pending') ) function applyProgressEvent(payload: any) { @@ -224,7 +224,8 @@ function openSse(kbId: number) { raw.progressTotal = data.totalPages } } - // 完成事件后,再做一次轻量 list 拉取确保其他字段(pageCount 等)同步 + // Clear stale job entry so JobStageBar hides + delete rawJobs[data.rawId] if (store.currentKB) store.fetchRawMaterials(store.currentKB.id) } catch { /* ignore */ } }) @@ -233,6 +234,8 @@ function openSse(kbId: number) { const data = JSON.parse(ev.data) const raw = store.rawMaterials.find(r => r.id === data.rawId) if (raw) raw.processingStatus = 'failed' + // Clear stale job entry + delete rawJobs[data.rawId] if (store.currentKB) store.fetchRawMaterials(store.currentKB.id) } catch { /* ignore */ } }) @@ -350,8 +353,21 @@ async function handleAddText() { async function reprocess(rawId: number) { if (!store.currentKB) return - await wikiApi.reprocessRaw(store.currentKB.id, rawId) - await store.fetchRawMaterials(store.currentKB.id) + const kbId = store.currentKB.id + await wikiApi.reprocessRaw(kbId, rawId) + // Immediately mark local state as processing so SSE connects and progress bar shows + const raw = store.rawMaterials.find(r => r.id === rawId) + if (raw) { + raw.processingStatus = 'processing' + raw.progressDone = 0 + raw.progressTotal = 0 + } + // Clear stale job entry + delete rawJobs[rawId] + await store.fetchRawMaterials(kbId) + // Delayed re-fetch to catch final status if processing finishes before SSE connects + setTimeout(() => { store.fetchRawMaterials(kbId) }, 5000) + setTimeout(() => { store.fetchRawMaterials(kbId) }, 15000) } async function deleteRaw(rawId: number) { @@ -362,8 +378,14 @@ async function deleteRaw(rawId: number) { async function processAll() { if (!store.currentKB) return - await wikiApi.processKB(store.currentKB.id) - await store.fetchRawMaterials(store.currentKB.id) + const kbId = store.currentKB.id + await wikiApi.processKB(kbId) + // Mark all pending materials as processing so SSE connects + store.rawMaterials + .filter(r => r.processingStatus === 'pending') + .forEach(r => { r.processingStatus = 'processing'; r.progressDone = 0; r.progressTotal = 0 }) + await store.fetchRawMaterials(kbId) + setTimeout(() => { store.fetchRawMaterials(kbId) }, 5000) } async function handleScanDir() {