fix: rubric:storeData 空数据保护防止误清

This commit is contained in:
2026-07-16 06:25:01 +08:00
parent 8dde1243d8
commit 8a6b1b39c1
+9 -3
View File
@@ -254,9 +254,14 @@ export function setupIpc(win: BrowserWindow): void {
// --- Rubric data bridge (toolbar ↔ rubric window), persisted to DB ---
ipcMain.handle('rubric:storeData', (_event, data: any) => {
const d = getDb()
const questions = data?.questions || []
// Don't clear rubric data when saving empty data (preserve existing)
if (questions.length === 0) {
rubricPayload = data
return
}
d.prepare('DELETE FROM rubric').run()
const insert = d.prepare('INSERT INTO rubric (question_title, max_score, reference_answer, rubric, sort_order) VALUES (?, ?, ?, ?, ?)')
const questions = data?.questions || []
for (let i = 0; i < questions.length; i++) {
const q = questions[i]
insert.run(q.questionTitle || '', q.maxScore ?? 100, q.referenceAnswer || '', q.rubric || '', i)
@@ -300,7 +305,7 @@ async function callAiApi(imageBase64: string, rubric: string, config: { apiKey:
deductions: string[]
comment: string
}> {
const systemRole = `你是高校阅卷专家,严格按照评分标准逐项评分。`
const systemRole = `你是高校阅卷专家,严格按照评分标准逐项评分。只输出JSON,不包含任何其他文字。`
const prompt = `${extras?.questionTitle ? `【题目】\n${extras.questionTitle}\n` : ''}【评分标准】
${rubric || '无'}
@@ -322,7 +327,8 @@ ${extras?.maxScore ?? 100}
3. 如果学生答案为空、空白或明显与题目无关,直接给0分
4. 部分正确时按评分标准酌情给分
请严格按照以下JSON格式返回结果,不要包含任何markdown标记或其他文字:
【输出要求】
只输出以下JSON,不要包含markdown代码块、\`\`\`标记、注释或任何其他文字:
{
"score": <总分>,
"confidence": <置信度0~1>,