修复错题一直显示处理中:超时、自动刷新与状态更新。

This commit is contained in:
dekun
2026-06-28 14:09:10 +08:00
parent c42cd0b46d
commit 6200dbb596
7 changed files with 163 additions and 46 deletions
+15 -3
View File
@@ -1,7 +1,9 @@
import { DeleteOutlined } from '@ant-design/icons'
import { Button, Popconfirm, Space, Tag, Typography, message } from 'antd'
import { useEffect } from 'react'
import { wrongQuestionApi } from '../api/client'
import type { WrongQuestion } from '../types'
import { isWrongQuestionProcessing, processingHint } from '../utils/wqProcessing'
import { STATUS_LABELS } from '../types'
import AuthenticatedImage from './AuthenticatedImage'
import WrongQuestionDetail from '../pages/WrongQuestionDetail'
@@ -12,14 +14,15 @@ interface Props {
onSelect: (id: string | null) => void
onRefresh: () => void
emptyText?: string
pollWhenProcessing?: boolean
}
function cardSummary(wq: WrongQuestion): { tone: 'error' | 'pending' | 'normal'; text: string } {
if (wq.error_message) {
return { tone: 'error', text: wq.error_message }
}
if (wq.status === 'pending') {
return { tone: 'pending', text: '正在识别、标注并生成解题思路…' }
if (isWrongQuestionProcessing(wq)) {
return { tone: 'pending', text: processingHint(wq) }
}
return {
tone: 'normal',
@@ -33,7 +36,16 @@ export default function WrongQuestionList({
onSelect,
onRefresh,
emptyText = '暂无记录',
pollWhenProcessing = true,
}: Props) {
const hasProcessing = pollWhenProcessing && items.some(isWrongQuestionProcessing)
useEffect(() => {
if (!hasProcessing) return
const timer = window.setInterval(() => onRefresh(), 4000)
return () => window.clearInterval(timer)
}, [hasProcessing, onRefresh])
const handleDelete = async (id: string) => {
try {
await wrongQuestionApi.remove(id)
@@ -58,7 +70,7 @@ export default function WrongQuestionList({
<Space size={4} wrap>
<Typography.Text strong>{wq.subject_name}</Typography.Text>
{wq.category === 'olympiad' && <Tag color="gold"></Tag>}
<Tag color={wq.error_message || wq.status === 'failed' ? 'error' : wq.status === 'pending' ? 'processing' : 'default'}>
<Tag color={wq.error_message || wq.status === 'failed' ? 'error' : isWrongQuestionProcessing(wq) ? 'processing' : 'default'}>
{wq.error_message ? '失败' : STATUS_LABELS[wq.status]}
</Tag>
</Space>