修复复盘保存失败:原地更新成绩并新增 review 专用接口。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-28 16:38:20 +08:00
parent ff4e0b1d37
commit bec9df5d6f
6 changed files with 128 additions and 37 deletions
+17 -7
View File
@@ -5,6 +5,17 @@ import type { Exam, ReviewStatus } from '../types'
import { EXAM_TYPE_LABELS, REVIEW_STATUS_OPTIONS } from '../types'
import ReviewTreeChart from './ReviewTreeChart'
function apiErrorMessage(err: unknown, fallback: string): string {
if (err && typeof err === 'object' && 'response' in err) {
const detail = (err as { response?: { data?: { detail?: unknown } } }).response?.data?.detail
if (typeof detail === 'string') return detail
if (Array.isArray(detail)) {
return detail.map((item) => item?.msg || String(item)).join('')
}
}
return fallback
}
interface Props {
exams: Exam[]
onRefresh: () => void
@@ -53,18 +64,17 @@ export default function ExamReviewPanel({ exams, onRefresh }: Props) {
}
setSaving(true)
try {
await examApi.update(selectedExam.id, {
scores: selectedExam.scores.map((score) => ({
await examApi.updateReview(
selectedExam.id,
selectedExam.scores.map((score) => ({
subject_id: score.subject_id,
total_score: score.total_score,
obtained_score: score.obtained_score,
review_statuses: statusMap[score.subject_id] || [],
})),
})
)
message.success('复盘已保存')
onRefresh()
} catch {
message.error('保存失败')
} catch (err) {
message.error(apiErrorMessage(err, '保存失败'))
} finally {
setSaving(false)
}