(taskId)
| 1452 | } |
| 1453 | |
| 1454 | async function pollVendorProgress(taskId) { |
| 1455 | if (!taskId) return; |
| 1456 | try { |
| 1457 | const payload = await api.get(`/payment/bind-card/tasks/${taskId}/vendor-progress?cursor=${vendorProgressState.cursor}`); |
| 1458 | const progressPayload = payload?.progress || {}; |
| 1459 | const logs = progressPayload?.logs || []; |
| 1460 | appendVendorLogs(logs); |
| 1461 | vendorProgressState.cursor = Number(progressPayload?.next_cursor || vendorProgressState.cursor || 0); |
| 1462 | updateVendorProgressUi(progressPayload, taskId); |
| 1463 | const state = String(progressPayload?.status || "").toLowerCase(); |
| 1464 | if (state === "completed") { |
| 1465 | toast.success(`任务 #${taskId} 订阅完成`); |
| 1466 | stopVendorProgressPolling(); |
| 1467 | setVendorStopButtonState(true, true); |
| 1468 | setVendorRetryButtonState(false, false); |
| 1469 | await loadBindCardTasks(true); |
| 1470 | return; |
| 1471 | } |
| 1472 | if (state === "failed") { |
| 1473 | toast.error(`任务 #${taskId} 订阅失败`); |
| 1474 | stopVendorProgressPolling(); |
| 1475 | setVendorStopButtonState(true, true); |
| 1476 | setVendorRetryButtonState(false, true); |
| 1477 | await loadBindCardTasks(true); |
| 1478 | return; |
| 1479 | } |
| 1480 | if (state === "cancelled") { |
| 1481 | toast.warning(`任务 #${taskId} 已停止`, 4000); |
| 1482 | stopVendorProgressPolling(); |
| 1483 | setVendorStopButtonState(true, true); |
| 1484 | setVendorRetryButtonState(false, true); |
| 1485 | await loadBindCardTasks(true); |
| 1486 | return; |
| 1487 | } |
| 1488 | if (state === "pending") { |
| 1489 | toast.warning(`任务 #${taskId} 接口执行已完成,等待订阅同步`, 6000); |
| 1490 | stopVendorProgressPolling(); |
| 1491 | // pending 阶段仍允许手动停止(仅停止订阅任务,不影响其他任务) |
| 1492 | setVendorStopButtonState(false, true); |
| 1493 | setVendorRetryButtonState(false, true); |
| 1494 | await loadBindCardTasks(true); |
| 1495 | return; |
| 1496 | } |
| 1497 | vendorProgressState.timer = setTimeout(() => { |
| 1498 | pollVendorProgress(taskId); |
| 1499 | }, 2000); |
| 1500 | } catch (error) { |
| 1501 | const status = Number(error?.response?.status || 0); |
| 1502 | const detail = String(error?.data?.detail || "").trim(); |
| 1503 | if (status === 404 && detail.includes("绑卡任务不存在")) { |
| 1504 | appendVendorLogs([{ time: "--:--:--", message: "进度服务未命中任务,已停止轮询(可刷新任务列表后重试)" }]); |
| 1505 | stopVendorProgressPolling(); |
| 1506 | setVendorStopButtonState(false, true); |
| 1507 | setVendorRetryButtonState(false, true); |
| 1508 | return; |
| 1509 | } |
| 1510 | appendVendorLogs([{ time: "--:--:--", message: `进度轮询失败: ${formatErrorMessage(error)}` }]); |
| 1511 | vendorProgressState.timer = setTimeout(() => { |
no test coverage detected