feat(training-workspace): 优化员工培训工作区考试交互与展示

This commit is contained in:
runny committed 2026-07-09 13:19:17 +08:00
1 parent 8bd66baa21
commit 61acbe50a7
7 files changed
+49 -23

No files matched your search

@@ -341,16 +341,10 @@ const handleStageCardClick = (stageKey: string) => {
<div class="truncate text-sm font-semibold text-primary">
{{ compactSummary }}
</div>
<div class="mt-1 text-xs leading-5 text-secondary">
<template v-if="workspace.activeView === 'admin'">
{{ $t('chat.training.hr.filters.keywordLabel') }}: {{ workspace.hrKeyword || $t('chat.training.hr.filters.noLimit') }}
· {{ $t('chat.training.hr.filters.departmentLabel') }}:
{{ workspace.hrDepartmentFilter === 'all' ? $t('chat.training.hr.filters.allDepartments') : workspace.hrDepartmentFilter }}
</template>
<template v-else>
{{ $t('chat.training.progressPercent') }}: {{ workspace.learnerProgressPercent }}%
· {{ $t('chat.training.learnerCard.name') }}: {{ workspace.currentUserName }}
</template>
<div v-if="workspace.activeView === 'admin'" class="mt-1 text-xs leading-5 text-secondary">
{{ $t('chat.training.hr.filters.keywordLabel') }}: {{ workspace.hrKeyword || $t('chat.training.hr.filters.noLimit') }}
· {{ $t('chat.training.hr.filters.departmentLabel') }}:
{{ workspace.hrDepartmentFilter === 'all' ? $t('chat.training.hr.filters.allDepartments') : workspace.hrDepartmentFilter }}
</div>
<div
v-if="workspace.activeView === 'learner'"
@@ -539,7 +533,6 @@ const handleStageCardClick = (stageKey: string) => {
? 'border-emerald-300 bg-emerald-50 text-emerald-700'
: 'border-default bg-white text-secondary hover:border-brand-200 hover:bg-brand-50/40',
]"
:disabled="workspace.answerLocked"
@click="workspace.selectAnswer(option.id)"
>
<div class="flex items-start justify-between gap-3">
@@ -138,7 +138,7 @@ const emit = defineEmits<{
? 'border-emerald-200 bg-emerald-50/50 text-emerald-600'
: 'border-slate-200 bg-white text-slate-600 hover:border-brand-200 hover:bg-brand-50/30 hover:text-brand-700',
]"
:disabled="answerLocked || isThinking"
:disabled="isThinking"
@click="emit('select', option.id)"
>
<span class="font-medium">{{ option.label }}</span>
@@ -305,6 +305,29 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
].join('\n');
};
/**
* 基于当前答题记录重算成绩,保证“修改答案”后分数与结果页口径一致。
* AI 触发时机:当培训考试支持点击题号返回修改答案时,不能再用“上一题答对就直接 +1”的增量算法。
*/
const recalculateScoreFromAnswers = (records: TrainingAnswerRecord[]) => calculateTrainingScore(
records.filter((item) => item.correct).length,
totalQuestionCount.value,
);
/**
* 覆盖或新增当前题的作答记录,避免同一道题在进度里出现重复答案。
* AI 触发时机:当员工返回已答题修改答案时,必须覆盖旧答案而不是重复追加,否则分数和已答题数都会失真。
*/
const upsertAnswerRecord = (nextRecord: TrainingAnswerRecord) => {
const existingIndex = answerRecords.value.findIndex((item) => item.questionId === nextRecord.questionId);
if (existingIndex >= 0) {
answerRecords.value.splice(existingIndex, 1, nextRecord);
return true;
}
answerRecords.value.push(nextRecord);
return false;
};
const syncAnswerStateForCurrentQuestion = () => {
const questionId = currentQuestion.value?.id;
const currentAnswer = questionId
@@ -531,31 +554,41 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
void persistProgress();
};
/**
* 记录当前题答案;首次作答沿用自动推进,回看题目时则覆盖旧答案并实时重算分数。
* AI 触发时机:当员工在逐题考试阶段点击右侧题号返回某题时,需要允许直接改答且不破坏“提交答卷后才结算”的流程。
*/
const selectAnswer = (optionId: string) => {
if (answerLocked.value || !currentQuestion.value) return;
if (!currentQuestion.value) return;
const answeredQuestion = currentQuestion.value;
const hadExistingAnswer = answerRecords.value.some((item) => item.questionId === answeredQuestion.id);
selectedOptionId.value = optionId;
answerLocked.value = true;
const isCorrect = optionId === answeredQuestion.answer;
currentFeedbackCorrect.value = isCorrect;
const nextCorrectAnswerCount = correctCount.value + (isCorrect ? 1 : 0);
const nextScore = calculateTrainingScore(nextCorrectAnswerCount, totalQuestionCount.value);
score.value = nextScore;
const answerRecord: TrainingAnswerRecord = {
questionId: answeredQuestion.id,
selectedOptionId: optionId,
correct: isCorrect,
};
answerRecords.value.push(answerRecord);
upsertAnswerRecord(answerRecord);
const nextScore = recalculateScoreFromAnswers(answerRecords.value);
score.value = nextScore;
latestExamFeedback.value = buildExamFeedback(answeredQuestion, answerRecord, nextScore);
// [STEP 1] 最后一题答完后先停留在考试阶段,必须点击“提交答卷”才能进入结算结果。
// [STEP 1] 已答题被回看并改答时,停留在当前题,方便继续检查或跳到其他题。
if (hadExistingAnswer) {
void persistProgress();
return;
}
// [STEP 2] 最后一题首次答完后先停留在考试阶段,必须点击“提交答卷”才能进入结算结果。
if (currentQuestionIndex.value >= totalQuestionCount.value - 1) {
void persistProgress();
return;
}
// [STEP 2] 非最后一题则在聊天流里自动反馈上一题,并紧接着展示下一题。
// [STEP 3] 首次作答且不是最后一题时,自动推进到下一题。
syncExamQuestionIndex(currentQuestionIndex.value + 1);
void persistProgress();
};
+1 -1
View File
@@ -552,7 +552,7 @@
},
"examQuestionCard": {
"title": "Exam Questions",
"hint": "Shows all question numbers. They become clickable only during the step-by-step exam stage."
"hint": "Shows all question numbers. They become clickable only during the step-by-step exam stage, and answered questions can be revisited and changed."
},
"rules": {
"title": "Exam rules",
+1 -1
View File
@@ -552,7 +552,7 @@
},
"examQuestionCard": {
"title": "ข้อสอบ",
"hint": "แสดงหมายเลขข้อทั้งหมด และจะกดได้เฉพาะในขั้นตอนสอบทีละข้อเท่านั้น"
"hint": "แสดงหมายเลขข้อทั้งหมด และจะกดได้เฉพาะในขั้นตอนสอบทีละข้อเท่านั้น พร้อมรองรับการย้อนกลับไปแก้คำตอบ"
},
"rules": {
"title": "กติกาการสอบ",
+1 -1
View File
@@ -552,7 +552,7 @@
},
"examQuestionCard": {
"title": "考试题目",
"hint": "展示全部题目序号;仅在“逐题考试”阶段可点击切换。"
"hint": "展示全部题目序号;仅在“逐题考试”阶段可点击切换,并支持返回修改答案。"
},
"rules": {
"title": "考试规则",
+1 -1
View File
@@ -552,7 +552,7 @@
},
"examQuestionCard": {
"title": "考試題目",
"hint": "顯示全部題目序號;僅在「逐題考試」階段可點擊切換。"
"hint": "展示全部題目序號;僅在“逐題考試”階段可點擊切換,並支援返回修改答案。"
},
"rules": {
"title": "考試規則",