feat(training-workspace): 培训考试增加提交答卷后再进入结算结果
feat(training-workspace): 完善员工培训工作区考试流转与配置交互
This commit is contained in:
1 parent
5bef77f86c
commit
8bd66baa21
8 files changed
+246
-197
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 ''),
|
||||
request_id=ctx.request_id,
|
||||
trigger_source='frontend_chat',
|
||||
user_role=str(getattr(ctx.user, 'role', '') or '').strip() or None,
|
||||
adapter_hints=ctx.adapter_hints,
|
||||
)
|
||||
|
||||
|
||||
@@ -531,200 +531,202 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
{{ form.training_workspace_enabled ? t('admin.agent.training.enableHint') : t('admin.agent.training.disabledHint') }}
|
||||
</p>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.passScore') }}</label>
|
||||
<input
|
||||
v-model.number="form.training_pass_score"
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
step="1"
|
||||
class="w-full input-field text-sm"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.passScoreHint') }}</p>
|
||||
</div>
|
||||
<div class="space-y-2 md:col-span-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryPoints') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_points_text"
|
||||
rows="5"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryPointsPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryChecklist') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_checklist_text"
|
||||
rows="4"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryChecklistPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-semibold text-primary">{{ t('admin.agent.training.questionBank') }}</div>
|
||||
<p class="mt-1 text-xs leading-5 text-muted">{{ t('admin.agent.training.questionHint') }}</p>
|
||||
<template v-if="form.training_workspace_enabled">
|
||||
<div class="mt-4 grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.passScore') }}</label>
|
||||
<input
|
||||
v-model.number="form.training_pass_score"
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
step="1"
|
||||
class="w-full input-field text-sm"
|
||||
/>
|
||||
<p class="text-xs leading-5 text-muted">{{ t('admin.agent.training.passScoreHint') }}</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="!isEditing || trainingExamPdfGuides.length === 0 || isImportingTrainingPdf"
|
||||
@click="emit('importTrainingPdf', trainingExamPdfGuides[0]?.id || null)"
|
||||
>
|
||||
<FileDown class="h-4 w-4" />
|
||||
{{ isImportingTrainingPdf ? t('admin.agent.training.importingPdf') : t('admin.agent.training.importFromPdf') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="emit('addTrainingQuestion')"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addQuestion') }}
|
||||
</button>
|
||||
<div class="space-y-2 md:col-span-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryPoints') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_points_text"
|
||||
rows="5"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryPointsPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.summaryChecklist') }}</label>
|
||||
<textarea
|
||||
v-model="form.training_summary_checklist_text"
|
||||
rows="4"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.summaryChecklistPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-xs leading-5 text-muted">
|
||||
{{
|
||||
!isEditing
|
||||
? t('admin.agent.training.importPdfCreateFirst')
|
||||
: trainingExamPdfGuides.length > 0
|
||||
? t('admin.agent.training.importPdfHint', { fileName: trainingExamPdfGuides[0]?.file_name || '--' })
|
||||
: t('admin.agent.training.importPdfMissing')
|
||||
}}
|
||||
</p>
|
||||
|
||||
<div v-if="form.training_question_bank.length === 0" class="rounded-xl border border-dashed border-default bg-white px-4 py-5 text-sm text-muted">
|
||||
{{ t('admin.agent.training.emptyQuestionBank') }}
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-4">
|
||||
<div
|
||||
v-for="(question, questionIndex) in form.training_question_bank"
|
||||
:key="questionIndex"
|
||||
class="rounded-2xl border border-default bg-white p-4"
|
||||
>
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ t('admin.agent.training.questionCardTitle', { index: questionIndex + 1 }) }}
|
||||
</div>
|
||||
<div class="mt-5 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-semibold text-primary">{{ t('admin.agent.training.questionBank') }}</div>
|
||||
<p class="mt-1 text-xs leading-5 text-muted">{{ t('admin.agent.training.questionHint') }}</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingQuestion', questionIndex)"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="!isEditing || trainingExamPdfGuides.length === 0 || isImportingTrainingPdf"
|
||||
@click="emit('importTrainingPdf', trainingExamPdfGuides[0]?.id || null)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.removeQuestion') }}
|
||||
<FileDown class="h-4 w-4" />
|
||||
{{ isImportingTrainingPdf ? t('admin.agent.training.importingPdf') : t('admin.agent.training.importFromPdf') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="emit('addTrainingQuestion')"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addQuestion') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionId') }}</label>
|
||||
<input
|
||||
v-model="question.id"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionIdPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionType') }}</label>
|
||||
<select
|
||||
v-model="question.type"
|
||||
class="w-full input-field text-sm"
|
||||
@change="handleTrainingQuestionTypeChange(form, questionIndex)"
|
||||
<p class="text-xs leading-5 text-muted">
|
||||
{{
|
||||
!isEditing
|
||||
? t('admin.agent.training.importPdfCreateFirst')
|
||||
: trainingExamPdfGuides.length > 0
|
||||
? t('admin.agent.training.importPdfHint', { fileName: trainingExamPdfGuides[0]?.file_name || '--' })
|
||||
: t('admin.agent.training.importPdfMissing')
|
||||
}}
|
||||
</p>
|
||||
|
||||
<div v-if="form.training_question_bank.length === 0" class="rounded-xl border border-dashed border-default bg-white px-4 py-5 text-sm text-muted">
|
||||
{{ t('admin.agent.training.emptyQuestionBank') }}
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-4">
|
||||
<div
|
||||
v-for="(question, questionIndex) in form.training_question_bank"
|
||||
:key="questionIndex"
|
||||
class="rounded-2xl border border-default bg-white p-4"
|
||||
>
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ t('admin.agent.training.questionCardTitle', { index: questionIndex + 1 }) }}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingQuestion', questionIndex)"
|
||||
>
|
||||
<option value="single">{{ t('admin.agent.training.single') }}</option>
|
||||
<option value="boolean">{{ t('admin.agent.training.boolean') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.correctAnswer') }}</label>
|
||||
<select v-model="question.answer" class="w-full input-field text-sm">
|
||||
<template v-if="question.type === 'boolean'">
|
||||
<option value="true">{{ t('admin.agent.training.booleanTrue') }}</option>
|
||||
<option value="false">{{ t('admin.agent.training.booleanFalse') }}</option>
|
||||
</template>
|
||||
<template v-else>
|
||||
<option
|
||||
v-for="(_, optionIndex) in question.options.filter((item) => String(item || '').trim())"
|
||||
:key="`${questionIndex}-${optionIndex}`"
|
||||
:value="String.fromCharCode(97 + optionIndex)"
|
||||
>
|
||||
{{ t('admin.agent.training.optionLabel', { label: optionLabels[optionIndex] || optionIndex + 1 }) }}
|
||||
</option>
|
||||
</template>
|
||||
</select>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.removeQuestion') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionPrompt') }}</label>
|
||||
<textarea
|
||||
v-model="question.prompt"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionPromptPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionExplanation') }}</label>
|
||||
<textarea
|
||||
v-model="question.explanation"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionExplanationPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="question.type === 'single'" class="space-y-3 md:col-span-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionOptions') }}</label>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-surface-soft px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-slate-100"
|
||||
@click="emit('addTrainingOption', questionIndex)"
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionId') }}</label>
|
||||
<input
|
||||
v-model="question.id"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionIdPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionType') }}</label>
|
||||
<select
|
||||
v-model="question.type"
|
||||
class="w-full input-field text-sm"
|
||||
@change="handleTrainingQuestionTypeChange(form, questionIndex)"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addOption') }}
|
||||
</button>
|
||||
<option value="single">{{ t('admin.agent.training.single') }}</option>
|
||||
<option value="boolean">{{ t('admin.agent.training.boolean') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.correctAnswer') }}</label>
|
||||
<select v-model="question.answer" class="w-full input-field text-sm">
|
||||
<template v-if="question.type === 'boolean'">
|
||||
<option value="true">{{ t('admin.agent.training.booleanTrue') }}</option>
|
||||
<option value="false">{{ t('admin.agent.training.booleanFalse') }}</option>
|
||||
</template>
|
||||
<template v-else>
|
||||
<option
|
||||
v-for="(_, optionIndex) in question.options.filter((item) => String(item || '').trim())"
|
||||
:key="`${questionIndex}-${optionIndex}`"
|
||||
:value="String.fromCharCode(97 + optionIndex)"
|
||||
>
|
||||
{{ t('admin.agent.training.optionLabel', { label: optionLabels[optionIndex] || optionIndex + 1 }) }}
|
||||
</option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
<div
|
||||
v-for="(_, optionIndex) in question.options"
|
||||
:key="`${questionIndex}-option-${optionIndex}`"
|
||||
class="flex items-center gap-2 rounded-xl border border-default bg-surface-soft/40 p-3"
|
||||
>
|
||||
<span class="min-w-6 text-xs font-semibold text-muted">{{ optionLabels[optionIndex] || optionIndex + 1 }}.</span>
|
||||
<input
|
||||
v-model="question.options[optionIndex]"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.optionPlaceholder')"
|
||||
/>
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionPrompt') }}</label>
|
||||
<textarea
|
||||
v-model="question.prompt"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionPromptPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 md:col-span-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionExplanation') }}</label>
|
||||
<textarea
|
||||
v-model="question.explanation"
|
||||
rows="3"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.questionExplanationPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="question.type === 'single'" class="space-y-3 md:col-span-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.training.questionOptions') }}</label>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-10 w-10 items-center justify-center rounded-lg border border-red-200 bg-red-50 text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingOption', questionIndex, optionIndex)"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default bg-surface-soft px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-slate-100"
|
||||
@click="emit('addTrainingOption', questionIndex)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.agent.training.addOption') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
<div
|
||||
v-for="(_, optionIndex) in question.options"
|
||||
:key="`${questionIndex}-option-${optionIndex}`"
|
||||
class="flex items-center gap-2 rounded-xl border border-default bg-surface-soft/40 p-3"
|
||||
>
|
||||
<span class="min-w-6 text-xs font-semibold text-muted">{{ optionLabels[optionIndex] || optionIndex + 1 }}.</span>
|
||||
<input
|
||||
v-model="question.options[optionIndex]"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:placeholder="t('admin.agent.training.optionPlaceholder')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-10 w-10 items-center justify-center rounded-lg border border-red-200 bg-red-50 text-red-600 transition-colors hover:bg-red-100"
|
||||
@click="emit('removeTrainingOption', questionIndex, optionIndex)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<AgentToolRunProgressConfig
|
||||
|
||||
@@ -138,7 +138,7 @@ const compactSummary = computed(() => {
|
||||
if (workspace.stage === 'summary') return t('chat.training.summary.title');
|
||||
if (workspace.stage === 'exam') {
|
||||
return t('chat.training.exam.questionCounter', {
|
||||
current: workspace.answeredCount + 1,
|
||||
current: workspace.currentQuestionNumber,
|
||||
total: workspace.totalQuestionCount,
|
||||
});
|
||||
}
|
||||
@@ -165,7 +165,15 @@ const examQuestionItems = computed(() => Array.from({ length: workspace.totalQue
|
||||
const canNavigateExamQuestions = computed(() => workspace.stage === 'exam');
|
||||
const jumpToExamQuestion = (index: number) => {
|
||||
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>
|
||||
|
||||
@@ -387,8 +395,11 @@ const jumpToExamQuestion = (index: number) => {
|
||||
v-for="(item, index) in stageItems"
|
||||
:key="item.key"
|
||||
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'"
|
||||
@click="workspace.stage = item.key as any"
|
||||
:class="[
|
||||
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
|
||||
@@ -492,7 +503,7 @@ const jumpToExamQuestion = (index: number) => {
|
||||
{{ $t('chat.training.exam.title') }}
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2 text-sm text-secondary">
|
||||
@@ -564,12 +575,12 @@ const jumpToExamQuestion = (index: number) => {
|
||||
<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"
|
||||
@click="workspace.moveToNextQuestion"
|
||||
@click="workspace.examReadyToSubmit ? workspace.submitExam() : workspace.moveToNextQuestion()"
|
||||
>
|
||||
<ClipboardCheck class="h-4 w-4" />
|
||||
{{
|
||||
workspace.answeredCount >= workspace.totalQuestionCount
|
||||
? $t('chat.training.exam.finishExam')
|
||||
workspace.examReadyToSubmit
|
||||
? $t('chat.training.exam.submitPaper')
|
||||
: $t('chat.training.exam.nextQuestion')
|
||||
}}
|
||||
</button>
|
||||
|
||||
@@ -199,10 +199,20 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
|
||||
const currentQuestion = computed(() => questionBank.value[currentQuestionIndex.value] || null);
|
||||
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 correctCount = 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 examReadyToSubmit = computed(() => (
|
||||
stage.value === 'exam'
|
||||
&& totalQuestionCount.value > 0
|
||||
&& answeredCount.value >= totalQuestionCount.value
|
||||
));
|
||||
const canEnterResultStage = computed(() => stage.value === 'result');
|
||||
|
||||
const learnerProgressPercent = computed(() => {
|
||||
if (stage.value === 'video') return 25;
|
||||
@@ -305,6 +315,21 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
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) => {
|
||||
if (!record) {
|
||||
stage.value = 'video';
|
||||
@@ -314,7 +339,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
return;
|
||||
}
|
||||
stage.value = record.stage;
|
||||
currentQuestionIndex.value = record.currentQuestionIndex;
|
||||
syncExamQuestionIndex(record.currentQuestionIndex);
|
||||
score.value = Number(record.score || 0);
|
||||
attemptCount.value = Number(record.attempts || 0);
|
||||
answerRecords.value = Array.isArray(record.answerDetails) ? record.answerDetails : [];
|
||||
@@ -510,6 +535,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
if (answerLocked.value || !currentQuestion.value) return;
|
||||
const answeredQuestion = currentQuestion.value;
|
||||
selectedOptionId.value = optionId;
|
||||
answerLocked.value = true;
|
||||
const isCorrect = optionId === answeredQuestion.answer;
|
||||
currentFeedbackCorrect.value = isCorrect;
|
||||
const nextCorrectAnswerCount = correctCount.value + (isCorrect ? 1 : 0);
|
||||
@@ -523,25 +549,14 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
answerRecords.value.push(answerRecord);
|
||||
latestExamFeedback.value = buildExamFeedback(answeredQuestion, answerRecord, nextScore);
|
||||
|
||||
// [STEP 1] 最后一题直接进入结算,对齐文档里的“答完即公布最终成绩”。
|
||||
// [STEP 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();
|
||||
return;
|
||||
}
|
||||
|
||||
// [STEP 2] 非最后一题则在聊天流里自动反馈上一题,并紧接着展示下一题。
|
||||
currentQuestionIndex.value += 1;
|
||||
selectedOptionId.value = '';
|
||||
answerLocked.value = false;
|
||||
currentFeedbackCorrect.value = false;
|
||||
syncExamQuestionIndex(currentQuestionIndex.value + 1);
|
||||
void persistProgress();
|
||||
};
|
||||
|
||||
@@ -552,19 +567,30 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const moveToNextQuestion = () => {
|
||||
if (!answerLocked.value) return;
|
||||
if (currentQuestionIndex.value >= totalQuestionCount.value - 1) {
|
||||
stage.value = 'result';
|
||||
completionDate.value = formatDate(new Date());
|
||||
void persistProgress();
|
||||
return;
|
||||
}
|
||||
currentQuestionIndex.value += 1;
|
||||
selectedOptionId.value = '';
|
||||
answerLocked.value = false;
|
||||
currentFeedbackCorrect.value = false;
|
||||
syncExamQuestionIndex(currentQuestionIndex.value + 1);
|
||||
latestExamFeedback.value = null;
|
||||
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 = () => {
|
||||
stage.value = 'video';
|
||||
resetExamState();
|
||||
@@ -645,6 +671,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
activeView,
|
||||
stage,
|
||||
currentQuestionIndex,
|
||||
currentQuestionNumber,
|
||||
currentQuestion,
|
||||
totalQuestionCount,
|
||||
passScore,
|
||||
@@ -654,6 +681,8 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
selectedOptionId,
|
||||
answerLocked,
|
||||
currentFeedbackCorrect,
|
||||
examReadyToSubmit,
|
||||
canEnterResultStage,
|
||||
latestExamFeedback,
|
||||
latestSettledResult,
|
||||
answerRecords,
|
||||
@@ -681,7 +710,9 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
markVideoCompleted,
|
||||
startExam,
|
||||
selectAnswer,
|
||||
syncExamQuestionIndex,
|
||||
moveToNextQuestion,
|
||||
submitExam,
|
||||
restartExam,
|
||||
exportRecords,
|
||||
showVideoModal,
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "Your answer: {answer}",
|
||||
"correctAnswer": "Correct answer: {answer}",
|
||||
"nextQuestion": "Next Question",
|
||||
"submitPaper": "Submit Paper",
|
||||
"finishExam": "Finish Exam"
|
||||
},
|
||||
"result": {
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "คำตอบของคุณ: {answer}",
|
||||
"correctAnswer": "คำตอบที่ถูกต้อง: {answer}",
|
||||
"nextQuestion": "ข้อถัดไป",
|
||||
"submitPaper": "ส่งข้อสอบ",
|
||||
"finishExam": "จบการสอบ"
|
||||
},
|
||||
"result": {
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "你的答案:{answer}",
|
||||
"correctAnswer": "正确答案:{answer}",
|
||||
"nextQuestion": "下一题",
|
||||
"submitPaper": "提交答卷",
|
||||
"finishExam": "完成考试"
|
||||
},
|
||||
"result": {
|
||||
|
||||
@@ -526,6 +526,7 @@
|
||||
"selectedAnswer": "你的答案:{answer}",
|
||||
"correctAnswer": "正確答案:{answer}",
|
||||
"nextQuestion": "下一題",
|
||||
"submitPaper": "提交答卷",
|
||||
"finishExam": "完成考試"
|
||||
},
|
||||
"result": {
|
||||
|
||||
Reference in new issue
Block a user