diff --git a/src/components/FloatingToolbar.vue b/src/components/FloatingToolbar.vue index 5c74039..f1cda4b 100644 --- a/src/components/FloatingToolbar.vue +++ b/src/components/FloatingToolbar.vue @@ -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') } diff --git a/src/components/ResultDrawer.vue b/src/components/ResultDrawer.vue index e1ce977..0bf2ed9 100644 --- a/src/components/ResultDrawer.vue +++ b/src/components/ResultDrawer.vue @@ -7,6 +7,19 @@