(fileId: string, taskId: string | number)
| 208 | |
| 209 | // 查询任务状态 |
| 210 | const pollTaskStatus = async (fileId: string, taskId: string | number) => { |
| 211 | try { |
| 212 | const response = await getTaskStatus(taskId) |
| 213 | const { status, error_message } = response |
| 214 | |
| 215 | // 更新任务状态(error_message 对应 error),并保存完整的响应 |
| 216 | onTaskStatusChange?.({ |
| 217 | fileId, |
| 218 | status, |
| 219 | response, |
| 220 | error_message |
| 221 | }) |
| 222 | |
| 223 | // 如果任务完成或失败,停止轮询 |
| 224 | if (status === 'completed' || status === 'failed') { |
| 225 | stopPolling(fileId) |
| 226 | setIsLoading(false) |
| 227 | } |
| 228 | } catch (error: any) { |
| 229 | console.error('查询任务状态失败:', error) |
| 230 | // 查询失败时也停止轮询,避免无限重试 |
| 231 | stopPolling(fileId) |
| 232 | setIsLoading(false) |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // 组件卸载时清理所有轮询 |
| 237 | useEffect(() => { |
no test coverage detected