feat(training): 培训模块改造!
This commit is contained in:
1 parent
57652ae581
commit
5f713f2c0c
11 files changed
+226
-51
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
exportTrainingRecords,
|
||||
getMyTrainingConfig,
|
||||
getMyTrainingProgress,
|
||||
getMyTrainingTypes,
|
||||
getTrainingStats,
|
||||
listTrainingRecords,
|
||||
saveMyTrainingProgress,
|
||||
@@ -32,6 +33,7 @@ import type {
|
||||
TrainingStage,
|
||||
TrainingStats,
|
||||
TrainingType,
|
||||
TrainingTypeOption,
|
||||
TrainingWorkspaceView,
|
||||
} from '@/features/chat/training/training.types';
|
||||
import {
|
||||
@@ -68,10 +70,7 @@ export interface UseTrainingWorkspaceOptions {
|
||||
}
|
||||
|
||||
const DEFAULT_PASS_SCORE = 90;
|
||||
const DEFAULT_TRAINING_VERSION: Record<TrainingType, string> = {
|
||||
onboarding: 'onboarding-v1',
|
||||
safety: 'safety-v1',
|
||||
};
|
||||
const DEFAULT_TRAINING_VERSION = 'v1.0';
|
||||
|
||||
const formatDate = (value: Date) => value.toISOString().slice(0, 10);
|
||||
|
||||
@@ -108,7 +107,11 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const defaultActiveView = computed<TrainingWorkspaceView>(() => (isAdminViewer.value ? 'admin' : 'learner'));
|
||||
const activeView = ref<TrainingWorkspaceView>('learner');
|
||||
const learnerTab = ref<TrainingType>('onboarding');
|
||||
const trainingVersion = ref<string>(DEFAULT_TRAINING_VERSION.onboarding);
|
||||
const trainingTypes = ref<TrainingTypeOption[]>([
|
||||
{ code: 'onboarding', name: t('chat.training.safety.tabs.onboarding') },
|
||||
{ code: 'safety', name: t('chat.training.safety.tabs.safety') },
|
||||
]);
|
||||
const trainingVersion = ref<string>(DEFAULT_TRAINING_VERSION);
|
||||
const examMode = ref<TrainingExamMode>('unified');
|
||||
const safetyStage = ref<SafetyStage>('company');
|
||||
const safetyViewStage = ref<SafetyStage>('company');
|
||||
@@ -369,6 +372,37 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const currentUserDepartment = computed(() => String(currentUser.value?.department || '').trim() || t('chat.training.unknownDepartment'));
|
||||
const filteredRecords = computed(() => records.value);
|
||||
|
||||
/**
|
||||
* 解析培训类型的展示名称,优先使用后端已发布配置名称,并兼容历史内置类型。
|
||||
* AI 触发时机:Tabs、HR 筛选、记录和报告展示培训类型时调用,禁止直接将类型 code 暴露给用户。
|
||||
*/
|
||||
const resolveTrainingTypeName = (code?: string | null) => {
|
||||
const normalizedCode = String(code || '').trim();
|
||||
return trainingTypes.value.find((item) => item.code === normalizedCode)?.name
|
||||
|| (normalizedCode === 'onboarding' ? t('chat.training.hr.filters.typeOnboarding') : '')
|
||||
|| (normalizedCode === 'safety' ? t('chat.training.hr.filters.typeSafety') : '')
|
||||
|| normalizedCode
|
||||
|| '--';
|
||||
};
|
||||
|
||||
/**
|
||||
* 读取员工可见的已发布培训类型,作为动态 Tabs 与 HR 类型筛选的统一数据源。
|
||||
* AI 触发时机:进入培训 Agent 或登录状态变更后调用;无已发布配置时保留内置类型以兼容历史数据。
|
||||
*/
|
||||
const loadTrainingTypes = async () => {
|
||||
if (!isTrainingAgent.value || !hasAuthenticatedUser.value) return;
|
||||
try {
|
||||
const items = await getMyTrainingTypes();
|
||||
if (!items.length) return;
|
||||
trainingTypes.value = items;
|
||||
if (!items.some((item) => item.code === learnerTab.value)) {
|
||||
learnerTab.value = items[0]?.code || learnerTab.value;
|
||||
}
|
||||
} catch {
|
||||
// 无法读取目录时保留内置兼容项,后续仍可按 code 请求配置。
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置考试状态,为首次开考或再次补考共用。
|
||||
* AI 触发时机:当前端需要严格模拟“未通过必须重考”的培训流程时使用,确保上一轮答题状态不会污染下一轮。
|
||||
@@ -543,7 +577,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
*/
|
||||
const applyProgressRecord = (record: TrainingProgressRecord | null) => {
|
||||
if (!record) {
|
||||
trainingVersion.value = DEFAULT_TRAINING_VERSION[learnerTab.value];
|
||||
trainingVersion.value = DEFAULT_TRAINING_VERSION;
|
||||
examMode.value = 'unified';
|
||||
resetSafetyProgress('company');
|
||||
stage.value = 'video';
|
||||
@@ -552,7 +586,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
latestSettledResult.value = null;
|
||||
return;
|
||||
}
|
||||
trainingVersion.value = record.trainingVersion || DEFAULT_TRAINING_VERSION[learnerTab.value];
|
||||
trainingVersion.value = record.trainingVersion || publishedConfig.value?.version || DEFAULT_TRAINING_VERSION;
|
||||
examMode.value = record.examMode || 'unified';
|
||||
if (learnerTab.value === 'safety') {
|
||||
safetyStage.value = record.safetyStage || 'company';
|
||||
@@ -769,6 +803,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
return;
|
||||
}
|
||||
isHydrated.value = false;
|
||||
void loadTrainingTypes();
|
||||
void loadTrainingConfig();
|
||||
void loadTrainingProgress();
|
||||
},
|
||||
@@ -974,7 +1009,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const parts = [
|
||||
t('chat.training.chatPrompts.hrSummaryPrefix'),
|
||||
`${t('chat.training.hr.filters.keywordLabel')}: ${hrKeyword.value || t('chat.training.hr.filters.noLimit')}`,
|
||||
`${t('chat.training.hr.filters.typeLabel')}: ${hrTypeFilter.value === 'all' ? t('chat.training.hr.filters.allTypes') : hrTypeFilter.value === 'safety' ? t('chat.training.hr.filters.typeSafety') : t('chat.training.hr.filters.typeOnboarding')}`,
|
||||
`${t('chat.training.hr.filters.typeLabel')}: ${hrTypeFilter.value === 'all' ? t('chat.training.hr.filters.allTypes') : resolveTrainingTypeName(hrTypeFilter.value)}`,
|
||||
`${t('chat.training.hr.filters.statusLabel')}: ${hrStatusFilter.value === 'all' ? t('chat.training.hr.filters.allStatuses') : t(`chat.training.hr.status.${hrStatusFilter.value}`)}`,
|
||||
`${t('chat.training.hr.filters.departmentLabel')}: ${hrDepartmentFilter.value === 'all' ? t('chat.training.hr.filters.allDepartments') : hrDepartmentFilter.value}`,
|
||||
`${t('chat.training.hr.stats.passRate')}: ${stats.value.passRate}%`,
|
||||
@@ -1126,6 +1161,8 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
publishedSafetySummary,
|
||||
activeView,
|
||||
learnerTab,
|
||||
trainingTypes,
|
||||
resolveTrainingTypeName,
|
||||
trainingVersion,
|
||||
examMode,
|
||||
safetyStage,
|
||||
|
||||
Reference in new issue
Block a user