fix(training): 修复出国培训规则培训bug
This commit is contained in:
1 parent
683f602475
commit
258098ea7b
13 files changed
+280
-26
No files matched your search
@@ -311,6 +311,25 @@ export async function getLeanTrainingDashboard(taskId?: number): Promise<LeanTra
|
||||
};
|
||||
}
|
||||
|
||||
export async function exportLeanTrainingDashboard(taskId: number): Promise<void> {
|
||||
const response = await fetch(`/api/admin/lean-training/dashboard/export?task_id=${taskId}`, {
|
||||
method: 'GET',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Export failed: HTTP ${response.status}`);
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `lean_training_dashboard_${new Date().toISOString().slice(0, 10)}.xlsx`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
/** HR 对指定成员发起精益培训定向提醒;返回后端实发统计(sent/failed 才是真实送达情况,created 含发送失败)。 */
|
||||
export async function sendLeanTrainingReminders(weeklyTaskId: number, userIds: number[]): Promise<{ created: number; sent: number; skipped: number; failed: number }> {
|
||||
return requestJson<{ created: number; sent: number; skipped: number; failed: number }>(`/api/admin/lean-training/weekly-tasks/${weeklyTaskId}/reminders`, {
|
||||
|
||||
@@ -500,6 +500,17 @@ const stopNonSafetyVideoTimer = () => {
|
||||
workspace.stopMaterialTimer();
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理普通培训主视频播放结束事件。
|
||||
* AI 触发时机:学员完整播放当前主视频到结尾时调用;仅出国规章培训将视频播放结束作为一次学习完成,其他培训类型保持现有阶段推进入口。
|
||||
*/
|
||||
const handleNonSafetyVideoEnded = () => {
|
||||
stopNonSafetyVideoTimer();
|
||||
if (workspace.isOverseasRegulationsTraining) {
|
||||
workspace.markVideoCompleted();
|
||||
}
|
||||
};
|
||||
|
||||
watch([() => workspace.learnerTab, nonSafetyVideoMaterials], () => {
|
||||
if (!nonSafetyVideoMaterials.value.some((material) => material.id === activeNonSafetyVideoId.value)) {
|
||||
activeNonSafetyVideoId.value = nonSafetyVideoMaterials.value[0]?.id ?? null;
|
||||
@@ -589,8 +600,8 @@ const leanStatusMeta: Record<LeanTrainingTaskStatus, { badgeClass: string; label
|
||||
/** 看板总结弹框上下文:员工姓名 + 完整总结文案;为 null 时弹框关闭。 */
|
||||
const summaryModal = ref<{ name: string; text: string } | null>(null);
|
||||
|
||||
/** 总结列预览截断:最多显示 15 个字,超出部分以省略号收尾,点击可弹框查看全文。 */
|
||||
const truncateSummary = (text: string) => (text.length > 15 ? `${text.slice(0, 15)}…` : text);
|
||||
/** 总结列预览截断:最多显示 4 个字,超出部分以省略号收尾,点击可弹框查看全文。 */
|
||||
const truncateSummary = (text: string) => (text.length > 4 ? `${text.slice(0, 4)}…` : text);
|
||||
|
||||
/** 打开总结详情弹框:仅当该行有总结文案时可点击(无总结的行显示 "--" 不可点)。 */
|
||||
const openSummaryModal = (name: string, text: string) => {
|
||||
@@ -992,7 +1003,7 @@ const currentSafetyStageText = computed(() => {
|
||||
:src="activeNonSafetyVideo.resource?.fileUrl"
|
||||
@play="startNonSafetyVideoTimer"
|
||||
@pause="stopNonSafetyVideoTimer"
|
||||
@ended="stopNonSafetyVideoTimer"
|
||||
@ended="handleNonSafetyVideoEnded"
|
||||
/>
|
||||
</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">
|
||||
@@ -1831,6 +1842,10 @@ const currentSafetyStageText = computed(() => {
|
||||
>
|
||||
<option v-for="period in workspace.leanDashboard.periods" :key="period.id" :value="period.id">{{ $t('chat.training.lean.dashboard.periodLabel', { index: period.index }) }}({{ period.weekKey }})</option>
|
||||
</select>
|
||||
<button type="button" class="inline-flex items-center gap-1.5 rounded-lg bg-emerald-600 px-2.5 py-1.5 text-xs font-medium text-white transition hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60" :disabled="workspace.leanExportLoading" @click="workspace.exportLeanDashboard">
|
||||
<Download class="h-3.5 w-3.5" />
|
||||
{{ workspace.leanExportLoading ? $t('chat.training.lean.dashboard.exporting') : $t('chat.training.lean.dashboard.export') }}
|
||||
</button>
|
||||
</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>
|
||||
@@ -1862,7 +1877,7 @@ const currentSafetyStageText = computed(() => {
|
||||
<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, 16).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' : row.status === 'overdue' ? 'bg-red-50 text-red-700' : 'bg-blue-50 text-blue-700'">{{ $t(`chat.training.lean.status.${row.status}`) }}</span></td>
|
||||
<!-- [RULE] 总结列最多显示 15 个字:超出截断并显示省略号,点击弹框查看全部文案;无总结显示 "--"。
|
||||
<!-- [RULE] 总结列最多显示 4 个字:超出截断并显示省略号,点击弹框查看全部文案;无总结显示 "--"。
|
||||
常显虚线下划线提示可点击(用户复测反馈点击无效,实为部署版本差异,此处强化可点性视觉)。 -->
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">
|
||||
<button v-if="row.summaryText" type="button" class="max-w-56 cursor-pointer text-left whitespace-pre-wrap break-words underline decoration-dotted decoration-secondary/60 underline-offset-2 transition hover:decoration-solid hover:text-primary" :title="$t('chat.training.lean.summaryModal.viewHint')" @click="openSummaryModal(row.name, row.summaryText)">{{ truncateSummary(row.summaryText) }}</button>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
exportTrainingRecords,
|
||||
exportLeanTrainingDashboard,
|
||||
getMyTrainingConfig,
|
||||
getMyTrainingProgress,
|
||||
getMyTrainingTypes,
|
||||
@@ -82,6 +83,11 @@ export interface UseTrainingWorkspaceOptions {
|
||||
|
||||
const DEFAULT_PASS_SCORE = 90;
|
||||
const DEFAULT_TRAINING_VERSION = 'v1.0';
|
||||
const OVERSEAS_REGULATIONS_TRAINING_TYPES = new Set([
|
||||
'overseas_regulations',
|
||||
'overseas_regulations_training',
|
||||
'overseas_training',
|
||||
]);
|
||||
|
||||
const formatDate = (value: Date) => value.toISOString().slice(0, 10);
|
||||
|
||||
@@ -125,6 +131,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
/** 管理端精益看板当前选中的期次任务 ID;为空表示最新一期,切换后重新拉取对应期看板。 */
|
||||
const leanDashboardTaskId = ref<number | null>(null);
|
||||
const leanReminderLoading = ref<Record<number, boolean>>({});
|
||||
const leanExportLoading = ref(false);
|
||||
/** 按任务 ID 分组的感悟草稿,支持时间树上多期任务并行编辑。 */
|
||||
const leanSummaryByTask = ref<Record<number, string>>({});
|
||||
/** 按任务 ID 分组的观看记录(资源 ID -> 观看时间),提交时随感悟一并交由服务端校验。 */
|
||||
@@ -136,6 +143,10 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
{ code: 'onboarding', name: t('chat.training.safety.tabs.onboarding') },
|
||||
{ code: 'safety', name: t('chat.training.safety.tabs.safety') },
|
||||
]);
|
||||
const isOverseasRegulationsTraining = computed(() => (
|
||||
OVERSEAS_REGULATIONS_TRAINING_TYPES.has(learnerTab.value)
|
||||
|| trainingTypes.value.some((item) => item.code === learnerTab.value && item.name.includes('出国规章'))
|
||||
));
|
||||
const trainingVersion = ref<string>(DEFAULT_TRAINING_VERSION);
|
||||
const examMode = ref<TrainingExamMode>('unified');
|
||||
const safetyStage = ref<SafetyStage>('company');
|
||||
@@ -147,6 +158,11 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
});
|
||||
|
||||
const stage = ref<TrainingStage>('video');
|
||||
watch(isOverseasRegulationsTraining, (isOverseas) => {
|
||||
if (isOverseas) {
|
||||
stage.value = 'video';
|
||||
}
|
||||
});
|
||||
const currentQuestionIndex = ref(0);
|
||||
const score = ref(0);
|
||||
const attemptCount = ref(0);
|
||||
@@ -665,7 +681,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
safetyViewStage.value = record.safetyStage || 'company';
|
||||
}
|
||||
}
|
||||
stage.value = record.stage;
|
||||
stage.value = isOverseasRegulationsTraining.value ? 'video' : record.stage;
|
||||
syncExamQuestionIndex(record.currentQuestionIndex);
|
||||
score.value = Number(record.score || 0);
|
||||
attemptCount.value = Number(record.attempts || 0);
|
||||
@@ -706,7 +722,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
safetyProgress: learnerTab.value === 'safety' ? safetyProgress.value : null,
|
||||
currentQuestionIndex: currentQuestionIndex.value,
|
||||
score: score.value,
|
||||
passed: isPassed.value,
|
||||
passed: isOverseasRegulationsTraining.value && stage.value === 'result' ? true : isPassed.value,
|
||||
attemptCount: attemptCount.value,
|
||||
answerDetails: answerRecords.value,
|
||||
joinDate: currentJoinDate.value || formatDate(new Date()),
|
||||
@@ -749,11 +765,14 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
isHydrated.value = true;
|
||||
return;
|
||||
}
|
||||
const requestedTrainingType = learnerTab.value;
|
||||
try {
|
||||
const record = await getMyTrainingProgress(learnerTab.value);
|
||||
const record = await getMyTrainingProgress(requestedTrainingType);
|
||||
if (learnerTab.value !== requestedTrainingType) return;
|
||||
hasWarnedLoadFailure.value = false;
|
||||
applyProgressRecord(record);
|
||||
} catch (error) {
|
||||
if (learnerTab.value !== requestedTrainingType) return;
|
||||
// 退出登录或登录态失效时,培训页可能尚未卸载;这里静默清空状态,避免把正常 401 提示成“读取失败”。
|
||||
if (error instanceof BusinessError && error.status === 401) {
|
||||
hasWarnedLoadFailure.value = false;
|
||||
@@ -782,15 +801,21 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
trainingConfigLoading.value = false;
|
||||
return;
|
||||
}
|
||||
const requestedTrainingType = learnerTab.value;
|
||||
trainingConfigLoading.value = true;
|
||||
try {
|
||||
publishedConfig.value = await getMyTrainingConfig(learnerTab.value);
|
||||
const config = await getMyTrainingConfig(requestedTrainingType);
|
||||
if (learnerTab.value === requestedTrainingType) {
|
||||
publishedConfig.value = config;
|
||||
}
|
||||
} catch (error) {
|
||||
if (!(error instanceof BusinessError && error.status === 401)) {
|
||||
if (learnerTab.value === requestedTrainingType && !(error instanceof BusinessError && error.status === 401)) {
|
||||
publishedConfig.value = null;
|
||||
}
|
||||
} finally {
|
||||
trainingConfigLoading.value = false;
|
||||
if (learnerTab.value === requestedTrainingType) {
|
||||
trainingConfigLoading.value = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -841,6 +866,20 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
await loadLeanDashboard();
|
||||
};
|
||||
|
||||
const exportLeanDashboard = async () => {
|
||||
const taskId = leanDashboardTaskId.value ?? leanDashboard.value.task?.id;
|
||||
if (!taskId || leanExportLoading.value) return;
|
||||
leanExportLoading.value = true;
|
||||
try {
|
||||
await exportLeanTrainingDashboard(taskId);
|
||||
msg.success(t('chat.training.lean.dashboard.exportSuccess'));
|
||||
} catch {
|
||||
msg.error(t('chat.training.lean.dashboard.exportFailed'));
|
||||
} finally {
|
||||
leanExportLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 读取学员端全部已发布精益周任务(含状态与播放地址),并以服务端完成记录回填各任务的感悟/观看草稿。 */
|
||||
const loadLeanTraining = async () => {
|
||||
if (!isTrainingAgent.value || !hasAuthenticatedUser.value) return;
|
||||
@@ -966,11 +1005,25 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
);
|
||||
|
||||
const markVideoCompleted = () => {
|
||||
if (!hasPublishedTrainingConfig.value || !videoUrl.value) return;
|
||||
if (!hasPublishedTrainingConfig.value) return;
|
||||
if (!isOverseasRegulationsTraining.value && !videoUrl.value) return;
|
||||
if (learnerTab.value === 'safety') {
|
||||
checkAndAdvanceStage();
|
||||
return;
|
||||
}
|
||||
if (isOverseasRegulationsTraining.value) {
|
||||
stage.value = 'result';
|
||||
score.value = 100;
|
||||
completionDate.value = formatDate(new Date());
|
||||
latestSettledResult.value = {
|
||||
score: 100,
|
||||
correctCount: 0,
|
||||
wrongCount: 0,
|
||||
isPassed: true,
|
||||
};
|
||||
void persistProgress();
|
||||
return;
|
||||
}
|
||||
stage.value = 'summary';
|
||||
void persistProgress();
|
||||
};
|
||||
@@ -1252,6 +1305,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
}
|
||||
void persistProgress();
|
||||
} else {
|
||||
if (isOverseasRegulationsTraining.value) return;
|
||||
const activeStageMaterials = publishedTrainingMaterials.value;
|
||||
if (!activeStageMaterials.length) return;
|
||||
const allCompleted = activeStageMaterials.every(m => {
|
||||
@@ -1357,6 +1411,8 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
leanStats,
|
||||
leanRows,
|
||||
leanDashboardTaskId,
|
||||
leanExportLoading,
|
||||
exportLeanDashboard,
|
||||
selectLeanDashboardPeriod,
|
||||
learnerChatPrompt,
|
||||
newSessionReminderMessage,
|
||||
@@ -1364,6 +1420,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
learnerAssistantMessage,
|
||||
managementChatPrompt,
|
||||
markVideoCompleted,
|
||||
isOverseasRegulationsTraining,
|
||||
startExam,
|
||||
selectAnswer,
|
||||
submitTextAnswer,
|
||||
|
||||
@@ -1060,7 +1060,11 @@
|
||||
"count": "{count} people",
|
||||
"empty": "No personnel data",
|
||||
"passRate": "Completion Rate",
|
||||
"periodLabel": "Period {index}"
|
||||
"periodLabel": "Session {index}",
|
||||
"export": "Export Excel",
|
||||
"exporting": "Exporting...",
|
||||
"exportSuccess": "Excel exported successfully",
|
||||
"exportFailed": "Excel export failed. Please try again later."
|
||||
},
|
||||
"columns": {
|
||||
"employeeId": "Employee ID",
|
||||
|
||||
@@ -1060,7 +1060,11 @@
|
||||
"count": "{count} คน",
|
||||
"empty": "ไม่มีข้อมูลบุคลากร",
|
||||
"passRate": "อัตราความสำเร็จ",
|
||||
"periodLabel": "รอบที่ {index}"
|
||||
"periodLabel": "รอบที่ {index}",
|
||||
"export": "ส่งออก Excel",
|
||||
"exporting": "กำลังส่งออก...",
|
||||
"exportSuccess": "ส่งออก Excel สำเร็จ",
|
||||
"exportFailed": "ส่งออก Excel ไม่สำเร็จ โปรดลองอีกครั้งภายหลัง"
|
||||
},
|
||||
"columns": {
|
||||
"employeeId": "รหัสพนักงาน",
|
||||
|
||||
@@ -1094,7 +1094,11 @@
|
||||
"count": "共 {count} 人",
|
||||
"empty": "暂无人员数据",
|
||||
"passRate": "完成率",
|
||||
"periodLabel": "第 {index} 期"
|
||||
"periodLabel": "第 {index} 期",
|
||||
"export": "导出 Excel",
|
||||
"exporting": "正在导出...",
|
||||
"exportSuccess": "Excel 导出成功",
|
||||
"exportFailed": "Excel 导出失败,请稍后重试"
|
||||
},
|
||||
"columns": {
|
||||
"employeeId": "工号",
|
||||
|
||||
@@ -1060,7 +1060,11 @@
|
||||
"count": "共 {count} 人",
|
||||
"empty": "暫無人員資料",
|
||||
"passRate": "完成率",
|
||||
"periodLabel": "第 {index} 期"
|
||||
"periodLabel": "第 {index} 期",
|
||||
"export": "匯出 Excel",
|
||||
"exporting": "正在匯出...",
|
||||
"exportSuccess": "Excel 匯出成功",
|
||||
"exportFailed": "Excel 匯出失敗,請稍後再試"
|
||||
},
|
||||
"columns": {
|
||||
"employeeId": "工號",
|
||||
|
||||
Reference in new issue
Block a user