feat(training): 完善安全培训题库与考试交互

修复 PDF 导入判断和填空题解析,支持文本题判分、回顾改答及安全培训三级流程校验。
This commit is contained in:
runny committed 2026-08-18 01:12:04 +08:00
1 parent ec4ed9b67d
commit e62e4961d4
19 files changed
+721 -48

No files matched your search

@@ -216,9 +216,16 @@ const expandCurrentWorkspace = () => {
const currentAnswerLabel = computed(() => {
const question = workspace.currentQuestion;
if (!question) return '';
if (question.type === 'fill' || question.type === 'essay') return workspace.answerText;
return question.options?.find((item) => item.id === workspace.selectedOptionId)?.label || '';
});
const isTextQuestion = computed(() => ['fill', 'essay'].includes(workspace.currentQuestion?.type || ''));
const isTextFeedbackPending = computed(() => (
workspace.currentQuestion?.type === 'essay'
|| (workspace.currentQuestion?.type === 'fill' && !workspace.currentQuestion.answer)
));
const trainingExamPdfGuide = computed(() => resolveTrainingExamPdfGuide(props.agentGuides));
const workspaceExpanded = ref(false);
@@ -747,7 +754,25 @@ const currentSafetyStageText = computed(() => {
</div>
</div>
<div class="mt-2.5 grid gap-2">
<div v-if="isTextQuestion" class="mt-2.5 grid gap-2">
<textarea
v-model="workspace.answerText"
:disabled="workspace.currentQuestion.type === 'essay' && workspace.answerLocked"
:rows="workspace.currentQuestion.type === 'essay' ? 5 : 3"
class="w-full rounded-2xl border border-default bg-white px-3.5 py-2 text-sm leading-6 text-primary outline-none transition focus:border-brand-400 focus:ring-2 focus:ring-brand-100 disabled:bg-surface-soft"
:placeholder="$t(workspace.currentQuestion.type === 'essay' ? 'chat.training.exam.essayPlaceholder' : 'chat.training.exam.fillPlaceholder')"
/>
<button
v-if="!workspace.answerLocked"
type="button"
:disabled="!workspace.answerText.trim()"
class="justify-self-start rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-50"
@click="workspace.submitTextAnswer()"
>
{{ $t('chat.training.exam.submitTextAnswer') }}
</button>
</div>
<div v-else class="mt-2.5 grid gap-2">
<button
v-for="option in workspace.currentQuestion.options"
:key="option.id"
@@ -776,20 +801,25 @@ const currentSafetyStageText = computed(() => {
</button>
</div>
<div
v-if="workspace.answerLocked"
class="mt-3 rounded-2xl border p-3"
:class="workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
>
<div class="flex items-center gap-2 text-sm font-semibold" :class="workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'">
<CheckCircle2 v-if="workspace.currentFeedbackCorrect" class="h-4 w-4" />
<XCircle v-else class="h-4 w-4" />
{{ workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
</div>
<div
v-if="workspace.answerLocked"
class="mt-3 rounded-2xl border p-3"
:class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
>
<div class="flex items-center gap-2 text-sm font-semibold" :class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'"">
<CheckCircle2 v-if="isTextFeedbackPending || workspace.currentFeedbackCorrect" class="h-4 w-4" />
<XCircle v-else class="h-4 w-4" />
{{ isTextFeedbackPending ? $t('chat.training.exam.textAnswerRecorded') : workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
</div>
<div class="mt-2 text-sm leading-6 text-secondary">
{{ $t('chat.training.exam.selectedAnswer', { answer: currentAnswerLabel || '--' }) }}
</div>
<div class="mt-1 text-sm leading-6 text-secondary">
<div v-if="isTextQuestion" class="mt-1 text-sm leading-6 text-secondary">
{{ workspace.currentQuestion.type === 'fill' && workspace.currentQuestion.answer
? $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.answer })
: $t('chat.training.exam.textAnswerRecorded') }}
</div>
<div v-else class="mt-1 text-sm leading-6 text-secondary">
{{ $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.options?.find((item) => item.id === workspace.currentQuestion?.answer)?.label || '--' }) }}
</div>
<div class="mt-2 text-sm leading-6 text-secondary">
@@ -1056,7 +1086,25 @@ const currentSafetyStageText = computed(() => {
</div>
</div>
<div class="mt-2.5 grid gap-2">
<div v-if="isTextQuestion" class="mt-2.5 grid gap-2">
<textarea
v-model="workspace.answerText"
:disabled="workspace.currentQuestion.type === 'essay' && workspace.answerLocked"
:rows="workspace.currentQuestion.type === 'essay' ? 5 : 3"
class="w-full rounded-2xl border border-default bg-white px-3.5 py-2 text-sm leading-6 text-primary outline-none transition focus:border-brand-400 focus:ring-2 focus:ring-brand-100 disabled:bg-surface-soft"
:placeholder="$t(workspace.currentQuestion.type === 'essay' ? 'chat.training.exam.essayPlaceholder' : 'chat.training.exam.fillPlaceholder')"
/>
<button
v-if="workspace.currentQuestion.type === 'fill' || !workspace.answerLocked"
type="button"
:disabled="!workspace.answerText.trim()"
class="justify-self-start rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-50"
@click="workspace.submitTextAnswer()"
>
{{ $t('chat.training.exam.submitTextAnswer') }}
</button>
</div>
<div v-else class="mt-2.5 grid gap-2">
<button
v-for="option in workspace.currentQuestion.options"
:key="option.id"
@@ -1088,17 +1136,22 @@ const currentSafetyStageText = computed(() => {
<div
v-if="workspace.answerLocked"
class="mt-3 rounded-2xl border p-3"
:class="workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
:class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
>
<div class="flex items-center gap-2 text-sm font-semibold" :class="workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'">
<CheckCircle2 v-if="workspace.currentFeedbackCorrect" class="h-4 w-4" />
<div class="flex items-center gap-2 text-sm font-semibold" :class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'"">
<CheckCircle2 v-if="isTextFeedbackPending || workspace.currentFeedbackCorrect" class="h-4 w-4" />
<XCircle v-else class="h-4 w-4" />
{{ workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
{{ isTextFeedbackPending ? $t('chat.training.exam.textAnswerRecorded') : workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
</div>
<div class="mt-2 text-sm leading-6 text-secondary">
{{ $t('chat.training.exam.selectedAnswer', { answer: currentAnswerLabel || '--' }) }}
</div>
<div class="mt-1 text-sm leading-6 text-secondary">
<div v-if="isTextQuestion" class="mt-1 text-sm leading-6 text-secondary">
{{ workspace.currentQuestion.type === 'fill' && workspace.currentQuestion.answer
? $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.answer })
: $t('chat.training.exam.textAnswerRecorded') }}
</div>
<div v-else class="mt-1 text-sm leading-6 text-secondary">
{{ $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.options?.find((item) => item.id === workspace.currentQuestion?.answer)?.label || '--' }) }}
</div>
<div class="mt-2 text-sm leading-6 text-secondary">