diff --git a/backend/app/services/training_service.py b/backend/app/services/training_service.py index 4c743a58..8e782082 100644 --- a/backend/app/services/training_service.py +++ b/backend/app/services/training_service.py @@ -85,7 +85,7 @@ def _normalize_exam_mode(value: Any) -> str: return text -def _build_default_safety_progress(safety_stage: str) -> dict[str, str]: +def _build_default_safety_progress(safety_stage: str) -> dict[str, Any]: """ 根据安全培训当前阶段推导三级学习进度。 @@ -94,7 +94,7 @@ def _build_default_safety_progress(safety_stage: str) -> dict[str, str]: Returns: company、department、team 三个级别的状态快照。 """ - progress: dict[str, str] = {key: "pending" for key in SAFETY_LEVEL_KEYS} + progress: dict[str, Any] = {key: "pending" for key in SAFETY_LEVEL_KEYS} if safety_stage == "company": progress["company"] = "active" return progress @@ -128,7 +128,7 @@ def _normalize_safety_stage(value: Any) -> str: return text -def _normalize_safety_progress(value: Any, safety_stage: str) -> dict[str, str]: +def _normalize_safety_progress(value: Any, safety_stage: str) -> dict[str, Any]: """ 规范安全培训三级进度对象。 diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 1d13ed73..6a69d726 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -26,6 +26,7 @@ }, "devDependencies": { "@types/node": "^24.10.1", + "@types/pdfjs-dist": "^2.10.377", "@vitejs/plugin-vue": "^6.0.2", "@vue/test-utils": "^2.4.11", "@vue/tsconfig": "^0.8.1", @@ -1152,6 +1153,16 @@ "undici-types": "~7.18.0" } }, + "node_modules/@types/pdfjs-dist": { + "version": "2.10.377", + "resolved": "https://registry.npmjs.org/@types/pdfjs-dist/-/pdfjs-dist-2.10.377.tgz", + "integrity": "sha512-RNBWpazVTkC5aiUIIo6d7ojlL0hJSoeQP1QCvTsVLW6qkNEpTALiI0DNGCYAGDfhbL0r17c/zNPQ15lk948UXg==", + "dev": true, + "license": "MIT", + "dependencies": { + "pdfjs-dist": "*" + } + }, "node_modules/@vitejs/plugin-vue": { "version": "6.0.8", "resolved": "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-6.0.8.tgz", diff --git a/frontend/package.json b/frontend/package.json index f181838e..5d3b8c32 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -28,6 +28,7 @@ }, "devDependencies": { "@types/node": "^24.10.1", + "@types/pdfjs-dist": "^2.10.377", "@vitejs/plugin-vue": "^6.0.2", "@vue/test-utils": "^2.4.11", "@vue/tsconfig": "^0.8.1", diff --git a/frontend/src/features/chat/components/TrainingWorkspacePanel.vue b/frontend/src/features/chat/components/TrainingWorkspacePanel.vue index 902610be..d82a5d52 100644 --- a/frontend/src/features/chat/components/TrainingWorkspacePanel.vue +++ b/frontend/src/features/chat/components/TrainingWorkspacePanel.vue @@ -247,6 +247,36 @@ const isMaterialCompleted = (material: any) => { const currentPreviewVideoUrl = ref(''); +const videoCountdownSeconds = ref(0); +let videoCountdownTimer: ReturnType | 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 +285,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 +311,7 @@ const handlePreviewClose = (val: boolean) => { const handleVideoModalClose = () => { workspace.showVideoModal = false; currentPreviewVideoUrl.value = ''; + stopVideoCountdown(); workspace.stopMaterialTimer(); }; const jumpToExamQuestion = (index: number) => { @@ -858,10 +889,6 @@ const currentSafetyStageText = computed(() => { {{ $t('chat.training.safety.progressHint') }} -
-
{{ $t('chat.training.progressPercent') }}
-
{{ workspace.safetyProgressPercent }}%
-
@@ -1314,9 +1341,14 @@ const currentSafetyStageText = computed(() => {
- +
+
+ {{ videoCountdownSeconds }}s +
+ +
+
+ {{ countdownSeconds }}s +