fix: 上一题/下一题不再调 AI API,改为保存后关闭并推进索引
This commit is contained in:
@@ -314,6 +314,12 @@ export function setupIpc(win: BrowserWindow): void {
|
||||
return { questions, currentIndex: 0 }
|
||||
})
|
||||
|
||||
// --- Rubric next question index (persisted between grading cycles) ---
|
||||
let rubricNextIndex = 0
|
||||
ipcMain.handle('rubric:getNextIndex', () => rubricNextIndex)
|
||||
ipcMain.handle('rubric:setNextIndex', (_event, idx: number) => { rubricNextIndex = idx })
|
||||
ipcMain.handle('rubric:resetNextIndex', () => { rubricNextIndex = 0 })
|
||||
|
||||
// --- Grading data bridge (toolbar → result window) ---
|
||||
ipcMain.handle('grading:storeData', (_event, data: any) => {
|
||||
gradingPayload = data
|
||||
|
||||
@@ -52,7 +52,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
storeData: (data: any) => ipcRenderer.invoke('rubric:storeData', data),
|
||||
getData: () => ipcRenderer.invoke('rubric:getData'),
|
||||
exportJson: () => ipcRenderer.invoke('rubric:exportJson'),
|
||||
importJson: () => ipcRenderer.invoke('rubric:importJson')
|
||||
importJson: () => ipcRenderer.invoke('rubric:importJson'),
|
||||
getNextIndex: () => ipcRenderer.invoke('rubric:getNextIndex'),
|
||||
setNextIndex: (idx: number) => ipcRenderer.invoke('rubric:setNextIndex', idx),
|
||||
resetNextIndex: () => ipcRenderer.invoke('rubric:resetNextIndex')
|
||||
},
|
||||
|
||||
template: {
|
||||
|
||||
@@ -118,12 +118,13 @@ async function startGrading() {
|
||||
const questions = rubricData?.questions?.length
|
||||
? JSON.parse(JSON.stringify(rubricData.questions))
|
||||
: [{ questionTitle: '', maxScore: 100, referenceAnswer: '', rubric: '' }]
|
||||
const nextIdx = Math.min(await window.electronAPI?.rubric.getNextIndex() ?? 0, questions.length - 1)
|
||||
gradingStore.setQuestions(questions)
|
||||
gradingStore.setCurrentQuestionIndex(0)
|
||||
gradingStore.setCurrentQuestionIndex(nextIdx)
|
||||
|
||||
appStore.isGrading = true
|
||||
try {
|
||||
const result = await gradeQuestion(0)
|
||||
const result = await gradeQuestion(nextIdx)
|
||||
if (!result) return
|
||||
|
||||
gradingStore.setResult(result)
|
||||
@@ -133,7 +134,7 @@ async function startGrading() {
|
||||
result,
|
||||
image: gradingStore.currentImage,
|
||||
questions,
|
||||
currentQuestionIndex: 0
|
||||
currentQuestionIndex: nextIdx
|
||||
})
|
||||
await window.electronAPI.dialog.open('result')
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
<div class="drawer-body" v-if="gradingStore.currentResult">
|
||||
<div class="error-message" v-if="errorMsg">{{ errorMsg }}</div>
|
||||
<div class="question-nav" v-if="questions.length > 1">
|
||||
<el-button size="small" @click="prevQuestion" :disabled="isGrading">上一题</el-button>
|
||||
<el-button size="small" @click="prevQuestion">上一题</el-button>
|
||||
<span class="question-indicator">{{ currentIdx + 1 }} / {{ questions.length }}</span>
|
||||
<el-button size="small" @click="nextQuestion" :disabled="isGrading">{{ currentIdx === questions.length - 1 ? '回到首题' : '下一题' }}</el-button>
|
||||
<el-button size="small" @click="nextQuestion">{{ currentIdx === questions.length - 1 ? '回到首题' : '下一题' }}</el-button>
|
||||
</div>
|
||||
|
||||
<div class="question-title" v-if="currentQuestion.questionTitle">
|
||||
@@ -153,7 +153,6 @@ async function gradeAt(idx: number) {
|
||||
gradingStore.setResult(result)
|
||||
currentIdx.value = idx
|
||||
gradingStore.setCurrentQuestionIndex(idx)
|
||||
// update grading bridge
|
||||
await window.electronAPI?.grading.storeData({
|
||||
result,
|
||||
image: gradingStore.currentImage,
|
||||
@@ -170,12 +169,30 @@ async function gradeAt(idx: number) {
|
||||
|
||||
async function nextQuestion() {
|
||||
const next = (currentIdx.value + 1) % questions.value.length
|
||||
await gradeAt(next)
|
||||
await saveAndAdvance(next)
|
||||
}
|
||||
|
||||
async function prevQuestion() {
|
||||
const prev = (currentIdx.value - 1 + questions.value.length) % questions.value.length
|
||||
await gradeAt(prev)
|
||||
await saveAndAdvance(prev)
|
||||
}
|
||||
|
||||
async function saveAndAdvance(targetIdx: number) {
|
||||
try {
|
||||
await window.electronAPI.grading.submit({
|
||||
questionId: 0,
|
||||
imagePath: '',
|
||||
aiScore: gradingStore.currentResult?.score ?? 0,
|
||||
teacherScore: teacherScore.value,
|
||||
confidence: gradingStore.currentResult?.confidence ?? 0,
|
||||
studentAnswer: ''
|
||||
})
|
||||
await window.electronAPI?.rubric.setNextIndex(targetIdx)
|
||||
gradingStore.reset()
|
||||
closeDrawer()
|
||||
} catch (err) {
|
||||
ElMessage.error('保存失败:' + (err as Error).message)
|
||||
}
|
||||
}
|
||||
|
||||
async function reGrade() {
|
||||
|
||||
@@ -96,6 +96,7 @@ async function handleSave() {
|
||||
questions: JSON.parse(JSON.stringify(questions.value)),
|
||||
currentIndex: 0
|
||||
})
|
||||
await window.electronAPI?.rubric.resetNextIndex()
|
||||
ElMessage.success('评分标准已保存')
|
||||
} catch (err) {
|
||||
ElMessage.error('保存失败:' + (err as Error).message)
|
||||
|
||||
@@ -83,6 +83,9 @@ export interface ElectronAPI {
|
||||
getData: () => Promise<any>
|
||||
exportJson: () => Promise<boolean>
|
||||
importJson: () => Promise<{ questions: QuestionItem[]; currentIndex: number } | null>
|
||||
getNextIndex: () => Promise<number>
|
||||
setNextIndex: (idx: number) => Promise<void>
|
||||
resetNextIndex: () => Promise<void>
|
||||
}
|
||||
template: {
|
||||
list: () => Promise<unknown[]>
|
||||
|
||||
Reference in New Issue
Block a user