fix(training): 修复安全培训状态问题!
This commit is contained in:
1 parent
11cef575b4
commit
375e4e371d
6 files changed
+192
-73
No files matched your search
@@ -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]:
|
||||
"""
|
||||
规范安全培训三级进度对象。
|
||||
|
||||
|
||||
Generated
+11
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -247,6 +247,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 +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') }}
|
||||
</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">
|
||||
@@ -1314,9 +1341,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,6 +1378,7 @@ const currentSafetyStageText = computed(() => {
|
||||
:file="previewFile"
|
||||
:agent-id="workspace.currentTrainingAgentId || undefined"
|
||||
:auth-headers="getAuthHeaders()"
|
||||
:required-duration="workspace.currentViewingMaterialRequiredDuration"
|
||||
@update:modelValue="handlePreviewClose"
|
||||
/>
|
||||
</Teleport>
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -41,6 +41,7 @@ const props = defineProps<{
|
||||
currentIndex?: number;
|
||||
agentId?: number | null;
|
||||
authHeaders?: Record<string, string>;
|
||||
requiredDuration?: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -49,6 +50,35 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const countdownSeconds = ref(0);
|
||||
let countdownTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const startCountdown = () => {
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer);
|
||||
countdownTimer = null;
|
||||
}
|
||||
if (props.requiredDuration && props.requiredDuration > 0) {
|
||||
countdownSeconds.value = props.requiredDuration * 60;
|
||||
countdownTimer = setInterval(() => {
|
||||
if (countdownSeconds.value > 0) {
|
||||
countdownSeconds.value--;
|
||||
} else {
|
||||
if (countdownTimer) clearInterval(countdownTimer);
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
countdownSeconds.value = 0;
|
||||
}
|
||||
};
|
||||
|
||||
const stopCountdown = () => {
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer);
|
||||
countdownTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
const isLoading = ref(false);
|
||||
const error = ref('');
|
||||
const markdownHtml = ref('');
|
||||
@@ -647,6 +677,9 @@ const loadContent = async () => {
|
||||
watch(
|
||||
() => [props.modelValue, activeFile.value?.url, activeFile.value?.name, activeIndex.value, activeFiles.value.length],
|
||||
() => {
|
||||
if (props.modelValue) {
|
||||
startCountdown();
|
||||
}
|
||||
loadContent();
|
||||
},
|
||||
{ immediate: true }
|
||||
@@ -657,6 +690,7 @@ watch(
|
||||
(v) => {
|
||||
if (!v) {
|
||||
clearOfficeObjectUrl();
|
||||
stopCountdown();
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -674,6 +708,9 @@ watch(
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-2">
|
||||
<div v-if="countdownSeconds > 0" class="flex items-center justify-center h-8 w-8 rounded-full border border-red-200 bg-red-50 text-red-500 font-semibold text-xs shadow-sm">
|
||||
{{ countdownSeconds }}s
|
||||
</div>
|
||||
<div v-if="isExcelPreviewFile" class="flex items-center gap-2 rounded-full border border-default bg-surface px-2 py-1">
|
||||
<button
|
||||
type="button"
|
||||
|
||||
Reference in new issue
Block a user