feat: 多题目评分支持

This commit is contained in:
2026-07-16 05:44:44 +08:00
parent 0532963aca
commit 31c435c410
5 changed files with 257 additions and 125 deletions
+37 -31
View File
@@ -80,6 +80,28 @@ async function selectImage() {
}
}
async function gradeQuestion(questionIdx: number) {
const questions = gradingStore.questions
if (!questions.length) {
ElMessage.warning('请先在评分标准中添加题目')
return null
}
const q = questions[Math.min(questionIdx, questions.length - 1)]
const result = await window.electronAPI.ai.grade({
imageBase64: gradingStore.currentImage,
rubric: q.rubric || `请根据答案内容评分,满分${q.maxScore}`,
maxScore: q.maxScore,
referenceAnswer: q.referenceAnswer,
questionTitle: q.questionTitle,
apiConfig: {
apiKey: settingsStore.settings.apiKey,
baseUrl: settingsStore.settings.baseUrl,
model: settingsStore.settings.model
}
})
return result
}
async function startGrading() {
if (!gradingStore.currentImage) {
ElMessage.info('请先截图或选择图片')
@@ -91,44 +113,28 @@ async function startGrading() {
return
}
// load rubric data
const rubricData = await window.electronAPI?.rubric.getData()
const questions = rubricData?.questions?.length
? JSON.parse(JSON.stringify(rubricData.questions))
: [{ questionTitle: '', maxScore: 100, referenceAnswer: '', rubric: '' }]
gradingStore.setQuestions(questions)
gradingStore.setCurrentQuestionIndex(0)
appStore.isGrading = true
try {
// load latest rubric data from main process (may have been updated by rubric dialog)
const rubricData = await window.electronAPI?.rubric.getData()
if (rubricData) {
if (rubricData.rubric) gradingStore.setRubric(rubricData.rubric)
if (rubricData.questionTitle) gradingStore.setQuestionTitle(rubricData.questionTitle)
if (rubricData.maxScore) gradingStore.setMaxScore(rubricData.maxScore)
if (rubricData.referenceAnswer) gradingStore.setReferenceAnswer(rubricData.referenceAnswer)
}
const result = await window.electronAPI.ai.grade({
imageBase64: gradingStore.currentImage,
rubric: gradingStore.rubric || `请根据答案内容评分,满分${gradingStore.maxScore}`,
maxScore: gradingStore.maxScore,
referenceAnswer: gradingStore.referenceAnswer,
questionTitle: gradingStore.questionTitle,
apiConfig: {
apiKey: settingsStore.settings.apiKey,
baseUrl: settingsStore.settings.baseUrl,
model: settingsStore.settings.model
}
})
const q = questions[0]
const result = await gradeQuestion(0)
if (!result) return
gradingStore.setResult(result)
if (window.electronAPI) {
// store grading data for result window
await window.electronAPI.grading.storeData({
result,
image: gradingStore.currentImage,
rubric: gradingStore.rubric,
questionTitle: gradingStore.questionTitle,
maxScore: gradingStore.maxScore,
referenceAnswer: gradingStore.referenceAnswer
})
// also update rubric bridge
await window.electronAPI.rubric.storeData({
questionTitle: gradingStore.questionTitle,
maxScore: gradingStore.maxScore,
referenceAnswer: gradingStore.referenceAnswer,
rubric: gradingStore.rubric
questions,
currentQuestionIndex: 0
})
await window.electronAPI.dialog.open('result')
}