feat(training): 新增精益培训视频与周任务管理

This commit is contained in:
runny committed 2026-09-08 17:10:14 +08:00
1 parent e5ede471fd
commit a69814c409
32 files changed
+1619 -55

No files matched your search

@@ -11,6 +11,7 @@ import { computed, reactive, ref, watch, type ShallowUnwrapRef } from 'vue';
import { useI18n } from 'vue-i18n';
import {
BookOpen,
Bell,
CheckCircle2,
ChevronDown,
ChevronUp,
@@ -33,9 +34,9 @@ import { resolveTrainingExamPdfGuide, type TrainingGuideLike } from '@/features/
import { getMyTrainingConfig } from '@/features/chat/api/training.api';
import type { TrainingAnswerRecord, TrainingRecord, TrainingQuestion } from '@/features/chat/training/training.types';
import html2pdf from 'html2pdf.js';
import { getAuthHeaders } from '@/shared/utils/auth';
const props = defineProps<{
currentAgent: Record<string, unknown> | null;
currentUser: Record<string, unknown> | null;
@@ -326,7 +327,7 @@ const applyDefaultExpandedState = () => {
// 监听 Agent/角色切换,重置本地展开态:培训角色首次进入默认展开工作区。
watch(
() => [props.currentAgent?.id, workspace.isAdminViewer],
() => [props.currentAgent?.id, workspace.canManageTrainingWorkspace],
() => {
userExpandedOverride.value = null;
applyDefaultExpandedState();
@@ -414,6 +415,40 @@ const isMaterialCompleted = (material: any) => {
};
const currentPreviewVideoUrl = ref('');
const activeNonSafetyVideoId = ref<number | null>(null);
const nonSafetyVideoMaterials = computed(() => workspace.publishedTrainingMaterials.filter((material) => (
material.resource?.fileType === 'video' && Boolean(material.resource.fileUrl)
)));
const activeNonSafetyVideo = computed(() => (
nonSafetyVideoMaterials.value.find((material) => material.id === activeNonSafetyVideoId.value)
|| nonSafetyVideoMaterials.value[0]
|| null
));
const selectNonSafetyVideo = (material: { id?: number | null; resource?: { fileUrl?: string } | null }) => {
if (!material.resource?.fileUrl) return;
if (workspace.currentViewingMaterialId !== material.id) {
workspace.stopMaterialTimer();
}
activeNonSafetyVideoId.value = material.id ?? null;
workspace.currentViewingMaterialId = material.id ?? null;
};
const startNonSafetyVideoTimer = () => {
if (activeNonSafetyVideo.value?.id != null) {
workspace.startMaterialTimer(activeNonSafetyVideo.value.id);
}
};
const stopNonSafetyVideoTimer = () => {
workspace.stopMaterialTimer();
};
watch([() => workspace.learnerTab, nonSafetyVideoMaterials], () => {
if (!nonSafetyVideoMaterials.value.some((material) => material.id === activeNonSafetyVideoId.value)) {
activeNonSafetyVideoId.value = nonSafetyVideoMaterials.value[0]?.id ?? null;
}
}, { immediate: true });
const videoCountdownSeconds = ref(0);
let videoCountdownTimer: ReturnType<typeof setInterval> | null = null;
@@ -533,7 +568,7 @@ const currentSafetyStageText = computed(() => {
{{ $t('chat.training.tabs.learner') }}
</button>
<button
v-if="workspace.isAdminViewer"
v-if="workspace.canManageTrainingWorkspace"
type="button"
class="rounded-full px-3 py-1.5 text-xs font-medium transition"
:class="workspace.activeView === 'admin' ? 'bg-brand-600 text-white' : 'bg-surface-soft text-secondary hover:bg-slate-100'"
@@ -546,7 +581,7 @@ const currentSafetyStageText = computed(() => {
<div class="flex flex-wrap items-center justify-end gap-2">
<button
v-if="trainingExamPdfGuide"
v-if="trainingExamPdfGuide && workspace.learnerTab === 'safety'"
type="button"
class="inline-flex h-9 items-center gap-2 rounded-xl border border-default bg-white px-3.5 text-xs font-medium leading-none text-secondary transition hover:bg-surface-soft"
@click="emit('open-guide', Number(trainingExamPdfGuide.id))"
@@ -555,7 +590,7 @@ const currentSafetyStageText = computed(() => {
<span class="leading-none">{{ $t('chat.training.actions.viewExamPdf') }}</span>
</button>
<button
v-if="workspace.stage === 'video'"
v-if="workspace.learnerTab === 'safety' && workspace.safetyViewStage !== 'exam' && workspace.safetyViewStage !== 'result'"
type="button"
class="inline-flex min-h-9 items-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-700 transition hover:bg-brand-100"
@click="showVideoModal = true"
@@ -619,7 +654,7 @@ const currentSafetyStageText = computed(() => {
{{ $t('chat.training.tabs.learner') }}
</button>
<button
v-if="workspace.isAdminViewer"
v-if="workspace.canManageTrainingWorkspace"
type="button"
class="rounded-full px-3 py-1.5 text-xs font-medium transition"
:class="workspace.activeView === 'admin' ? 'bg-brand-600 text-white' : 'bg-surface-soft text-secondary hover:bg-slate-100'"
@@ -632,7 +667,7 @@ const currentSafetyStageText = computed(() => {
<div class="flex flex-wrap items-center justify-end gap-2">
<button
v-if="trainingExamPdfGuide"
v-if="trainingExamPdfGuide && workspace.learnerTab === 'safety'"
type="button"
class="inline-flex h-9 items-center gap-2 rounded-xl border border-default bg-white px-3.5 text-xs font-medium leading-none text-secondary transition hover:bg-surface-soft"
@click="emit('open-guide', Number(trainingExamPdfGuide.id))"
@@ -708,7 +743,27 @@ const currentSafetyStageText = computed(() => {
<div class="mt-3 text-base font-semibold text-primary">{{ $t('chat.training.noContent.title') }}</div>
<div class="mt-1 text-sm">{{ $t('chat.training.noContent.description') }}</div>
</div>
<template v-else-if="workspace.learnerTab !== 'safety'">
<div v-if="workspace.learnerTab === 'lean_management' && workspace.leanTask" class="col-span-full rounded-2xl border border-emerald-200 bg-emerald-50/40 p-4">
<div class="flex flex-wrap items-center justify-between gap-2">
<div>
<div class="text-base font-semibold text-primary">{{ $t('chat.training.lean.learner.title') }}</div>
<div class="mt-1 text-xs text-secondary">{{ $t('chat.training.lean.learner.description', { count: workspace.leanTask.videos.length, minSummaryLength: workspace.leanTask.minSummaryLength }) }}</div>
</div>
<div class="rounded-full bg-white px-3 py-1 text-xs font-medium text-emerald-700">{{ $t('chat.training.lean.dueAt', { time: workspace.leanTask.dueAt.slice(0, 16).replace('T', ' ') }) }}</div>
</div>
<div class="mt-4 grid gap-3 md:grid-cols-2">
<button v-for="video in workspace.leanTask.videos" :key="video.id" type="button" class="rounded-xl border border-default bg-white p-3 text-left hover:border-emerald-400" @click="workspace.markLeanVideoWatched(video.id)">
<div class="flex items-center gap-2 text-sm font-medium text-primary"><Video class="h-4 w-4 text-emerald-600" />{{ video.name }}</div>
<div class="mt-1 text-xs text-secondary">{{ workspace.leanWatchedAt[String(video.id)] ? $t('chat.training.lean.watchedAt', { time: (workspace.leanWatchedAt[String(video.id)] || '').slice(0, 19).replace('T', ' ') }) : $t('chat.training.lean.markVideoWatched') }}</div>
</button>
</div>
<textarea v-model="workspace.leanSummaryText" rows="4" class="mt-3 w-full rounded-xl border border-default bg-white p-3 text-sm" :placeholder="$t('chat.training.lean.summaryPlaceholder', { minSummaryLength: workspace.leanTask.minSummaryLength })" />
<div class="mt-2 flex items-center justify-between gap-3">
<span class="text-xs" :class="workspace.leanSummaryText.length >= workspace.leanTask.minSummaryLength ? 'text-emerald-600' : 'text-amber-600'">{{ $t('chat.training.lean.summaryLength', { current: workspace.leanSummaryText.length, minSummaryLength: workspace.leanTask.minSummaryLength }) }}</span>
<button type="button" class="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white disabled:cursor-not-allowed disabled:opacity-50" :disabled="workspace.leanSummaryText.trim().length < workspace.leanTask.minSummaryLength || Object.keys(workspace.leanWatchedAt).length < workspace.leanTask.videos.length" @click="workspace.submitLeanTrainingCompletion">{{ $t('chat.training.lean.submitSummary') }}</button>
</div>
</div>
<template v-if="workspace.learnerTab !== 'safety' && workspace.learnerTab !== 'lean_management'">
<div :class="learnerWorkspaceMainClass">
<div v-if="showLearnerProgressModule" :class="progressCardClass">
<div class="flex flex-col gap-1.5 lg:flex-row lg:items-start lg:justify-between">
@@ -762,31 +817,34 @@ const currentSafetyStageText = computed(() => {
<p v-if="learnerStepIntroDescription" class="mt-1 whitespace-pre-line text-sm leading-6 text-secondary">{{ learnerStepIntroDescription }}</p>
</div>
</div>
<div class="mt-3">
<ul v-if="workspace.publishedTrainingMaterials.length" class="space-y-2">
<li
v-for="material in workspace.publishedTrainingMaterials"
:key="material.id || `${material.resourceType}-${material.sortOrder}`"
class="flex items-center justify-between gap-3 rounded-xl border border-slate-100 bg-slate-50 px-3 py-2.5 cursor-pointer transition hover:bg-slate-100"
@click="handleMaterialClick(material)"
>
<div class="flex min-w-0 items-center gap-2 text-sm font-medium text-primary hover:text-brand-600">
<Video v-if="material.resource?.fileType === 'video'" class="h-4 w-4 text-brand-500" />
<FileText v-else class="h-4 w-4 text-slate-400" />
<span class="truncate">{{ material.title || material.resource?.fileName || $t('chat.training.video.playerTitle') }}</span>
</div>
</li>
</ul>
<div v-if="activeNonSafetyVideo" class="mt-3 overflow-hidden rounded-2xl border border-default bg-black shadow-lg">
<video
:key="activeNonSafetyVideo.id ?? activeNonSafetyVideo.resource?.fileUrl"
controls
playsinline
preload="metadata"
class="aspect-video w-full"
:src="activeNonSafetyVideo.resource?.fileUrl"
@play="startNonSafetyVideoTimer"
@pause="stopNonSafetyVideoTimer"
@ended="stopNonSafetyVideoTimer"
/>
</div>
<div class="mt-3 relative group cursor-pointer overflow-hidden rounded-2xl border border-default bg-slate-900 shadow-lg aspect-video flex items-center justify-center" @click="showVideoModal = true">
<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-3">
<div class="h-16 w-16 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-8 w-8 text-white fill-white/20" />
</div>
<span class="text-white font-medium drop-shadow-md">{{ $t('chat.training.video.playerTitle') }}</span>
</div>
<div v-else class="mt-3 rounded-2xl border border-dashed border-default bg-surface-soft px-4 py-10 text-center text-sm text-muted">
{{ $t('chat.training.video.empty') }}
</div>
<div v-if="nonSafetyVideoMaterials.length > 1" class="mt-3 grid gap-2 sm:grid-cols-2">
<button
v-for="(material, index) in nonSafetyVideoMaterials"
:key="material.id || `${material.resourceType}-${material.sortOrder}`"
type="button"
class="flex min-w-0 items-center gap-2 rounded-xl border px-3 py-2.5 text-left text-sm transition"
:class="activeNonSafetyVideo?.id === material.id ? 'border-brand-300 bg-brand-50 text-brand-700' : 'border-default bg-white text-primary hover:border-brand-200'"
@click="selectNonSafetyVideo(material)"
>
<Video class="h-4 w-4 shrink-0" />
<span class="min-w-0 flex-1 truncate">{{ material.title || material.resource?.fileName || `${$t('chat.training.video.playerTitle')} ${index + 1}` }}</span>
</button>
</div>
</div>
@@ -1572,6 +1630,69 @@ const currentSafetyStageText = computed(() => {
</table>
</div>
</div>
<div v-if="workspace.canViewLeanDashboard && workspace.leanDashboard.task" class="rounded-2xl border border-emerald-200 bg-emerald-50/40 p-4 shadow-sm">
<div class="flex flex-wrap items-start justify-between gap-3">
<div>
<div class="flex items-center gap-2 text-base font-semibold text-primary">
<BookOpen class="h-4 w-4 text-emerald-600" />
{{ $t('chat.training.lean.dashboard.title') }}
</div>
<div class="mt-1 text-xs text-secondary">{{ $t('chat.training.lean.dashboard.week', { week: workspace.leanDashboard.task.weekKey }) }}</div>
</div>
<div class="rounded-full bg-white px-3 py-1 text-xs font-medium text-emerald-700">{{ $t('chat.training.lean.dueAt', { time: workspace.leanDashboard.task.dueAt.slice(0, 16).replace('T', ' ') }) }}</div>
</div>
<div class="mt-4 grid gap-4 xl:grid-cols-2">
<div v-for="group in [{ key: 'completed', rows: workspace.leanDashboard.completed }, { key: 'incomplete', rows: workspace.leanDashboard.incomplete }]" :key="group.key" class="overflow-hidden rounded-2xl border border-default bg-white">
<div class="flex items-center justify-between border-b border-default px-4 py-3" :class="group.key === 'completed' ? 'bg-emerald-50/70' : 'bg-amber-50/70'">
<div class="text-sm font-semibold text-primary">{{ $t(`chat.training.lean.dashboard.${group.key}`) }}</div>
<div class="rounded-full bg-white px-2.5 py-1 text-xs font-medium text-secondary">{{ $t('chat.training.lean.dashboard.count', { count: group.rows.length }) }}</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-[900px] border-collapse text-sm">
<thead class="bg-surface-soft">
<tr>
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.employeeId') }}</th>
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.name') }}</th>
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.department') }}</th>
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.videoName') }}</th>
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.watchedAt') }}</th>
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.status') }}</th>
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.summary') }}</th>
<th v-if="group.key === 'incomplete'" class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.action') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="row in group.rows" :key="row.userId" class="odd:bg-white even:bg-surface-soft/30">
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ row.employeeId || '--' }}</td>
<td class="border-b border-default px-3 py-2.5 font-medium text-primary">{{ row.name }}</td>
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ row.department || '--' }}</td>
<td class="border-b border-default px-3 py-2.5 text-secondary"><div v-for="video in row.videos" :key="video.name" class="whitespace-nowrap">{{ video.name }}</div><span v-if="!row.videos.length">--</span></td>
<td class="border-b border-default px-3 py-2.5 text-secondary"><div v-for="video in row.videos" :key="`${video.name}-${video.watchedAt}`" class="whitespace-nowrap">{{ video.watchedAt ? video.watchedAt.slice(0, 19).replace('T', ' ') : '--' }}</div><span v-if="!row.videos.length">--</span></td>
<td class="border-b border-default px-3 py-2.5"><span class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold" :class="row.status === 'completed' ? 'bg-emerald-50 text-emerald-700' : 'bg-amber-50 text-amber-700'">{{ $t(`chat.training.lean.status.${row.status}`) }}</span></td>
<td class="border-b border-default px-3 py-2.5 text-secondary"><div class="min-w-48 whitespace-pre-wrap break-words">{{ row.summaryText || '--' }}</div></td>
<td v-if="group.key === 'incomplete'" class="border-b border-default px-3 py-2.5">
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-lg bg-amber-500 px-2.5 py-1.5 text-xs font-medium text-white transition hover:bg-amber-600 disabled:cursor-not-allowed disabled:opacity-60"
:disabled="workspace.leanReminderLoading[row.userId]"
@click="workspace.remindLeanTrainingMember(row.userId)"
>
<Bell class="h-3.5 w-3.5" />
{{ workspace.leanReminderLoading[row.userId] ? $t('chat.training.lean.reminder.sending') : $t('chat.training.lean.reminder.action') }}
</button>
</td>
</tr>
<tr v-if="group.rows.length === 0">
<td :colspan="group.key === 'incomplete' ? 8 : 7" class="px-4 py-6 text-center text-sm text-muted">{{ $t('chat.training.lean.dashboard.empty') }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>