feat(training-workspace): 培训考试增加提交答卷后再进入结算结果

feat(training-workspace): 完善员工培训工作区考试流转与配置交互
This commit is contained in:
runny committed 2026-07-09 12:03:57 +08:00
1 parent 5bef77f86c
commit 8bd66baa21
8 files changed
+78 -29

No files matched your search

@@ -38,6 +38,7 @@ def build_dify_inputs_for_context(ctx: ChatStreamContext) -> dict[str, Any]:
session_id=str(getattr(ctx.session, 'session_id', '') or ''), session_id=str(getattr(ctx.session, 'session_id', '') or ''),
request_id=ctx.request_id, request_id=ctx.request_id,
trigger_source='frontend_chat', trigger_source='frontend_chat',
user_role=str(getattr(ctx.user, 'role', '') or '').strip() or None,
adapter_hints=ctx.adapter_hints, adapter_hints=ctx.adapter_hints,
) )
@@ -531,6 +531,7 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
{{ form.training_workspace_enabled ? t('admin.agent.training.enableHint') : t('admin.agent.training.disabledHint') }} {{ form.training_workspace_enabled ? t('admin.agent.training.enableHint') : t('admin.agent.training.disabledHint') }}
</p> </p>
<template v-if="form.training_workspace_enabled">
<div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-3"> <div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-3">
<div class="space-y-2"> <div class="space-y-2">
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.passScore') }}</label> <label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.passScore') }}</label>
@@ -725,6 +726,7 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
</div> </div>
</div> </div>
</div> </div>
</template>
</div> </div>
<AgentToolRunProgressConfig <AgentToolRunProgressConfig
@@ -138,7 +138,7 @@ const compactSummary = computed(() => {
if (workspace.stage === 'summary') return t('chat.training.summary.title'); if (workspace.stage === 'summary') return t('chat.training.summary.title');
if (workspace.stage === 'exam') { if (workspace.stage === 'exam') {
return t('chat.training.exam.questionCounter', { return t('chat.training.exam.questionCounter', {
current: workspace.answeredCount + 1, current: workspace.currentQuestionNumber,
total: workspace.totalQuestionCount, total: workspace.totalQuestionCount,
}); });
} }
@@ -165,7 +165,15 @@ const examQuestionItems = computed(() => Array.from({ length: workspace.totalQue
const canNavigateExamQuestions = computed(() => workspace.stage === 'exam'); const canNavigateExamQuestions = computed(() => workspace.stage === 'exam');
const jumpToExamQuestion = (index: number) => { const jumpToExamQuestion = (index: number) => {
if (!canNavigateExamQuestions.value) return; if (!canNavigateExamQuestions.value) return;
workspace.currentQuestionIndex = index; workspace.syncExamQuestionIndex(index);
};
const canSwitchToStage = (stageKey: string) => {
if (stageKey !== 'result') return true;
return workspace.canEnterResultStage;
};
const handleStageCardClick = (stageKey: string) => {
if (!canSwitchToStage(stageKey)) return;
workspace.stage = stageKey as typeof workspace.stage;
}; };
</script> </script>
@@ -387,8 +395,11 @@ const jumpToExamQuestion = (index: number) => {
v-for="(item, index) in stageItems" v-for="(item, index) in stageItems"
:key="item.key" :key="item.key"
class="rounded-xl border px-3 py-2.5 transition cursor-pointer hover:border-brand-300" class="rounded-xl border px-3 py-2.5 transition cursor-pointer hover:border-brand-300"
:class="stageStep >= index + 1 ? 'border-brand-200 bg-brand-50/70' : 'border-default bg-surface-soft/70'" :class="[
@click="workspace.stage = item.key as any" stageStep >= index + 1 ? 'border-brand-200 bg-brand-50/70' : 'border-default bg-surface-soft/70',
canSwitchToStage(String(item.key)) ? 'cursor-pointer hover:border-brand-300' : 'cursor-not-allowed opacity-60',
]"
@click="handleStageCardClick(String(item.key))"
> >
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<div <div
@@ -492,7 +503,7 @@ const jumpToExamQuestion = (index: number) => {
{{ $t('chat.training.exam.title') }} {{ $t('chat.training.exam.title') }}
</div> </div>
<h3 class="mt-1 text-lg font-semibold text-primary"> <h3 class="mt-1 text-lg font-semibold text-primary">
{{ $t('chat.training.exam.questionCounter', { current: workspace.answeredCount + 1, total: workspace.totalQuestionCount }) }} {{ $t('chat.training.exam.questionCounter', { current: workspace.currentQuestionNumber, total: workspace.totalQuestionCount }) }}
</h3> </h3>
</div> </div>
<div class="flex flex-wrap gap-2 text-sm text-secondary"> <div class="flex flex-wrap gap-2 text-sm text-secondary">
@@ -564,12 +575,12 @@ const jumpToExamQuestion = (index: number) => {
<button <button
type="button" type="button"
class="inline-flex items-center gap-2 rounded-xl bg-brand-600 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-brand-700" class="inline-flex items-center gap-2 rounded-xl bg-brand-600 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-brand-700"
@click="workspace.moveToNextQuestion" @click="workspace.examReadyToSubmit ? workspace.submitExam() : workspace.moveToNextQuestion()"
> >
<ClipboardCheck class="h-4 w-4" /> <ClipboardCheck class="h-4 w-4" />
{{ {{
workspace.answeredCount >= workspace.totalQuestionCount workspace.examReadyToSubmit
? $t('chat.training.exam.finishExam') ? $t('chat.training.exam.submitPaper')
: $t('chat.training.exam.nextQuestion') : $t('chat.training.exam.nextQuestion')
}} }}
</button> </button>
@@ -199,10 +199,20 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
const currentQuestion = computed(() => questionBank.value[currentQuestionIndex.value] || null); const currentQuestion = computed(() => questionBank.value[currentQuestionIndex.value] || null);
const totalQuestionCount = computed(() => questionBank.value.length); const totalQuestionCount = computed(() => questionBank.value.length);
const currentQuestionNumber = computed(() => {
if (totalQuestionCount.value <= 0) return 0;
return Math.min(currentQuestionIndex.value + 1, totalQuestionCount.value);
});
const answeredCount = computed(() => answerRecords.value.length); const answeredCount = computed(() => answerRecords.value.length);
const correctCount = computed(() => answerRecords.value.filter((item) => item.correct).length); const correctCount = computed(() => answerRecords.value.filter((item) => item.correct).length);
const wrongCount = computed(() => answerRecords.value.filter((item) => !item.correct).length); const wrongCount = computed(() => answerRecords.value.filter((item) => !item.correct).length);
const isPassed = computed(() => score.value >= passScore.value); const isPassed = computed(() => score.value >= passScore.value);
const examReadyToSubmit = computed(() => (
stage.value === 'exam'
&& totalQuestionCount.value > 0
&& answeredCount.value >= totalQuestionCount.value
));
const canEnterResultStage = computed(() => stage.value === 'result');
const learnerProgressPercent = computed(() => { const learnerProgressPercent = computed(() => {
if (stage.value === 'video') return 25; if (stage.value === 'video') return 25;
@@ -305,6 +315,21 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
currentFeedbackCorrect.value = Boolean(currentAnswer?.correct); currentFeedbackCorrect.value = Boolean(currentAnswer?.correct);
}; };
/**
* 切换考试题目时,同步左侧题干、已答状态和反馈展示。
* AI 触发时机:当员工点击右侧题号导航或后端恢复考试进度时,必须保证“当前题序号、选中项、答题对错反馈”完全一致。
*/
const syncExamQuestionIndex = (nextIndex: number) => {
if (totalQuestionCount.value <= 0) {
currentQuestionIndex.value = 0;
syncAnswerStateForCurrentQuestion();
return;
}
const normalizedIndex = Math.min(Math.max(nextIndex, 0), totalQuestionCount.value - 1);
currentQuestionIndex.value = normalizedIndex;
syncAnswerStateForCurrentQuestion();
};
const applyProgressRecord = (record: TrainingProgressRecord | null) => { const applyProgressRecord = (record: TrainingProgressRecord | null) => {
if (!record) { if (!record) {
stage.value = 'video'; stage.value = 'video';
@@ -314,7 +339,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
return; return;
} }
stage.value = record.stage; stage.value = record.stage;
currentQuestionIndex.value = record.currentQuestionIndex; syncExamQuestionIndex(record.currentQuestionIndex);
score.value = Number(record.score || 0); score.value = Number(record.score || 0);
attemptCount.value = Number(record.attempts || 0); attemptCount.value = Number(record.attempts || 0);
answerRecords.value = Array.isArray(record.answerDetails) ? record.answerDetails : []; answerRecords.value = Array.isArray(record.answerDetails) ? record.answerDetails : [];
@@ -510,6 +535,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
if (answerLocked.value || !currentQuestion.value) return; if (answerLocked.value || !currentQuestion.value) return;
const answeredQuestion = currentQuestion.value; const answeredQuestion = currentQuestion.value;
selectedOptionId.value = optionId; selectedOptionId.value = optionId;
answerLocked.value = true;
const isCorrect = optionId === answeredQuestion.answer; const isCorrect = optionId === answeredQuestion.answer;
currentFeedbackCorrect.value = isCorrect; currentFeedbackCorrect.value = isCorrect;
const nextCorrectAnswerCount = correctCount.value + (isCorrect ? 1 : 0); const nextCorrectAnswerCount = correctCount.value + (isCorrect ? 1 : 0);
@@ -523,25 +549,14 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
answerRecords.value.push(answerRecord); answerRecords.value.push(answerRecord);
latestExamFeedback.value = buildExamFeedback(answeredQuestion, answerRecord, nextScore); latestExamFeedback.value = buildExamFeedback(answeredQuestion, answerRecord, nextScore);
// [STEP 1] 最后一题直接进入结算,对齐文档里的“答完即公布最终成绩”。 // [STEP 1] 最后一题答完后先停留在考试阶段,必须点击“提交答卷”才能进入结算结果。
if (currentQuestionIndex.value >= totalQuestionCount.value - 1) { if (currentQuestionIndex.value >= totalQuestionCount.value - 1) {
stage.value = 'result';
completionDate.value = formatDate(new Date());
latestSettledResult.value = {
score: nextScore,
correctCount: answerRecords.value.filter((item) => item.correct).length,
wrongCount: answerRecords.value.filter((item) => !item.correct).length,
isPassed: nextScore >= passScore.value,
};
void persistProgress(); void persistProgress();
return; return;
} }
// [STEP 2] 非最后一题则在聊天流里自动反馈上一题,并紧接着展示下一题。 // [STEP 2] 非最后一题则在聊天流里自动反馈上一题,并紧接着展示下一题。
currentQuestionIndex.value += 1; syncExamQuestionIndex(currentQuestionIndex.value + 1);
selectedOptionId.value = '';
answerLocked.value = false;
currentFeedbackCorrect.value = false;
void persistProgress(); void persistProgress();
}; };
@@ -552,19 +567,30 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
const moveToNextQuestion = () => { const moveToNextQuestion = () => {
if (!answerLocked.value) return; if (!answerLocked.value) return;
if (currentQuestionIndex.value >= totalQuestionCount.value - 1) { if (currentQuestionIndex.value >= totalQuestionCount.value - 1) {
stage.value = 'result';
completionDate.value = formatDate(new Date());
void persistProgress();
return; return;
} }
currentQuestionIndex.value += 1; syncExamQuestionIndex(currentQuestionIndex.value + 1);
selectedOptionId.value = '';
answerLocked.value = false;
currentFeedbackCorrect.value = false;
latestExamFeedback.value = null; latestExamFeedback.value = null;
void persistProgress(); void persistProgress();
}; };
/**
* 统一提交整份答卷并进入结算结果。
* AI 触发时机:当员工已完成全部题目但尚未结算时,必须显式点击“提交答卷”后才允许进入第 4 阶段。
*/
const submitExam = () => {
if (!examReadyToSubmit.value) return;
stage.value = 'result';
completionDate.value = formatDate(new Date());
latestSettledResult.value = {
score: score.value,
correctCount: answerRecords.value.filter((item) => item.correct).length,
wrongCount: answerRecords.value.filter((item) => !item.correct).length,
isPassed: score.value >= passScore.value,
};
void persistProgress();
};
const restartExam = () => { const restartExam = () => {
stage.value = 'video'; stage.value = 'video';
resetExamState(); resetExamState();
@@ -645,6 +671,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
activeView, activeView,
stage, stage,
currentQuestionIndex, currentQuestionIndex,
currentQuestionNumber,
currentQuestion, currentQuestion,
totalQuestionCount, totalQuestionCount,
passScore, passScore,
@@ -654,6 +681,8 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
selectedOptionId, selectedOptionId,
answerLocked, answerLocked,
currentFeedbackCorrect, currentFeedbackCorrect,
examReadyToSubmit,
canEnterResultStage,
latestExamFeedback, latestExamFeedback,
latestSettledResult, latestSettledResult,
answerRecords, answerRecords,
@@ -681,7 +710,9 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
markVideoCompleted, markVideoCompleted,
startExam, startExam,
selectAnswer, selectAnswer,
syncExamQuestionIndex,
moveToNextQuestion, moveToNextQuestion,
submitExam,
restartExam, restartExam,
exportRecords, exportRecords,
showVideoModal, showVideoModal,
+1
View File
@@ -526,6 +526,7 @@
"selectedAnswer": "Your answer: {answer}", "selectedAnswer": "Your answer: {answer}",
"correctAnswer": "Correct answer: {answer}", "correctAnswer": "Correct answer: {answer}",
"nextQuestion": "Next Question", "nextQuestion": "Next Question",
"submitPaper": "Submit Paper",
"finishExam": "Finish Exam" "finishExam": "Finish Exam"
}, },
"result": { "result": {
+1
View File
@@ -526,6 +526,7 @@
"selectedAnswer": "คำตอบของคุณ: {answer}", "selectedAnswer": "คำตอบของคุณ: {answer}",
"correctAnswer": "คำตอบที่ถูกต้อง: {answer}", "correctAnswer": "คำตอบที่ถูกต้อง: {answer}",
"nextQuestion": "ข้อถัดไป", "nextQuestion": "ข้อถัดไป",
"submitPaper": "ส่งข้อสอบ",
"finishExam": "จบการสอบ" "finishExam": "จบการสอบ"
}, },
"result": { "result": {
+1
View File
@@ -526,6 +526,7 @@
"selectedAnswer": "你的答案:{answer}", "selectedAnswer": "你的答案:{answer}",
"correctAnswer": "正确答案:{answer}", "correctAnswer": "正确答案:{answer}",
"nextQuestion": "下一题", "nextQuestion": "下一题",
"submitPaper": "提交答卷",
"finishExam": "完成考试" "finishExam": "完成考试"
}, },
"result": { "result": {
+1
View File
@@ -526,6 +526,7 @@
"selectedAnswer": "你的答案:{answer}", "selectedAnswer": "你的答案:{answer}",
"correctAnswer": "正確答案:{answer}", "correctAnswer": "正確答案:{answer}",
"nextQuestion": "下一題", "nextQuestion": "下一題",
"submitPaper": "提交答卷",
"finishExam": "完成考試" "finishExam": "完成考試"
}, },
"result": { "result": {