feat(training): 新增精益培训视频与周任务管理
This commit is contained in:
1 parent
e5ede471fd
commit
a69814c409
32 files changed
+1619
-55
No files matched your search
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/api/training.api.ts
|
||||
* 用途:培训工作区专用 HTTP API,负责员工进度读取/保存、HR 记录查询、统计和导出。
|
||||
* 用途:培训工作区专用 HTTP API,负责员工进度读取/保存、HR 记录查询、统计导出和精益任务提醒。
|
||||
* 依赖:shared/api/client、auth headers、training.types。
|
||||
* 逻辑:把后端 training 领域的 snake_case 返回值统一映射成前端工作区需要的 camelCase 结构。
|
||||
* 逻辑:把后端 training 领域的 snake_case 返回值统一映射成前端工作区需要的 camelCase 结构,并提交精益未完成人员提醒请求。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
@@ -15,10 +15,37 @@ import type {
|
||||
TrainingRecord,
|
||||
TrainingStage,
|
||||
TrainingStats,
|
||||
LeanTrainingDashboard,
|
||||
LeanTrainingDashboardRow,
|
||||
LeanTrainingWeeklyTask,
|
||||
TrainingType,
|
||||
TrainingTypeOption,
|
||||
} from '../training/training.types';
|
||||
|
||||
type LeanTrainingTaskApi = {
|
||||
id: number; week_key: string; due_at: string; video_resource_ids: number[];
|
||||
target_roles: string[]; target_user_ids: number[];
|
||||
videos: Array<{ id: number; name: string }>; status: string; min_summary_length: number;
|
||||
};
|
||||
|
||||
type LeanTrainingDashboardRowApi = {
|
||||
id?: number; user_id: number; employee_id?: string | null; name: string; department?: string | null;
|
||||
videos: Array<{ name: string; watched_at?: string | null }>;
|
||||
summary_text?: string | null; status: 'completed' | 'incomplete'; completed_at?: string | null;
|
||||
};
|
||||
|
||||
const mapLeanTask = (data: LeanTrainingTaskApi): LeanTrainingWeeklyTask => ({
|
||||
id: data.id, weekKey: data.week_key, dueAt: data.due_at, videoResourceIds: data.video_resource_ids || [],
|
||||
targetRoles: data.target_roles || [], targetUserIds: data.target_user_ids || [],
|
||||
videos: data.videos || [], status: data.status, minSummaryLength: data.min_summary_length,
|
||||
});
|
||||
|
||||
const mapLeanDashboardRow = (data: LeanTrainingDashboardRowApi): LeanTrainingDashboardRow => ({
|
||||
id: data.id, userId: data.user_id, employeeId: data.employee_id, name: data.name, department: data.department,
|
||||
videos: (data.videos || []).map((item) => ({ name: item.name, watchedAt: item.watched_at })),
|
||||
summaryText: data.summary_text, status: data.status, completedAt: data.completed_at,
|
||||
});
|
||||
|
||||
type TrainingRecordApi = {
|
||||
id: number;
|
||||
user_id?: number;
|
||||
@@ -229,6 +256,31 @@ export async function getMyTrainingTypes(): Promise<TrainingTypeOption[]> {
|
||||
return requestJson<TrainingTypeOption[]>('/api/user/training-types', authHeaders());
|
||||
}
|
||||
|
||||
export async function getCurrentLeanTrainingTask(): Promise<LeanTrainingWeeklyTask | null> {
|
||||
const response = await requestJson<LeanTrainingTaskApi | null>('/api/user/lean-training/current-task', authHeaders());
|
||||
return response ? mapLeanTask(response) : null;
|
||||
}
|
||||
|
||||
export async function saveMyLeanTrainingCompletion(payload: { weeklyTaskId: number; watchedAt: Record<string, string>; summaryText: string }): Promise<LeanTrainingDashboardRow> {
|
||||
const response = await requestJson<LeanTrainingDashboardRowApi>('/api/user/lean-training/completions', {
|
||||
method: 'PUT', ...jsonAuthHeaders(), body: JSON.stringify({ weekly_task_id: payload.weeklyTaskId, watched_at: payload.watchedAt, summary_text: payload.summaryText }),
|
||||
});
|
||||
return mapLeanDashboardRow(response);
|
||||
}
|
||||
|
||||
export async function getLeanTrainingDashboard(): Promise<LeanTrainingDashboard> {
|
||||
const response = await requestJson<{ task: LeanTrainingTaskApi | null; completed: LeanTrainingDashboardRowApi[]; incomplete: LeanTrainingDashboardRowApi[] }>('/api/admin/lean-training/dashboard', authHeaders());
|
||||
return { task: response.task ? mapLeanTask(response.task) : null, completed: (response.completed || []).map(mapLeanDashboardRow), incomplete: (response.incomplete || []).map(mapLeanDashboardRow) };
|
||||
}
|
||||
|
||||
export async function sendLeanTrainingReminders(weeklyTaskId: number, userIds: number[]): Promise<{ created: number; skipped: number; failed: number }> {
|
||||
return requestJson<{ created: number; skipped: number; failed: number }>(`/api/admin/lean-training/weekly-tasks/${weeklyTaskId}/reminders`, {
|
||||
method: 'POST',
|
||||
...jsonAuthHeaders(),
|
||||
body: JSON.stringify({ user_ids: userIds }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function getMyTrainingProgress(type: string = 'onboarding'): Promise<TrainingProgressRecord | null> {
|
||||
const data = await requestJson<TrainingRecordApi | null>(`/api/user/training-record?type=${encodeURIComponent(type)}`, authHeaders());
|
||||
return data ? mapTrainingProgressRecord(data) : null;
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* features/chat/composables/useTrainingWorkspace.ts
|
||||
* 用途:封装员工培训 Agent 的工作区状态,包括学员考试流、进度持久化与 HR 真实统计导出。
|
||||
* 用途:封装员工培训 Agent 的工作区状态,包括学员考试流、进度持久化、HR 真实统计导出与精益定向提醒。
|
||||
* 依赖:Vue reactivity、vue-i18n、training.api,以及 training.types。
|
||||
* 逻辑:仅在培训 Agent 下启用;学员端按“视频 -> 知识点 -> 一题一答 -> 结算”推进,并把进度同步到后端;
|
||||
* 非安全培训页额外按后台配置动态渲染进度项与步骤说明文案。
|
||||
* 非安全培训页额外按后台配置动态渲染进度项与步骤说明文案;精益管理面板通过独立状态提交未完成人员提醒。
|
||||
*/
|
||||
import { computed, ref, watch, type ComputedRef } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -15,8 +15,12 @@ import {
|
||||
getMyTrainingProgress,
|
||||
getMyTrainingTypes,
|
||||
getTrainingStats,
|
||||
getCurrentLeanTrainingTask,
|
||||
getLeanTrainingDashboard,
|
||||
sendLeanTrainingReminders,
|
||||
listTrainingRecords,
|
||||
saveMyTrainingProgress,
|
||||
saveMyLeanTrainingCompletion,
|
||||
} from '@/features/chat/api/training.api';
|
||||
import type {
|
||||
SafetyProgressState,
|
||||
@@ -36,6 +40,8 @@ import type {
|
||||
TrainingType,
|
||||
TrainingTypeOption,
|
||||
TrainingWorkspaceView,
|
||||
LeanTrainingDashboard,
|
||||
LeanTrainingWeeklyTask,
|
||||
} from '@/features/chat/training/training.types';
|
||||
import {
|
||||
SAFETY_STAGE_GUIDE_USAGE_MAP,
|
||||
@@ -107,7 +113,14 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
});
|
||||
const hasAuthenticatedUser = computed(() => Boolean(String(currentUser.value?.username || '').trim()));
|
||||
const isAdminViewer = computed(() => Boolean(currentUser.value?.feature_permissions?.training_hr_manage));
|
||||
const defaultActiveView = computed<TrainingWorkspaceView>(() => (isAdminViewer.value ? 'admin' : 'learner'));
|
||||
const canViewLeanDashboard = computed(() => isAdminViewer.value);
|
||||
const canManageTrainingWorkspace = computed(() => isAdminViewer.value);
|
||||
const leanTask = ref<LeanTrainingWeeklyTask | null>(null);
|
||||
const leanDashboard = ref<LeanTrainingDashboard>({ task: null, completed: [], incomplete: [] });
|
||||
const leanReminderLoading = ref<Record<number, boolean>>({});
|
||||
const leanSummaryText = ref('');
|
||||
const leanWatchedAt = ref<Record<string, string>>({});
|
||||
const defaultActiveView = computed<TrainingWorkspaceView>(() => (canManageTrainingWorkspace.value ? 'admin' : 'learner'));
|
||||
const activeView = ref<TrainingWorkspaceView>('learner');
|
||||
const learnerTab = ref<TrainingType>('onboarding');
|
||||
const trainingTypes = ref<TrainingTypeOption[]>([
|
||||
@@ -172,7 +185,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
});
|
||||
|
||||
watch(
|
||||
[isTrainingAgent, isAdminViewer],
|
||||
[isTrainingAgent, canManageTrainingWorkspace],
|
||||
([enabled]) => {
|
||||
if (!enabled) return;
|
||||
activeView.value = defaultActiveView.value;
|
||||
@@ -780,6 +793,44 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
}
|
||||
};
|
||||
|
||||
/** 读取精益周任务与受权限约束的完成/未完成名单。 */
|
||||
const loadLeanTraining = async () => {
|
||||
if (!isTrainingAgent.value || !hasAuthenticatedUser.value) return;
|
||||
try {
|
||||
leanTask.value = await getCurrentLeanTrainingTask();
|
||||
if (canViewLeanDashboard.value) leanDashboard.value = await getLeanTrainingDashboard();
|
||||
} catch {
|
||||
leanTask.value = null;
|
||||
leanDashboard.value = { task: null, completed: [], incomplete: [] };
|
||||
}
|
||||
};
|
||||
|
||||
/** 标记视频已完整观看并记录观看时间,供精益周任务提交时一并交由服务端校验。 */
|
||||
const markLeanVideoWatched = (resourceId: number) => {
|
||||
leanWatchedAt.value[String(resourceId)] = new Date().toISOString();
|
||||
};
|
||||
|
||||
/** 提交精益学习感悟;服务端校验两个视频与至少 50 字,成功后刷新个人和管理看板。 */
|
||||
const submitLeanTrainingCompletion = async () => {
|
||||
if (!leanTask.value) return;
|
||||
await saveMyLeanTrainingCompletion({ weeklyTaskId: leanTask.value.id, watchedAt: leanWatchedAt.value, summaryText: leanSummaryText.value });
|
||||
await loadLeanTraining();
|
||||
};
|
||||
|
||||
const remindLeanTrainingMember = async (userId: number) => {
|
||||
if (!leanDashboard.value.task || leanReminderLoading.value[userId]) return;
|
||||
leanReminderLoading.value[userId] = true;
|
||||
try {
|
||||
const result = await sendLeanTrainingReminders(leanDashboard.value.task.id, [userId]);
|
||||
msg.success(t('chat.training.lean.reminder.success', { count: result.created }));
|
||||
await loadLeanTraining();
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('chat.training.lean.reminder.failed'));
|
||||
} finally {
|
||||
leanReminderLoading.value[userId] = false;
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
[
|
||||
currentAgent,
|
||||
@@ -812,6 +863,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
void loadTrainingTypes();
|
||||
void loadTrainingConfig();
|
||||
void loadTrainingProgress();
|
||||
void loadLeanTraining();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
@@ -1160,6 +1212,13 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
return {
|
||||
isTrainingAgent,
|
||||
isAdminViewer,
|
||||
canViewLeanDashboard,
|
||||
canManageTrainingWorkspace,
|
||||
leanTask,
|
||||
leanDashboard,
|
||||
leanReminderLoading,
|
||||
leanSummaryText,
|
||||
leanWatchedAt,
|
||||
isHydrated,
|
||||
trainingConfigLoading,
|
||||
hasPublishedTrainingConfig,
|
||||
@@ -1230,6 +1289,10 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
restartExam,
|
||||
setSafetyStage,
|
||||
exportRecords,
|
||||
loadLeanTraining,
|
||||
markLeanVideoWatched,
|
||||
submitLeanTrainingCompletion,
|
||||
remindLeanTrainingMember,
|
||||
showVideoModal,
|
||||
videoUrl,
|
||||
startMaterialTimer,
|
||||
|
||||
@@ -139,3 +139,33 @@ export interface TrainingStats {
|
||||
passRate: number;
|
||||
averageScore: number;
|
||||
}
|
||||
|
||||
export interface LeanTrainingWeeklyTask {
|
||||
id: number;
|
||||
weekKey: string;
|
||||
dueAt: string;
|
||||
videoResourceIds: number[];
|
||||
targetRoles: string[];
|
||||
targetUserIds: number[];
|
||||
videos: Array<{ id: number; name: string }>;
|
||||
status: string;
|
||||
minSummaryLength: number;
|
||||
}
|
||||
|
||||
export interface LeanTrainingDashboardRow {
|
||||
id?: number;
|
||||
userId: number;
|
||||
employeeId?: string | null;
|
||||
name: string;
|
||||
department?: string | null;
|
||||
videos: Array<{ name: string; watchedAt?: string | null }>;
|
||||
summaryText?: string | null;
|
||||
status: 'completed' | 'incomplete';
|
||||
completedAt?: string | null;
|
||||
}
|
||||
|
||||
export interface LeanTrainingDashboard {
|
||||
task: LeanTrainingWeeklyTask | null;
|
||||
completed: LeanTrainingDashboardRow[];
|
||||
incomplete: LeanTrainingDashboardRow[];
|
||||
}
|
||||
Reference in new issue
Block a user