feat(员工培训): 完善新人入职培训聊天闭环交互
This commit is contained in:
1 parent
eb0466245b
commit
3f13bb5b46
19 files changed
+2975
-12
No files matched your search
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* features/chat/components/messages/TrainingExamQuestionMessage.vue
|
||||
* 用途:在聊天气泡中渲染交互式答题选择器,支持单选题与判断题。
|
||||
* 逻辑:由 ChatMessageBubble 内部调用;展示当前题目内容、选项,并在答题后展示即时反馈与“下一题”操作。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { CheckCircle2, XCircle, ClipboardCheck } from 'lucide-vue-next';
|
||||
import type { TrainingQuestion } from '@/features/chat/training/training.types';
|
||||
|
||||
export interface TrainingHandlers {
|
||||
getQuestion: () => TrainingQuestion | null;
|
||||
getCurrentQuestionIndex: () => number;
|
||||
getAnsweredCount: () => number;
|
||||
getTotalCount: () => number;
|
||||
getScore: () => number;
|
||||
getSelectedOptionId: () => string;
|
||||
getAnswerLocked: () => boolean;
|
||||
getFeedbackCorrect: () => boolean;
|
||||
getAnswerLabel: () => string;
|
||||
onSelect: (optionId: string) => void;
|
||||
onNext: () => void;
|
||||
onPlayVideo: () => void;
|
||||
onStartExam: () => void;
|
||||
onRestartExam: () => void;
|
||||
getCorrectCount: () => number;
|
||||
getWrongCount: () => number;
|
||||
getSummaryPoints: () => string[];
|
||||
getSummaryChecklist: () => string[];
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
question: TrainingQuestion;
|
||||
currentQuestionIndex: number;
|
||||
answeredCount: number;
|
||||
totalCount: number;
|
||||
score: number;
|
||||
selectedOptionId: string;
|
||||
answerLocked: boolean;
|
||||
feedbackCorrect: boolean;
|
||||
answerLabel: string;
|
||||
isThinking: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
select: [optionId: string];
|
||||
next: [];
|
||||
}>();
|
||||
|
||||
const passLine = 90;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="my-2 flex flex-col gap-4 rounded-2xl border border-brand-100 bg-white p-4 shadow-sm ring-1 ring-brand-50/50">
|
||||
<!-- 头部进度与分数 -->
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<div class="text-[11px] font-bold uppercase tracking-[0.15em] text-brand-600/80">
|
||||
第三步:逐题考试
|
||||
</div>
|
||||
<h3 class="mt-1 text-lg font-bold text-slate-800">
|
||||
第 {{ currentQuestionIndex + 1 }} / {{ totalCount }} 题
|
||||
</h3>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2 text-[13px]">
|
||||
<div class="rounded-lg bg-slate-50 px-3 py-1.5 font-medium text-slate-600 border border-slate-100 flex items-center gap-2">
|
||||
<span>当前分数:</span>
|
||||
<span class="text-slate-800 font-bold">{{ score }} 分</span>
|
||||
</div>
|
||||
<div class="rounded-lg bg-slate-50 px-3 py-1.5 font-medium text-slate-600 border border-slate-100 flex items-center gap-2">
|
||||
<span>及格线:</span>
|
||||
<span class="text-slate-800 font-bold">{{ passLine }} 分</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 题目正文 -->
|
||||
<div class="rounded-xl bg-brand-50/30 p-4 border border-brand-100/50">
|
||||
<div class="text-[15px] font-bold leading-7 text-slate-800">
|
||||
{{ question.prompt }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 选项列表 -->
|
||||
<div class="grid gap-2.5">
|
||||
<button
|
||||
v-for="option in question.options"
|
||||
:key="option.id"
|
||||
type="button"
|
||||
class="group relative flex items-center justify-between rounded-2xl border px-5 py-3.5 text-left text-[14px] transition-all duration-200"
|
||||
:class="[
|
||||
selectedOptionId === option.id
|
||||
? answerLocked
|
||||
? option.id === question.answer
|
||||
? 'border-emerald-300 bg-emerald-50 text-emerald-700 ring-4 ring-emerald-500/5'
|
||||
: 'border-red-300 bg-red-50 text-red-700 ring-4 ring-red-500/5'
|
||||
: 'border-brand-300 bg-brand-50 text-brand-700 ring-4 ring-brand-500/5'
|
||||
: answerLocked && option.id === question.answer
|
||||
? '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"
|
||||
@click="emit('select', option.id)"
|
||||
>
|
||||
<span class="font-medium">{{ option.label }}</span>
|
||||
<CheckCircle2
|
||||
v-if="answerLocked && option.id === question.answer"
|
||||
class="h-5 w-5 shrink-0 text-emerald-500"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 答题反馈 -->
|
||||
<div
|
||||
v-if="answerLocked"
|
||||
class="mt-1 animate-in fade-in slide-in-from-top-2 duration-300 rounded-2xl border p-4"
|
||||
:class="feedbackCorrect ? 'border-emerald-100 bg-emerald-50/60' : 'border-red-100 bg-red-50/60'"
|
||||
>
|
||||
<div class="flex items-center gap-2 text-sm font-bold" :class="feedbackCorrect ? 'text-emerald-700' : 'text-red-700'">
|
||||
<CheckCircle2 v-if="feedbackCorrect" class="h-4 w-4" />
|
||||
<XCircle v-else class="h-4 w-4" />
|
||||
{{ feedbackCorrect ? '回答正确,继续下一题' : '回答错误' }}
|
||||
</div>
|
||||
|
||||
<div class="mt-3 space-y-2 text-[13px] leading-6 text-slate-600">
|
||||
<div class="flex gap-2">
|
||||
<span class="font-medium text-slate-500 shrink-0">你的答案:</span>
|
||||
<span class="font-medium" :class="feedbackCorrect ? 'text-emerald-600' : 'text-red-600'">{{ answerLabel || '--' }}</span>
|
||||
</div>
|
||||
<div v-if="!feedbackCorrect" class="flex gap-2">
|
||||
<span class="font-medium text-slate-500 shrink-0">正确答案:</span>
|
||||
<span class="text-emerald-600 font-medium">{{ question.options?.find(o => o.id === question.answer)?.label || '--' }}</span>
|
||||
</div>
|
||||
<div class="mt-2 pl-2 border-l-2 border-slate-200/60 text-slate-500/90">
|
||||
{{ question.explanation }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2 rounded-xl bg-brand-600 px-5 py-2.5 text-[14px] font-bold text-white shadow-lg shadow-brand-500/20 transition-all hover:bg-brand-700 hover:-translate-y-0.5 active:translate-y-0 disabled:opacity-50 disabled:translate-y-0"
|
||||
:disabled="isThinking"
|
||||
@click="emit('next')"
|
||||
>
|
||||
<ClipboardCheck class="h-4 w-4" />
|
||||
{{ answeredCount >= totalCount - 1 ? '完成考试并查看结果' : '下一题' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user