Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
331cfdc361
14 files changed
+769
-83
No files matched your search
@@ -205,6 +205,7 @@ function mapTrainingRecord(data: TrainingRecordApi): TrainingRecord {
|
||||
score: progress.score,
|
||||
attempts: progress.attempts,
|
||||
status: progress.status,
|
||||
answerDetails: progress.answerDetails,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ import {
|
||||
ChevronUp,
|
||||
ClipboardCheck,
|
||||
Download,
|
||||
FileText,
|
||||
PlayCircle,
|
||||
RefreshCcw,
|
||||
ShieldCheck,
|
||||
Target,
|
||||
User,
|
||||
FileText,
|
||||
Video,
|
||||
Lock,
|
||||
XCircle,
|
||||
@@ -30,6 +30,9 @@ import { useTrainingWorkspace } from '@/features/chat/composables/useTrainingWor
|
||||
import FilePreviewModal from '@/shared/components/FilePreviewModal.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { resolveTrainingExamPdfGuide, type TrainingGuideLike } from '@/features/chat/training/trainingWorkspace.utils';
|
||||
import { getMyTrainingConfig } from '@/features/chat/api/training.api';
|
||||
import type { TrainingRecord } from '@/features/chat/training/training.types';
|
||||
import html2pdf from 'html2pdf.js';
|
||||
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
@@ -98,6 +101,74 @@ const handleVideoEnded = () => {
|
||||
workspace.stopMaterialTimer();
|
||||
};
|
||||
|
||||
const reportModalVisible = ref(false);
|
||||
const currentReportRecord = ref<TrainingRecord | null>(null);
|
||||
const reportQuestions = ref<Record<string, any>>({});
|
||||
const reportLoading = ref(false);
|
||||
|
||||
const openReport = async (record: TrainingRecord) => {
|
||||
currentReportRecord.value = record;
|
||||
reportModalVisible.value = true;
|
||||
reportLoading.value = true;
|
||||
try {
|
||||
const config = await getMyTrainingConfig(record.trainingType || 'onboarding');
|
||||
const qMap: Record<string, any> = {};
|
||||
if (config?.resources) {
|
||||
config.resources.forEach(r => {
|
||||
if (Array.isArray(r.inlineQuestions)) {
|
||||
r.inlineQuestions.forEach((q: any) => {
|
||||
qMap[q.id] = q;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
reportQuestions.value = qMap;
|
||||
} catch (err) {
|
||||
console.error('Failed to load config for report', err);
|
||||
} finally {
|
||||
reportLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const closeReport = () => {
|
||||
reportModalVisible.value = false;
|
||||
currentReportRecord.value = null;
|
||||
};
|
||||
|
||||
const printReport = async () => {
|
||||
const element = document.getElementById('report-modal-content');
|
||||
const report = currentReportRecord.value;
|
||||
if (!element || !report) return;
|
||||
const fileName = `${report.name}_${report.trainingType === 'onboarding' ? t('chat.training.hr.filters.typeOnboarding') : report.trainingType === 'safety' ? t('chat.training.hr.filters.typeSafety') : report.trainingType}_考试报告.pdf`;
|
||||
|
||||
const opt = {
|
||||
margin: [15, 15, 15, 15] as [number, number, number, number],
|
||||
filename: fileName,
|
||||
image: { type: 'jpeg' as const, quality: 0.98 },
|
||||
html2canvas: {
|
||||
scale: 2,
|
||||
useCORS: true,
|
||||
letterRendering: true,
|
||||
windowWidth: 794,
|
||||
scrollX: 0,
|
||||
scrollY: 0,
|
||||
},
|
||||
pagebreak: {
|
||||
mode: ['css', 'legacy'] as const,
|
||||
avoid: ['.report-question', '.report-header-info', '.report-option'] as string[],
|
||||
},
|
||||
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' as const }
|
||||
};
|
||||
|
||||
try {
|
||||
await html2pdf().set(opt).from(element).save();
|
||||
msg.success(t('chat.training.hr.report.downloadSuccess') || 'PDF 下载成功');
|
||||
} catch (error) {
|
||||
console.error('Failed to generate PDF:', error);
|
||||
msg.error(t('chat.training.hr.report.downloadFailed') || 'PDF 生成失败');
|
||||
}
|
||||
};
|
||||
|
||||
const reportVideoDebugEvent = (event: Event) => {
|
||||
const video = event.target as HTMLVideoElement;
|
||||
// #region debug-point A-E:ios-video-runtime
|
||||
@@ -247,6 +318,36 @@ const isMaterialCompleted = (material: any) => {
|
||||
|
||||
const currentPreviewVideoUrl = ref('');
|
||||
|
||||
const videoCountdownSeconds = ref(0);
|
||||
let videoCountdownTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const startVideoCountdown = () => {
|
||||
if (videoCountdownTimer) {
|
||||
clearInterval(videoCountdownTimer);
|
||||
videoCountdownTimer = null;
|
||||
}
|
||||
const requiredDuration = workspace.currentViewingMaterialRequiredDuration;
|
||||
if (requiredDuration && requiredDuration > 0) {
|
||||
videoCountdownSeconds.value = requiredDuration * 60;
|
||||
videoCountdownTimer = setInterval(() => {
|
||||
if (videoCountdownSeconds.value > 0) {
|
||||
videoCountdownSeconds.value--;
|
||||
} else {
|
||||
if (videoCountdownTimer) clearInterval(videoCountdownTimer);
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
videoCountdownSeconds.value = 0;
|
||||
}
|
||||
};
|
||||
|
||||
const stopVideoCountdown = () => {
|
||||
if (videoCountdownTimer) {
|
||||
clearInterval(videoCountdownTimer);
|
||||
videoCountdownTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
const handleMaterialClick = (material: any) => {
|
||||
const url = material.resource?.fileUrl;
|
||||
if (!url) {
|
||||
@@ -255,18 +356,18 @@ const handleMaterialClick = (material: any) => {
|
||||
}
|
||||
|
||||
if (material.resource?.fileType === 'video') {
|
||||
workspace.currentViewingMaterialId = material.id;
|
||||
workspace.showVideoModal = true;
|
||||
currentPreviewVideoUrl.value = url;
|
||||
// 当点击视频资料时,我们应该记录正在观看的资源ID,以便后续更新进度
|
||||
workspace.currentViewingMaterialId = material.id;
|
||||
startVideoCountdown();
|
||||
} else {
|
||||
workspace.currentViewingMaterialId = material.id;
|
||||
previewFile.value = {
|
||||
name: material.title || material.resource?.fileName || '资料预览',
|
||||
url: url,
|
||||
actualExt: material.resource?.fileType,
|
||||
};
|
||||
showFilePreview.value = true;
|
||||
workspace.currentViewingMaterialId = material.id;
|
||||
}
|
||||
workspace.startMaterialTimer(material.id);
|
||||
};
|
||||
@@ -281,6 +382,7 @@ const handlePreviewClose = (val: boolean) => {
|
||||
const handleVideoModalClose = () => {
|
||||
workspace.showVideoModal = false;
|
||||
currentPreviewVideoUrl.value = '';
|
||||
stopVideoCountdown();
|
||||
workspace.stopMaterialTimer();
|
||||
};
|
||||
const jumpToExamQuestion = (index: number) => {
|
||||
@@ -858,10 +960,6 @@ const currentSafetyStageText = computed(() => {
|
||||
{{ $t('chat.training.safety.progressHint') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-lg bg-surface-soft px-2.5 py-1 text-center">
|
||||
<div class="text-xs text-muted">{{ $t('chat.training.progressPercent') }}</div>
|
||||
<div class="text-base font-semibold leading-none text-primary">{{ workspace.safetyProgressPercent }}%</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-2 grid grid-cols-2 gap-1 lg:grid-cols-4">
|
||||
@@ -1269,11 +1367,13 @@ const currentSafetyStageText = computed(() => {
|
||||
<tr>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.joinDate') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.completionDate') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.trainingType') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.department') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.name') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.employeeId') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.score') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.attempts') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.trainingReport') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.hr.columns.status') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -1281,11 +1381,18 @@ const currentSafetyStageText = computed(() => {
|
||||
<tr v-for="record in workspace.filteredRecords" :key="record.id" class="odd:bg-white even:bg-surface-soft/30">
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ record.joinDate }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ record.completionDate || '--' }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ record.trainingType === 'onboarding' ? $t('chat.training.hr.filters.typeOnboarding') : record.trainingType === 'safety' ? $t('chat.training.hr.filters.typeSafety') : (record.trainingType || '--') }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ record.department }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 font-medium text-primary">{{ record.name }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ record.employeeId }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ record.score ?? '--' }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ record.attempts }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">
|
||||
<button v-if="record.status === 'passed' || record.status === 'failed'" @click="openReport(record)" class="text-brand-600 hover:text-brand-700 transition" :title="$t('chat.training.hr.report.title')">
|
||||
<FileText class="w-5 h-5" />
|
||||
</button>
|
||||
<span v-else class="text-muted">--</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"
|
||||
@@ -1314,9 +1421,14 @@ const currentSafetyStageText = computed(() => {
|
||||
<Teleport to="body">
|
||||
<div v-if="workspace.showVideoModal" class="fixed inset-0 z-[100] flex items-center justify-center bg-slate-950/80 p-4 backdrop-blur-sm" @click.self="handleVideoModalClose">
|
||||
<div class="relative w-full max-w-4xl overflow-hidden rounded-3xl bg-black shadow-2xl">
|
||||
<button @click="handleVideoModalClose" class="absolute top-4 right-4 z-10 h-10 w-10 flex items-center justify-center rounded-full bg-white/10 text-white hover:bg-white/20 transition backdrop-blur-md">
|
||||
<XCircle class="h-6 w-6" />
|
||||
</button>
|
||||
<div class="absolute top-4 right-4 z-10 flex items-center gap-2">
|
||||
<div v-if="videoCountdownSeconds > 0" class="flex items-center justify-center h-10 w-10 rounded-full border border-red-200 bg-red-50 text-red-500 font-semibold text-xs shadow-sm backdrop-blur-md">
|
||||
{{ videoCountdownSeconds }}s
|
||||
</div>
|
||||
<button @click="handleVideoModalClose" class="h-10 w-10 flex items-center justify-center rounded-full bg-white/10 text-white hover:bg-white/20 transition backdrop-blur-md">
|
||||
<XCircle class="h-6 w-6" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="aspect-video bg-black">
|
||||
<video
|
||||
controls
|
||||
@@ -1346,7 +1458,199 @@ const currentSafetyStageText = computed(() => {
|
||||
:file="previewFile"
|
||||
:agent-id="workspace.currentTrainingAgentId || undefined"
|
||||
:auth-headers="getAuthHeaders()"
|
||||
:required-duration="workspace.currentViewingMaterialRequiredDuration"
|
||||
@update:modelValue="handlePreviewClose"
|
||||
/>
|
||||
|
||||
<div v-if="reportModalVisible" class="fixed inset-0 z-[100] flex items-center justify-center bg-slate-950/80 p-4 backdrop-blur-sm" @click.self="closeReport">
|
||||
<div class="relative w-full max-w-4xl max-h-[90vh] flex flex-col overflow-hidden rounded-3xl bg-white shadow-2xl">
|
||||
<div class="flex items-center justify-between border-b border-default px-6 py-4">
|
||||
<h3 class="text-lg font-semibold text-primary">{{ $t('chat.training.hr.report.title') }}</h3>
|
||||
<div class="flex items-center gap-3">
|
||||
<button @click="printReport" class="flex items-center gap-2 rounded-xl bg-brand-50 px-4 py-2 text-sm font-medium text-brand-600 transition hover:bg-brand-100">
|
||||
<Download class="w-4 h-4" />
|
||||
{{ $t('chat.training.hr.report.download') }}
|
||||
</button>
|
||||
<button @click="closeReport" class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-soft text-secondary hover:bg-surface hover:text-primary transition">
|
||||
<XCircle class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-6 report-print-container" id="report-modal-content">
|
||||
<div class="report-pdf-page">
|
||||
<div v-if="reportLoading" class="flex h-full items-center justify-center">
|
||||
<div class="h-8 w-8 animate-spin rounded-full border-4 border-brand-200 border-t-brand-600"></div>
|
||||
</div>
|
||||
<div v-else-if="currentReportRecord">
|
||||
<!-- Header Info -->
|
||||
<div class="report-header-info mb-8 rounded-2xl bg-surface-soft p-6">
|
||||
<h2 class="mb-4 text-center text-2xl font-bold text-primary">{{ currentReportRecord.trainingType === 'onboarding' ? $t('chat.training.hr.filters.typeOnboarding') : currentReportRecord.trainingType === 'safety' ? $t('chat.training.hr.filters.typeSafety') : currentReportRecord.trainingType }} {{ $t('chat.training.hr.report.title') }}</h2>
|
||||
<div class="grid grid-cols-2 gap-4 sm:grid-cols-4">
|
||||
<div>
|
||||
<div class="text-xs text-secondary">{{ $t('chat.training.hr.columns.name') }}</div>
|
||||
<div class="font-medium text-primary">{{ currentReportRecord.name }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-xs text-secondary">{{ $t('chat.training.hr.columns.department') }}</div>
|
||||
<div class="font-medium text-primary">{{ currentReportRecord.department }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-xs text-secondary">{{ $t('chat.training.hr.columns.employeeId') }}</div>
|
||||
<div class="font-medium text-primary">{{ currentReportRecord.employeeId }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-xs text-secondary">{{ $t('chat.training.hr.columns.score') }}</div>
|
||||
<div class="font-medium" :class="currentReportRecord.status === 'passed' ? 'text-emerald-600' : 'text-rose-600'">
|
||||
{{ currentReportRecord.score ?? '--' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Exam Details -->
|
||||
<div class="space-y-6">
|
||||
<div v-for="(answer, idx) in currentReportRecord.answerDetails || []" :key="answer.questionId" class="report-question rounded-xl border border-default p-4">
|
||||
<div class="report-question-header mb-3">
|
||||
<div class="report-question-title font-medium text-primary">
|
||||
<span class="mr-2 text-secondary">{{ idx + 1 }}.</span>
|
||||
{{ reportQuestions[answer.questionId]?.prompt || `[ID: ${answer.questionId}]` }}
|
||||
</div>
|
||||
<div class="report-question-result">
|
||||
<span v-if="answer.correct" class="inline-flex rounded-full bg-emerald-50 px-2 py-1 text-xs font-semibold text-emerald-700">正确</span>
|
||||
<span v-else class="inline-flex rounded-full bg-rose-50 px-2 py-1 text-xs font-semibold text-rose-700">错误</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="report-options pl-6">
|
||||
<div v-for="(opt, optIdx) in reportQuestions[answer.questionId]?.options || []" :key="opt.id"
|
||||
class="report-option text-sm"
|
||||
:class="{
|
||||
'font-semibold text-emerald-600': opt.id === reportQuestions[answer.questionId]?.answer,
|
||||
'text-rose-600': !answer.correct && opt.id === answer.selectedOptionId,
|
||||
'text-secondary': opt.id !== reportQuestions[answer.questionId]?.answer && opt.id !== answer.selectedOptionId
|
||||
}"
|
||||
>
|
||||
<span class="report-option-marker"
|
||||
:class="{
|
||||
'border-emerald-200 bg-emerald-50 text-emerald-600': opt.id === reportQuestions[answer.questionId]?.answer,
|
||||
'border-rose-200 bg-rose-50 text-rose-600': !answer.correct && opt.id === answer.selectedOptionId,
|
||||
'border-default': opt.id !== reportQuestions[answer.questionId]?.answer && opt.id !== answer.selectedOptionId
|
||||
}"
|
||||
> {{ String.fromCharCode(65 + Number(optIdx)) }}</span>
|
||||
<span class="report-option-text">{{ opt.label }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="!reportQuestions[answer.questionId]" class="text-sm text-secondary">
|
||||
<div class="mb-1">Selected Option: {{ answer.selectedOptionId }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!currentReportRecord.answerDetails?.length" class="text-center text-sm text-secondary py-8">
|
||||
{{ $t('chat.training.hr.report.noReport') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.report-pdf-page {
|
||||
width: 100%;
|
||||
max-width: 794px;
|
||||
min-height: 1123px;
|
||||
margin: 0 auto;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.report-question-header {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
align-items: start;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.report-question-title {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.report-question-result {
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.report-options {
|
||||
display: grid;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.report-header-info,
|
||||
.report-question,
|
||||
.report-option {
|
||||
break-inside: avoid;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.report-question {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.report-option {
|
||||
display: grid;
|
||||
grid-template-columns: 1.25rem minmax(0, 1fr);
|
||||
align-items: start;
|
||||
column-gap: 0.5rem;
|
||||
min-width: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.report-option-marker {
|
||||
display: inline-flex;
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
border-width: 1px;
|
||||
border-radius: 9999px;
|
||||
font-size: 0.75rem;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.report-option-text {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
@media print {
|
||||
body > *:not(.report-print-container) {
|
||||
display: none !important;
|
||||
}
|
||||
.report-print-container {
|
||||
position: absolute !important;
|
||||
left: 0 !important;
|
||||
top: 0 !important;
|
||||
width: 794px !important;
|
||||
max-width: none !important;
|
||||
min-height: 1123px !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
overflow: visible !important;
|
||||
background: white !important;
|
||||
}
|
||||
.report-pdf-page {
|
||||
width: 794px !important;
|
||||
max-width: none !important;
|
||||
min-height: 1123px !important;
|
||||
margin: 0 !important;
|
||||
padding: 32px !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -273,12 +273,26 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
));
|
||||
const canEnterResultStage = computed(() => stage.value === 'result');
|
||||
const safetyProgressPercent = computed(() => {
|
||||
if (safetyStage.value === 'company') return 25;
|
||||
if (safetyStage.value === 'department') return 50;
|
||||
if (safetyStage.value === 'team') return 75;
|
||||
if (safetyStage.value === 'exam') return 90;
|
||||
return 100;
|
||||
if (safetyStage.value === 'result') return 100;
|
||||
|
||||
let completedCount = 0;
|
||||
if (isStageCompleted('company')) completedCount++;
|
||||
if (isStageCompleted('department')) completedCount++;
|
||||
if (isStageCompleted('team')) completedCount++;
|
||||
|
||||
return Math.round((completedCount / 3) * 75) || 10; // Start at 10% or just based on completed
|
||||
});
|
||||
const isStageCompleted = (stageKey: SafetyLearningStage) => {
|
||||
const materials = resolveSafetyStageMaterials(stageKey);
|
||||
if (!materials.length) return true;
|
||||
return materials.every(m => {
|
||||
if (m.id == null) return true;
|
||||
const progress = safetyProgress.value.resource_progress?.[String(m.id)];
|
||||
return progress?.completed;
|
||||
});
|
||||
};
|
||||
|
||||
const safetyStepItems = computed(() => {
|
||||
const base: Array<{ id: SafetyStage extends infer U ? U : never; labelKey: string }> = [
|
||||
{ id: 'company', labelKey: 'chat.training.safety.steps.company' },
|
||||
@@ -288,26 +302,22 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
];
|
||||
return base.map((item) => {
|
||||
let status: 'completed' | 'active' | 'pending' | 'locked' = 'pending';
|
||||
if (item.id === 'company') {
|
||||
status = safetyProgress.value.company === 'completed'
|
||||
? 'completed'
|
||||
: safetyProgress.value.company === 'active' ? 'active' : 'pending';
|
||||
} else if (item.id === 'department') {
|
||||
status = safetyProgress.value.department === 'completed'
|
||||
? 'completed'
|
||||
: safetyProgress.value.department === 'active' ? 'active' : 'pending';
|
||||
} else if (item.id === 'team') {
|
||||
status = safetyProgress.value.team === 'completed'
|
||||
? 'completed'
|
||||
: safetyProgress.value.team === 'active' ? 'active' : 'pending';
|
||||
if (item.id === 'company' || item.id === 'department' || item.id === 'team') {
|
||||
const completed = isStageCompleted(item.id);
|
||||
if (safetyViewStage.value === item.id) {
|
||||
status = 'active';
|
||||
} else if (completed) {
|
||||
status = 'completed';
|
||||
} else {
|
||||
status = 'pending';
|
||||
}
|
||||
} else if (item.id === 'exam') {
|
||||
status = ['exam', 'result'].includes(safetyStage.value)
|
||||
? (safetyStage.value === 'exam' ? 'active' : 'completed')
|
||||
: (safetyProgress.value.company === 'completed'
|
||||
&& safetyProgress.value.department === 'completed'
|
||||
&& safetyProgress.value.team === 'completed'
|
||||
? 'pending'
|
||||
: 'locked');
|
||||
const allCompleted = isStageCompleted('company') && isStageCompleted('department') && isStageCompleted('team');
|
||||
if (['exam', 'result'].includes(safetyStage.value)) {
|
||||
status = safetyStage.value === 'exam' ? 'active' : 'completed';
|
||||
} else {
|
||||
status = allCompleted ? 'pending' : 'locked';
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: item.id,
|
||||
@@ -519,8 +529,30 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
examMode.value = record.examMode || 'unified';
|
||||
if (learnerTab.value === 'safety') {
|
||||
safetyStage.value = record.safetyStage || 'company';
|
||||
safetyProgress.value = record.safetyProgress;
|
||||
safetyViewStage.value = record.safetyStage || 'company';
|
||||
// Ensure resource_progress is preserved when merging from backend
|
||||
safetyProgress.value = {
|
||||
...record.safetyProgress,
|
||||
resource_progress: record.safetyProgress?.resource_progress || safetyProgress.value.resource_progress || {}
|
||||
};
|
||||
|
||||
// Sync legacy fields with actual resource completion
|
||||
safetyProgress.value.company = isStageCompleted('company') ? 'completed' : 'active';
|
||||
safetyProgress.value.department = isStageCompleted('department') ? 'completed' : 'active';
|
||||
safetyProgress.value.team = isStageCompleted('team') ? 'completed' : 'active';
|
||||
|
||||
if (safetyStage.value !== 'exam' && safetyStage.value !== 'result') {
|
||||
if (!isStageCompleted('company')) {
|
||||
safetyViewStage.value = 'company';
|
||||
} else if (!isStageCompleted('department')) {
|
||||
safetyViewStage.value = 'department';
|
||||
} else if (!isStageCompleted('team')) {
|
||||
safetyViewStage.value = 'team';
|
||||
} else {
|
||||
safetyViewStage.value = 'company';
|
||||
}
|
||||
} else {
|
||||
safetyViewStage.value = record.safetyStage || 'company';
|
||||
}
|
||||
}
|
||||
stage.value = record.stage;
|
||||
syncExamQuestionIndex(record.currentQuestionIndex);
|
||||
@@ -735,15 +767,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const markVideoCompleted = () => {
|
||||
if (!hasPublishedTrainingConfig.value || !videoUrl.value) return;
|
||||
if (learnerTab.value === 'safety') {
|
||||
if (safetyStage.value === 'company') {
|
||||
resetSafetyProgress('department');
|
||||
} else if (safetyStage.value === 'department') {
|
||||
resetSafetyProgress('team');
|
||||
} else if (safetyStage.value === 'team') {
|
||||
resetSafetyProgress('exam');
|
||||
enterSafetyExam();
|
||||
}
|
||||
void persistProgress();
|
||||
checkAndAdvanceStage();
|
||||
return;
|
||||
}
|
||||
stage.value = 'summary';
|
||||
@@ -861,7 +885,13 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
if (!hasPublishedTrainingConfig.value) return;
|
||||
const target = safetyStepItems.value.find((item) => item.id === nextStage);
|
||||
if (!target || target.status === 'locked') return;
|
||||
safetyViewStage.value = nextStage;
|
||||
|
||||
if (nextStage === 'exam' && safetyStage.value !== 'exam' && safetyStage.value !== 'result') {
|
||||
enterSafetyExam();
|
||||
void persistProgress();
|
||||
} else {
|
||||
safetyViewStage.value = nextStage;
|
||||
}
|
||||
};
|
||||
|
||||
const exportRecords = async () => {
|
||||
@@ -930,6 +960,12 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const currentViewingMaterialId = ref<number | null>(null);
|
||||
const materialStartTime = ref<number>(0);
|
||||
|
||||
const currentViewingMaterialRequiredDuration = computed(() => {
|
||||
if (!currentViewingMaterialId.value) return 0;
|
||||
const resource = (publishedConfig.value?.resources || []).find((item) => String(item.id) === String(currentViewingMaterialId.value));
|
||||
return resource?.requiredDuration || 0;
|
||||
});
|
||||
|
||||
const startMaterialTimer = (materialId: number) => {
|
||||
currentViewingMaterialId.value = materialId;
|
||||
materialStartTime.value = Date.now();
|
||||
@@ -963,32 +999,32 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
};
|
||||
|
||||
const checkAndAdvanceStage = () => {
|
||||
const activeStageMaterials = learnerTab.value === 'safety'
|
||||
? resolveSafetyStageMaterials(activeSafetyLearningStage.value)
|
||||
: publishedTrainingMaterials.value;
|
||||
if (!activeStageMaterials.length) return;
|
||||
const allCompleted = activeStageMaterials.every(m => {
|
||||
if (m.id == null) return true;
|
||||
const progress = safetyProgress.value.resource_progress?.[String(m.id)];
|
||||
return progress?.completed;
|
||||
});
|
||||
|
||||
if (allCompleted) {
|
||||
if (learnerTab.value === 'safety') {
|
||||
if (safetyStage.value === 'company') {
|
||||
resetSafetyProgress('department');
|
||||
} else if (safetyStage.value === 'department') {
|
||||
resetSafetyProgress('team');
|
||||
} else if (safetyStage.value === 'team') {
|
||||
resetSafetyProgress('exam');
|
||||
enterSafetyExam();
|
||||
}
|
||||
} else {
|
||||
stage.value = 'summary';
|
||||
}
|
||||
void persistProgress();
|
||||
// Update legacy string fields to reflect real status based on resources
|
||||
safetyProgress.value.company = isStageCompleted('company') ? 'completed' : 'active';
|
||||
safetyProgress.value.department = isStageCompleted('department') ? 'completed' : 'active';
|
||||
safetyProgress.value.team = isStageCompleted('team') ? 'completed' : 'active';
|
||||
|
||||
if (learnerTab.value === 'safety') {
|
||||
const allSafetyCompleted = isStageCompleted('company') && isStageCompleted('department') && isStageCompleted('team');
|
||||
|
||||
if (allSafetyCompleted && safetyStage.value !== 'exam' && safetyStage.value !== 'result') {
|
||||
safetyStage.value = 'exam';
|
||||
enterSafetyExam();
|
||||
}
|
||||
void persistProgress();
|
||||
} else {
|
||||
void persistProgress();
|
||||
const activeStageMaterials = publishedTrainingMaterials.value;
|
||||
if (!activeStageMaterials.length) return;
|
||||
const allCompleted = activeStageMaterials.every(m => {
|
||||
if (m.id == null) return true;
|
||||
const progress = safetyProgress.value.resource_progress?.[String(m.id)];
|
||||
return progress?.completed;
|
||||
});
|
||||
|
||||
if (allCompleted) {
|
||||
stage.value = 'summary';
|
||||
}
|
||||
void persistProgress();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1084,6 +1120,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
startMaterialTimer,
|
||||
stopMaterialTimer,
|
||||
currentViewingMaterialId,
|
||||
currentViewingMaterialRequiredDuration,
|
||||
currentTrainingAgentId,
|
||||
};
|
||||
}
|
||||
@@ -102,6 +102,7 @@ export interface TrainingRecord {
|
||||
score: number | null;
|
||||
attempts: number;
|
||||
status: TrainingRecordStatus;
|
||||
answerDetails?: TrainingAnswerRecord[];
|
||||
}
|
||||
|
||||
export interface TrainingProgressRecord extends TrainingRecord {
|
||||
|
||||
Reference in new issue
Block a user