feat: 多题目评分支持
This commit is contained in:
+106
-44
@@ -7,6 +7,19 @@
|
||||
</div>
|
||||
|
||||
<div class="drawer-body" v-if="gradingStore.currentResult">
|
||||
<div class="question-nav" v-if="questions.length > 1">
|
||||
<el-button size="small" @click="prevQuestion" :disabled="isGrading">上一题</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>
|
||||
</div>
|
||||
|
||||
<div class="question-title" v-if="currentQuestion.questionTitle">
|
||||
{{ currentQuestion.questionTitle }}
|
||||
</div>
|
||||
<div class="question-maxscore" v-if="currentQuestion.maxScore">
|
||||
满分:{{ currentQuestion.maxScore }}
|
||||
</div>
|
||||
|
||||
<div class="result-score">
|
||||
<div class="score-value">{{ gradingStore.currentResult.score }}</div>
|
||||
<div class="score-label">建议分数</div>
|
||||
@@ -34,29 +47,18 @@
|
||||
<div class="result-section">
|
||||
<div class="section-title">教师评分(可修改)</div>
|
||||
<div class="teacher-score-input">
|
||||
<el-input-number
|
||||
v-model="teacherScore"
|
||||
:min="0"
|
||||
:max="100"
|
||||
size="small"
|
||||
/>
|
||||
<el-input-number v-model="teacherScore" :min="0" :max="currentQuestion.maxScore" size="small" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="result-section">
|
||||
<div class="section-title">教师评语</div>
|
||||
<el-input
|
||||
v-model="teacherComment"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
size="small"
|
||||
placeholder="输入评语(可选)"
|
||||
/>
|
||||
<el-input v-model="teacherComment" type="textarea" :rows="2" size="small" placeholder="输入评语(可选)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-footer">
|
||||
<el-button size="small" @click="reGrade">重新评分</el-button>
|
||||
<el-button size="small" @click="reGrade" :loading="isGrading">重新评分</el-button>
|
||||
<el-button type="primary" size="small" @click="confirmScore">确认评分</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -65,23 +67,30 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, watch } from 'vue'
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { useGradingStore } from '@/stores/grading'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import type { QuestionItem } from '@/types'
|
||||
|
||||
const appStore = useAppStore()
|
||||
const gradingStore = useGradingStore()
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
const visible = ref(false)
|
||||
const isGrading = ref(false)
|
||||
const teacherScore = ref(0)
|
||||
const teacherComment = ref('')
|
||||
const questions = ref<QuestionItem[]>([])
|
||||
const currentIdx = ref(0)
|
||||
|
||||
const currentQuestion = computed(() => questions.value[currentIdx.value] || { questionTitle: '', maxScore: 100, referenceAnswer: '', rubric: '' })
|
||||
|
||||
watch(() => appStore.isResultDrawerOpen, (val) => {
|
||||
visible.value = val
|
||||
})
|
||||
|
||||
// load grading data from bridge when result window opens
|
||||
watch(() => gradingStore.currentResult, (val) => {
|
||||
if (val) {
|
||||
teacherScore.value = val.score
|
||||
@@ -89,20 +98,40 @@ watch(() => gradingStore.currentResult, (val) => {
|
||||
}
|
||||
})
|
||||
|
||||
// listen for grading data when window becomes visible
|
||||
watch(visible, async (val) => {
|
||||
if (val) {
|
||||
const data = await window.electronAPI?.grading.getData()
|
||||
if (data) {
|
||||
gradingStore.setImage(data.image || '')
|
||||
if (data.questions) {
|
||||
questions.value = JSON.parse(JSON.stringify(data.questions))
|
||||
gradingStore.setQuestions(data.questions)
|
||||
}
|
||||
currentIdx.value = data.currentQuestionIndex ?? 0
|
||||
gradingStore.setCurrentQuestionIndex(currentIdx.value)
|
||||
if (data.result) {
|
||||
gradingStore.setResult(data.result)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function closeDrawer() {
|
||||
window.electronAPI?.dialog.close()
|
||||
}
|
||||
|
||||
async function reGrade() {
|
||||
async function gradeAt(idx: number) {
|
||||
if (!gradingStore.currentImage) return
|
||||
appStore.isGrading = true
|
||||
isGrading.value = true
|
||||
try {
|
||||
const q = questions.value[idx]
|
||||
const result = await window.electronAPI.ai.grade({
|
||||
imageBase64: gradingStore.currentImage,
|
||||
rubric: gradingStore.rubric || `请根据答案内容评分,满分${gradingStore.maxScore}分`,
|
||||
maxScore: gradingStore.maxScore,
|
||||
referenceAnswer: gradingStore.referenceAnswer,
|
||||
questionTitle: gradingStore.questionTitle,
|
||||
rubric: q.rubric || `请根据答案内容评分,满分${q.maxScore}分`,
|
||||
maxScore: q.maxScore,
|
||||
referenceAnswer: q.referenceAnswer,
|
||||
questionTitle: q.questionTitle,
|
||||
apiConfig: {
|
||||
apiKey: settingsStore.settings.apiKey,
|
||||
baseUrl: settingsStore.settings.baseUrl,
|
||||
@@ -110,14 +139,42 @@ async function reGrade() {
|
||||
}
|
||||
})
|
||||
gradingStore.setResult(result)
|
||||
ElMessage.success('重新评分完成')
|
||||
currentIdx.value = idx
|
||||
gradingStore.setCurrentQuestionIndex(idx)
|
||||
// update rubric bridge currentIndex
|
||||
await window.electronAPI?.rubric.storeData({
|
||||
questions: questions.value,
|
||||
currentIndex: idx
|
||||
})
|
||||
// update grading bridge
|
||||
await window.electronAPI?.grading.storeData({
|
||||
result,
|
||||
image: gradingStore.currentImage,
|
||||
questions: questions.value,
|
||||
currentQuestionIndex: idx
|
||||
})
|
||||
ElMessage.success(`第 ${idx + 1} 题评分完成`)
|
||||
} catch (err) {
|
||||
ElMessage.error('重新评分失败:' + (err as Error).message)
|
||||
ElMessage.error('评分失败:' + (err as Error).message)
|
||||
} finally {
|
||||
appStore.isGrading = false
|
||||
isGrading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function nextQuestion() {
|
||||
const next = (currentIdx.value + 1) % questions.value.length
|
||||
await gradeAt(next)
|
||||
}
|
||||
|
||||
async function prevQuestion() {
|
||||
const prev = (currentIdx.value - 1 + questions.value.length) % questions.value.length
|
||||
await gradeAt(prev)
|
||||
}
|
||||
|
||||
async function reGrade() {
|
||||
await gradeAt(currentIdx.value)
|
||||
}
|
||||
|
||||
async function confirmScore() {
|
||||
const result = gradingStore.currentResult
|
||||
if (!result) return
|
||||
@@ -149,16 +206,14 @@ async function confirmScore() {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.drawer-panel {
|
||||
width: 360px;
|
||||
width: 400px;
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.drawer-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -166,79 +221,88 @@ async function confirmScore() {
|
||||
padding: 16px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.drawer-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.drawer-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.question-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.question-indicator {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #409EFF;
|
||||
}
|
||||
.question-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.question-maxscore {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.result-score {
|
||||
text-align: center;
|
||||
padding: 20px 0;
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.score-value {
|
||||
font-size: 48px;
|
||||
font-weight: 700;
|
||||
color: #409EFF;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.score-label {
|
||||
font-size: 13px;
|
||||
color: #999;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.result-confidence {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.confidence-bar {
|
||||
height: 6px;
|
||||
background: #eee;
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.confidence-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #67C23A, #409EFF);
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
.confidence-text {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-top: 4px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.result-section {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.deduction-item {
|
||||
font-size: 13px;
|
||||
color: #F56C6C;
|
||||
padding: 4px 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.comment-text {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
@@ -247,11 +311,9 @@ async function confirmScore() {
|
||||
padding: 10px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.teacher-score-input {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.drawer-footer {
|
||||
padding: 12px 16px;
|
||||
border-top: 1px solid #eee;
|
||||
@@ -259,4 +321,4 @@ async function confirmScore() {
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user