feat(training): 新增精益培训视频与周任务管理
This commit is contained in:
1 parent
e5ede471fd
commit
a69814c409
32 files changed
+1619
-55
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user