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) => {