feat(员工培训): 完善新人入职培训聊天闭环交互

This commit is contained in:
runny committed 2026-06-30 13:25:17 +08:00
1 parent eb0466245b
commit 3f13bb5b46
19 files changed
+2975 -12

No files matched your search

@@ -11,6 +11,10 @@ import LeaveMessageBlock, { type LeaveMessageHandlers } from './LeaveMessageBloc
import ShippingInventoryMappingMessage, { type ShippingMappingHandlers } from './ShippingInventoryMappingMessage.vue';
import ShippingMatchResultCard from './ShippingMatchResultCard.vue';
import ShippingParseReviewMessage, { type ShippingParseReviewHandlers } from './ShippingParseReviewMessage.vue';
import TrainingExamQuestionMessage, { type TrainingHandlers } from './TrainingExamQuestionMessage.vue';
import TrainingVideoMessage from './TrainingVideoMessage.vue';
import TrainingSummaryMessage from './TrainingSummaryMessage.vue';
import TrainingResultCard from './TrainingResultCard.vue';
import type { ChatMessage, InlineDownloadFile, SourceFileLink } from '../../types/chat.types';
import type { ShippingInventoryMappingFormPayload, ShippingMatchResultPayload } from '../../types/shipping.types';
@@ -57,6 +61,7 @@ const {
handlers: ChatMessageBubbleHandlers;
leaveHandlers: LeaveMessageHandlers;
shippingHandlers: ShippingMappingHandlers;
trainingHandlers: TrainingHandlers;
}>();
const emit = defineEmits<{
@@ -73,6 +78,35 @@ const isLeaveMessage = computed(() =>
|| message.type === 'leave-result',
);
const isTrainingExamMessage = computed(() => {
if (message.role !== 'assistant') return false;
// 必须是最后一条助手消息,且包含题目特征文字(确保只在当前正在进行的题目上显示交互组件)
if (!isLastMessage.value) return false;
const content = message.content || '';
return content.includes('正在进行新人培训考试')
|| (content.includes('第') && content.includes('题') && (content.includes('共') || content.includes('/')));
});
const isTrainingVideoMessage = computed(() => {
if (message.role !== 'assistant') return false;
// 只要包含特定引导文案,就显示视频占位符,不限于最后一条消息
const content = message.content || '';
return content.includes('专属入职培训助手') || (content.includes('看视频') && content.includes('已看完'));
});
const isTrainingSummaryMessage = computed(() => {
if (message.role !== 'assistant') return false;
const content = message.content || '';
return content.includes('完成视频学习') || content.includes('复盘重点知识') || content.includes('复盘知识点') || content.includes('总结重点知识');
});
const isTrainingResultMessage = computed(() => {
if (message.role !== 'assistant') return false;
// 只要是结果文案,就显示结算卡片,不限于最后一条消息
const content = message.content || '';
return content.includes('考试结束') || content.includes('顺利通过新人考核');
});
const retrieverResources = computed(() => handlers.getDisplayRetrieverResources(message));
const sourceLinks = computed(() => handlers.getSourceLinks(retrieverResources.value));
@@ -480,13 +514,51 @@ function handleInlineDownload(file: InlineDownloadFile): void {
:action-button-class="handlers.shippingActionButtonClass"
:on-action-click="(action) => handlers.onShippingActionClick(message, action)"
/>
<TrainingExamQuestionMessage
v-else-if="isTrainingExamMessage && trainingHandlers.getQuestion()"
:question="trainingHandlers.getQuestion()!"
:current-question-index="trainingHandlers.getCurrentQuestionIndex()"
:answered-count="trainingHandlers.getAnsweredCount()"
:total-count="trainingHandlers.getTotalCount()"
:score="trainingHandlers.getScore()"
:selected-option-id="trainingHandlers.getSelectedOptionId()"
:answer-locked="trainingHandlers.getAnswerLocked()"
:feedback-correct="trainingHandlers.getFeedbackCorrect()"
:answer-label="trainingHandlers.getAnswerLabel()"
:is-thinking="isThinking"
@select="trainingHandlers.onSelect"
@next="trainingHandlers.onNext"
/>
<TrainingResultCard
v-else-if="isTrainingResultMessage"
:score="trainingHandlers.getScore()"
:is-passed="trainingHandlers.getScore() >= 90"
:correct-count="trainingHandlers.getCorrectCount()"
:wrong-count="trainingHandlers.getWrongCount()"
:is-thinking="isThinking"
@restart="trainingHandlers.onRestartExam"
/>
<div
v-else-if="renderedMarkdown"
class="chat-markdown prose prose-sm max-w-none leading-7 text-primary prose-a:text-blue-600 prose-p:my-1 prose-li:my-0.5 prose-ol:my-2 prose-ul:my-2 prose-headings:my-2 prose-hr:my-3 prose-code:rounded prose-code:bg-slate-100 prose-code:px-1 prose-code:text-blue-700 prose-pre:my-3 prose-pre:border prose-pre:border-slate-700 prose-pre:bg-slate-900 prose-pre:text-slate-100 prose-th:border prose-th:border-slate-200 prose-th:bg-slate-50 prose-th:px-3 prose-th:py-2 prose-th:text-left prose-td:border prose-td:border-slate-200 prose-td:px-3 prose-td:py-2"
@click="handlers.onMarkdownClick"
ref="markdownContainer"
class="markdown-body chat-markdown min-w-0 break-words text-sm leading-relaxed"
v-html="renderedMarkdown"
/>
<TrainingVideoMessage
v-if="isTrainingVideoMessage"
:is-thinking="isThinking"
@play="trainingHandlers.onPlayVideo"
/>
<TrainingSummaryMessage
v-if="isTrainingSummaryMessage"
:summary-points="trainingHandlers.getSummaryPoints()"
:summary-checklist="trainingHandlers.getSummaryChecklist()"
:is-thinking="isThinking"
@start-exam="trainingHandlers.onStartExam"
/>
<div v-if="actionableInlineFileEntries.length > 0" class="mt-4">
<div class="flex flex-wrap gap-2">
<button
@@ -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>
@@ -0,0 +1,88 @@
/**
* features/chat/components/messages/TrainingResultCard.vue
* 用途:在聊天气泡中渲染考试结算结果。
*/
<script setup lang="ts">
import { ShieldCheck, XCircle, RotateCcw, CheckCircle2 } from 'lucide-vue-next';
defineProps<{
score: number;
isPassed: boolean;
correctCount: number;
wrongCount: number;
isThinking: boolean;
}>();
const emit = defineEmits<{
restart: [];
}>();
</script>
<template>
<div class="my-2 flex flex-col gap-5 rounded-2xl border border-brand-100 bg-white p-5 shadow-sm ring-1 ring-brand-50/50">
<!-- 状态头部 -->
<div class="flex items-center justify-between">
<div class="flex items-center gap-2.5">
<div
class="flex h-10 w-10 items-center justify-center rounded-xl"
:class="isPassed ? 'bg-emerald-100 text-emerald-600' : 'bg-red-100 text-red-600'"
>
<ShieldCheck v-if="isPassed" class="h-6 w-6" />
<XCircle v-else class="h-6 w-6" />
</div>
<div>
<div class="text-[11px] font-bold uppercase tracking-[0.15em] text-slate-500">
第四步:结算结果
</div>
<h3 class="text-lg font-bold text-slate-800">
{{ isPassed ? '恭喜,你已通过考核!' : '很遗憾,考试未通过' }}
</h3>
</div>
</div>
<div
class="rounded-full px-3 py-1 text-xs font-bold uppercase"
:class="isPassed ? 'bg-emerald-50 text-emerald-700 border border-emerald-100' : 'bg-red-50 text-red-700 border border-red-100'"
>
{{ isPassed ? 'PASSED' : 'FAILED' }}
</div>
</div>
<!-- 分数展示 -->
<div class="grid grid-cols-3 gap-3">
<div class="rounded-2xl bg-slate-50 p-4 border border-slate-100 text-center">
<div class="text-[11px] font-bold text-slate-400 uppercase">{{ $t('chat.training.result.scoreLabel') }}</div>
<div class="mt-1 text-2xl font-black text-brand-600">{{ score }}</div>
</div>
<div class="rounded-2xl bg-emerald-50/50 p-4 border border-emerald-100/50 text-center">
<div class="text-[11px] font-bold text-emerald-500 uppercase">{{ $t('chat.training.result.correctCount') }}</div>
<div class="mt-1 text-2xl font-black text-emerald-600">{{ correctCount }}</div>
</div>
<div class="rounded-2xl bg-red-50/50 p-4 border border-red-100/50 text-center">
<div class="text-[11px] font-bold text-red-400 uppercase">答错</div>
<div class="mt-1 text-2xl font-black text-red-500">{{ wrongCount }}</div>
</div>
</div>
<!-- 描述语 -->
<div class="text-sm leading-relaxed text-slate-600">
{{ isPassed ? $t('chat.training.result.passDescription') : $t('chat.training.result.failDescription') }}
</div>
<!-- 操作 -->
<div v-if="!isPassed" class="pt-2">
<button
type="button"
class="inline-flex w-full items-center justify-center gap-2 rounded-xl bg-slate-800 px-5 py-3 text-sm font-bold text-white transition-all hover:bg-slate-900 active:scale-[0.98] disabled:opacity-50"
:disabled="isThinking"
@click="emit('restart')"
>
<RotateCcw class="h-4 w-4" />
重新考试
</button>
</div>
<div v-else class="flex items-center gap-2 text-emerald-600 font-medium text-sm">
<CheckCircle2 class="h-4 w-4" />
成绩已同步至 HR 管理系统
</div>
</div>
</template>
@@ -0,0 +1,87 @@
/**
* features/chat/components/messages/TrainingSummaryMessage.vue
* 用途:在聊天气泡中渲染“知识点复盘”卡片。
* 逻辑:展示重点知识和考前必知,并提供“开始考试”按钮。
*/
<script setup lang="ts">
import { BookOpen, CheckCircle2, ClipboardCheck } from 'lucide-vue-next';
defineProps<{
summaryPoints: string[];
summaryChecklist: string[];
isThinking: boolean;
}>();
const emit = defineEmits<{
startExam: [];
}>();
</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-1 sm:flex-row sm:items-center sm:justify-between">
<div class="flex items-center gap-2">
<div class="flex h-8 w-8 items-center justify-center rounded-lg bg-brand-50 text-brand-600">
<BookOpen class="h-5 w-5" />
</div>
<div>
<h3 class="text-base font-bold text-slate-800">
{{ $t('chat.training.summary.title') }}
</h3>
<p class="text-[12px] text-slate-500">
{{ $t('chat.training.summary.description') }}
</p>
</div>
</div>
<button
type="button"
class="mt-2 inline-flex items-center gap-2 rounded-xl bg-brand-600 px-4 py-2 text-[13px] font-bold text-white shadow-md shadow-brand-500/20 transition-all hover:bg-brand-700 sm:mt-0"
:disabled="isThinking"
@click="emit('startExam')"
>
<ClipboardCheck class="h-4 w-4" />
{{ $t('chat.training.summary.startExam') }}
</button>
</div>
<!-- 内容网格 -->
<div class="grid gap-4 md:grid-cols-2">
<!-- 重点知识 -->
<div class="rounded-xl bg-brand-50/30 p-4 border border-brand-100/50">
<h4 class="mb-3 flex items-center gap-2 text-[14px] font-bold text-brand-700">
<div class="h-1.5 w-1.5 rounded-full bg-brand-500"></div>
{{ $t('chat.training.summary.keyPoints') }}
</h4>
<ul class="space-y-2.5">
<li
v-for="(point, i) in summaryPoints"
:key="i"
class="flex gap-2 text-[13px] leading-6 text-slate-600"
>
<span class="text-brand-400 font-bold">•</span>
<span>{{ point }}</span>
</li>
</ul>
</div>
<!-- 考前必知 -->
<div class="rounded-xl bg-slate-50/50 p-4 border border-slate-100">
<h4 class="mb-3 flex items-center gap-2 text-[14px] font-bold text-slate-700">
<div class="h-1.5 w-1.5 rounded-full bg-slate-400"></div>
{{ $t('chat.training.summary.mustKnow') }}
</h4>
<ul class="space-y-2.5">
<li
v-for="(item, i) in summaryChecklist"
:key="i"
class="flex gap-2 text-[13px] leading-6 text-slate-600"
>
<CheckCircle2 class="mt-1 h-3.5 w-3.5 shrink-0 text-emerald-500/80" />
<span>{{ item }}</span>
</li>
</ul>
</div>
</div>
</div>
</template>
@@ -0,0 +1,37 @@
/**
* features/chat/components/messages/TrainingVideoMessage.vue
* 用途:在聊天气泡中渲染培训视频占位符。
* 逻辑:点击占位符触发视频播放弹窗(复用工作区逻辑)。
*/
<script setup lang="ts">
import { PlayCircle } from 'lucide-vue-next';
defineProps<{
isThinking: boolean;
}>();
const emit = defineEmits<{
play: [];
}>();
</script>
<template>
<div class="my-1.5 flex flex-col gap-3 rounded-2xl border border-brand-100 bg-white p-3 shadow-sm ring-1 ring-brand-50/30">
<div
class="relative group cursor-pointer overflow-hidden rounded-xl border border-default bg-slate-900 shadow-sm aspect-video flex items-center justify-center"
:class="{ 'opacity-50 pointer-events-none': isThinking }"
@click="emit('play')"
>
<img
src="https://coresg-normal.trae.ai/api/ide/v1/text_to_image?prompt=Professional%20corporate%20training%20video%20cover%2C%20high-quality%2C%20modern%20office%20background%2C%20play%20button%20overlay&image_size=landscape_16_9"
class="absolute inset-0 w-full h-full object-cover opacity-60 group-hover:scale-105 transition-transform duration-500"
/>
<div class="relative z-10 flex flex-col items-center gap-2">
<div class="h-12 w-12 flex items-center justify-center rounded-full bg-white/20 backdrop-blur-md border border-white/30 group-hover:bg-brand-600 group-hover:border-brand-500 transition-all duration-300">
<PlayCircle class="h-6 w-6 text-white fill-white/20" />
</div>
<span class="text-white text-xs font-medium drop-shadow-md">点击播放视频</span>
</div>
</div>
</div>
</template>