import { Alert, Button, Col, Input, Modal, Popconfirm, Row, Space, Spin, Typography, message } from 'antd' import { useEffect, useState } from 'react' import ReactMarkdown from 'react-markdown' import AuthenticatedImage from '../components/AuthenticatedImage' import { wrongQuestionApi } from '../api/client' import type { WrongQuestion } from '../types' import { STATUS_LABELS } from '../types' interface Props { questionId: string open: boolean onClose: () => void onUpdated: () => void onDeleted?: () => void } export default function WrongQuestionDetail({ questionId, open, onClose, onUpdated, onDeleted, }: Props) { const [wq, setWq] = useState(null) const [loading, setLoading] = useState(false) const [questionText, setQuestionText] = useState('') const [solutionText, setSolutionText] = useState('') const [saving, setSaving] = useState(false) const [regenerating, setRegenerating] = useState(false) const [deleting, setDeleting] = useState(false) const load = async () => { setLoading(true) try { const { data } = await wrongQuestionApi.get(questionId) setWq(data) setQuestionText(data.question_text || '') setSolutionText(data.solution_text || '') } finally { setLoading(false) } } useEffect(() => { if (open && questionId) load() }, [open, questionId]) const handleSave = async () => { setSaving(true) try { await wrongQuestionApi.update(questionId, { question_text: questionText, solution_text: solutionText, }) message.success('已保存') onUpdated() } finally { setSaving(false) } } const handleRegenerate = async () => { setRegenerating(true) try { const { data } = await wrongQuestionApi.regenerate(questionId) setWq(data) setQuestionText(data.question_text || '') setSolutionText(data.solution_text || '') message.success('解法已重新生成') onUpdated() } catch { message.error('生成失败,请检查 AI 模型配置') } finally { setRegenerating(false) } } const handleRetryOcr = async () => { await wrongQuestionApi.retryOcr(questionId) message.info('已重新识别,请稍后刷新') onUpdated() onClose() } const handleDelete = async () => { setDeleting(true) try { await wrongQuestionApi.remove(questionId) message.success('已删除') onDeleted?.() onClose() } catch { message.error('删除失败') } finally { setDeleting(false) } } return ( } > {wq && ( <> 状态:{STATUS_LABELS[wq.status]} {wq.solution_text && ( )} {wq.ocr_raw_text && (
OCR 原文
                      {wq.ocr_raw_text}
                    
)} 识别题目(可编辑) setQuestionText(e.target.value)} style={{ marginTop: 8, marginBottom: 16 }} /> 解法 setSolutionText(e.target.value)} style={{ marginTop: 8, marginBottom: 12 }} /> {solutionText && (
预览 {solutionText}
)}
)}
) }