From 2aef8010dbadece2515d103fe8397a1efe1566d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E5=B1=85?= Date: Fri, 6 Nov 2026 15:40:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(clearance):=20=E4=BF=AE=E6=AD=A3=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=8A=B6=E6=80=81=E8=BD=AE=E8=AF=A2=E4=B8=8E=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/clearance/ClearanceView.tsx | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/furniture-3d-system/src/app/supply-chain/management/clearance/ClearanceView.tsx b/furniture-3d-system/src/app/supply-chain/management/clearance/ClearanceView.tsx index 6dd1a3f6..51dd5e76 100644 --- a/furniture-3d-system/src/app/supply-chain/management/clearance/ClearanceView.tsx +++ b/furniture-3d-system/src/app/supply-chain/management/clearance/ClearanceView.tsx @@ -661,6 +661,7 @@ export function ClearanceView({ const taskScrollRef = useRef(null) const [taskRefreshKey, setTaskRefreshKey] = useState(0) const taskProgressRetryCountRef = useRef(0) + const handledProgressSyncRef = useRef(null) const [scores, setScores] = useState(null) const [scorePeriod, setScorePeriod] = useState('') @@ -813,18 +814,43 @@ export function ClearanceView({ if (!progressStale) { taskProgressRetryCountRef.current = 0 } - void requestJson<{ queued: boolean }>( + void requestJson<{ + queued: boolean + status?: { + running: boolean + lastError: string + through: string | null + lastFinishedAt: string | null + } + }>( '/api/supply-chain/clearance/tasks/progress-refresh', { method: 'POST', body: JSON.stringify({ periodKey: data.periodKey }), }, ) - .then(() => { - if (controller.signal.aborted || !progressStale) return + .then((response) => { + const syncFinishedAt = response.status?.lastFinishedAt ?? null + const hasUnhandledFinishedSync = Boolean( + syncFinishedAt && handledProgressSyncRef.current !== syncFinishedAt, + ) + const shouldPoll = Boolean( + response.queued + || response.status?.running + || response.status?.lastError + || progressStale + || hasUnhandledFinishedSync, + ) + if (syncFinishedAt && !response.status?.running) { + handledProgressSyncRef.current = syncFinishedAt + } + if (controller.signal.aborted || !shouldPoll) return const attempt = taskProgressRetryCountRef.current const delay = TASK_PROGRESS_RETRY_DELAYS[attempt] - if (delay == null) return + if (delay == null) { + setTaskError('发货同步仍在处理中,请稍后手动刷新') + return + } taskProgressRetryCountRef.current += 1 progressRetryTimer = window.setTimeout(async () => { try { @@ -835,7 +861,6 @@ export function ClearanceView({ }>( `/api/supply-chain/clearance/tasks/progress-refresh?period=${encodeURIComponent(data.periodKey)}`, { signal: controller.signal }, - 2, ) if (controller.signal.aborted) return if (!status.running && status.lastError) { @@ -854,6 +879,9 @@ export function ClearanceView({ }) .catch((reason: Error) => { console.warn('[clearance] progress refresh queue failed', reason) + if (!controller.signal.aborted) { + setTaskError('无法启动发货同步,请稍后手动刷新') + } }) }) .catch((reason: Error) => {