修复复盘保存失败:原地更新成绩并新增 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
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -9,7 +9,7 @@
<meta name="author" content="马建军" />
<meta name="copyright" content="Copyright (c) 马建军. All rights reserved." />
<title>中学成绩档案</title>
<script type="module" crossorigin src="/assets/index-Db1YZbA8.js"></script>
<script type="module" crossorigin src="/assets/index-C801hcLu.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BSTLtBBx.css">
</head>
<body>
+4
View File
@@ -120,6 +120,10 @@ export const examApi = {
examId: string,
data: Partial<{ exam_type: ExamType; exam_date: string; title: string; scores: ScoreInput[] }>,
) => api.patch<Exam>(`/exams/${examId}`, data),
updateReview: (
examId: string,
reviews: { subject_id: number; review_statuses: ScoreInput['review_statuses'] }[],
) => api.patch<Exam>(`/exams/${examId}/review`, { reviews }),
remove: (examId: string) => api.delete(`/exams/${examId}`),
trend: (studentId: string, subjectId: number) =>
api.get<TrendResponse>(`/students/${studentId}/scores/trend`, {
+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)
}