feat(training): 新增精益培训视频与周任务管理
This commit is contained in:
1 parent
e5ede471fd
commit
a69814c409
32 files changed
+1619
-55
No files matched your search
@@ -18,7 +18,14 @@ import type {
|
||||
UsageReport,
|
||||
UsageRangeKey,
|
||||
} from '../types/report.types';
|
||||
import type { TrainingConfig, TrainingConfigPayload, TrainingResourceCandidates } from '../types/training-config.types';
|
||||
import type {
|
||||
LeanTrainingWeeklyTask,
|
||||
LeanTrainingWeeklyTaskPayload,
|
||||
LeanTrainingDashboard,
|
||||
TrainingConfig,
|
||||
TrainingConfigPayload,
|
||||
TrainingResourceCandidates,
|
||||
} from '../types/training-config.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
||||
@@ -454,6 +461,16 @@ export const deleteAdminTrainingConfig = (id: number) =>
|
||||
...auth(),
|
||||
});
|
||||
|
||||
export const createOrUpdateAdminLeanTrainingWeeklyTask = (payload: LeanTrainingWeeklyTaskPayload) =>
|
||||
requestJson<LeanTrainingWeeklyTask>('/api/admin/lean-training/weekly-tasks', {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const getAdminLeanTrainingDashboard = () =>
|
||||
requestJson<LeanTrainingDashboard>('/api/admin/lean-training/dashboard', auth());
|
||||
|
||||
// Users
|
||||
export const listAdminUsers = () => requestJson<AdminUserRow[]>('/api/admin/users', auth());
|
||||
|
||||
|
||||
@@ -29,14 +29,21 @@ import { useMessage } from '@/shared/composables/useMessage';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import {
|
||||
createAdminTrainingConfig,
|
||||
createAdminAgentGuide,
|
||||
createOrUpdateAdminLeanTrainingWeeklyTask,
|
||||
deleteAdminTrainingConfig,
|
||||
getAdminLeanTrainingDashboard,
|
||||
listAdminTrainingConfigs,
|
||||
listAdminAgents,
|
||||
listAdminTrainingResourceCandidates,
|
||||
listAdminUsers,
|
||||
parseAdminTrainingQuestionBank,
|
||||
updateAdminTrainingConfig,
|
||||
uploadAdminAgentGuideFile,
|
||||
} from '../../api/admin.api';
|
||||
import type {
|
||||
GenericTrainingStage,
|
||||
LeanTrainingWeeklyTask,
|
||||
SafetyTrainingStage,
|
||||
TrainingConfig,
|
||||
TrainingConfigPayload,
|
||||
@@ -44,6 +51,7 @@ import type {
|
||||
TrainingLevel,
|
||||
TrainingProgressItem,
|
||||
} from '../../types/training-config.types';
|
||||
import type { AdminUserRow } from '../../types/admin.types';
|
||||
import TrainingTypeFormModal from './components/TrainingTypeFormModal.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -61,9 +69,29 @@ const questionSourceVersionId = ref<number | null>(null);
|
||||
const isParsingQuestions = ref(false);
|
||||
const questionParseMeta = ref<{ mode: string; fileName: string; skipped: number[] } | null>(null);
|
||||
const candidates = ref({ guides: [], documents: [], training_exam_documents: [] } as Awaited<ReturnType<typeof listAdminTrainingResourceCandidates>>);
|
||||
const leanTask = ref<LeanTrainingWeeklyTask | null>(null);
|
||||
const leanWeekKey = ref('');
|
||||
const leanDueAt = ref('');
|
||||
const leanVideoResourceIds = ref<number[]>([]);
|
||||
const leanTargetRoles = ref<string[]>([]);
|
||||
const leanTargetUserIds = ref<number[]>([]);
|
||||
const leanTargetUsers = ref<AdminUserRow[]>([]);
|
||||
const isSavingLeanTask = ref(false);
|
||||
const isUploadingVideo = ref(false);
|
||||
const videoInput = ref<HTMLInputElement | null>(null);
|
||||
|
||||
const selected = computed(() => configs.value.find((item) => item.id === selectedId.value) || null);
|
||||
const form = ref<TrainingConfigPayload>(emptyForm());
|
||||
const isSafetyConfig = computed(() => form.value.training_type === 'safety');
|
||||
const supportsDirectVideoUpload = computed(() => (
|
||||
['lean_management', 'overseas_regulations', 'overseas_regulations_training', 'overseas_training'].includes(form.value.training_type)
|
||||
|| form.value.name.includes('出国规章')
|
||||
));
|
||||
const videoGuideCandidates = computed(() => candidates.value.guides.filter((guide) => guide.file_type.toLowerCase() === 'video'));
|
||||
const directVideoResources = computed(() => contentResources.value.filter((resource) => (
|
||||
resource.resource_type === 'agent_guide'
|
||||
&& videoGuideCandidates.value.some((guide) => guide.id === resource.agent_guide_id)
|
||||
)));
|
||||
const contentResources = computed(() => form.value.resources.filter((resource) => resource.resource_type !== 'inline_questions'));
|
||||
const trainingLevels: TrainingLevel[] = ['company', 'department', 'team'];
|
||||
const guideGroups = computed(() => {
|
||||
@@ -97,7 +125,8 @@ const sectionItems = computed(() => [
|
||||
{ id: 'resources', label: t('admin.trainingConfig.sections.resourcesTitle'), icon: Library },
|
||||
{ id: 'exam', label: t('admin.trainingConfig.sections.examTitle'), icon: FileQuestion },
|
||||
{ id: 'review', label: t('admin.trainingConfig.sections.reviewTitle'), icon: ClipboardCheck },
|
||||
]);
|
||||
{ id: 'lean', label: t('admin.trainingConfig.sections.leanTitle'), icon: Video },
|
||||
].filter((item) => item.id !== 'lean' || form.value.training_type === 'lean_management'));
|
||||
const publishedCount = computed(() => configs.value.filter((config) => config.status === 'published').length);
|
||||
const resourceCount = computed(() => contentResources.value.length);
|
||||
const configuredLevelCount = computed(() => trainingLevels.filter((level) => resourcesByLevel(level).length > 0).length);
|
||||
@@ -120,6 +149,75 @@ const progressItems = computed(() => {
|
||||
const settings = form.value.settings as TrainingConfigSettings;
|
||||
return Array.isArray(settings.progress_items) ? settings.progress_items : [];
|
||||
});
|
||||
const leanVideoResources = computed(() => form.value.resources.filter((resource) => {
|
||||
if (resource.resource_type !== 'agent_guide' || !resource.id || !resource.agent_guide_id) return false;
|
||||
const guide = candidates.value.guides.find((item) => item.id === resource.agent_guide_id);
|
||||
return Boolean(guide?.file_type?.toLowerCase().startsWith('video'));
|
||||
}));
|
||||
const leanTaskVideoNames = computed(() => new Map(leanVideoResources.value.map((resource) => [
|
||||
resource.id as number,
|
||||
resource.title || candidates.value.guides.find((guide) => guide.id === resource.agent_guide_id)?.file_name || t('admin.trainingConfig.lean.unnamedVideo'),
|
||||
])));
|
||||
const leanRoleOptions = computed(() => [...new Set(leanTargetUsers.value.map((user) => user.role).filter(Boolean))].sort());
|
||||
|
||||
function mondayOfCurrentWeek(): string {
|
||||
const today = new Date();
|
||||
const monday = new Date(today);
|
||||
monday.setDate(today.getDate() - ((today.getDay() + 6) % 7));
|
||||
return monday.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function defaultLeanDueAt(weekKey: string): string {
|
||||
const due = new Date(`${weekKey}T23:59:00`);
|
||||
due.setDate(due.getDate() + 6);
|
||||
const local = new Date(due.getTime() - due.getTimezoneOffset() * 60000);
|
||||
return local.toISOString().slice(0, 16);
|
||||
}
|
||||
|
||||
const loadLeanTask = async () => {
|
||||
if (form.value.training_type !== 'lean_management') return;
|
||||
try {
|
||||
const dashboard = await getAdminLeanTrainingDashboard();
|
||||
leanTask.value = dashboard.task;
|
||||
} catch {
|
||||
leanTask.value = null;
|
||||
}
|
||||
leanWeekKey.value = leanTask.value?.week_key || mondayOfCurrentWeek();
|
||||
leanDueAt.value = leanTask.value?.due_at ? leanTask.value.due_at.slice(0, 16) : defaultLeanDueAt(leanWeekKey.value);
|
||||
leanVideoResourceIds.value = leanTask.value?.video_resource_ids ? [...leanTask.value.video_resource_ids] : [];
|
||||
leanTargetRoles.value = leanTask.value?.target_roles ? [...leanTask.value.target_roles] : [];
|
||||
leanTargetUserIds.value = leanTask.value?.target_user_ids ? [...leanTask.value.target_user_ids] : [];
|
||||
leanTargetUsers.value = await listAdminUsers();
|
||||
};
|
||||
|
||||
const toggleLeanVideo = (resourceId: number) => {
|
||||
if (leanTask.value?.week_key === leanWeekKey.value) return;
|
||||
leanVideoResourceIds.value = leanVideoResourceIds.value.includes(resourceId)
|
||||
? leanVideoResourceIds.value.filter((id) => id !== resourceId)
|
||||
: [...leanVideoResourceIds.value, resourceId];
|
||||
};
|
||||
|
||||
const saveLeanTask = async () => {
|
||||
if (leanVideoResourceIds.value.length !== 2) {
|
||||
msg.warning(t('admin.trainingConfig.messages.leanVideoCount'));
|
||||
return;
|
||||
}
|
||||
isSavingLeanTask.value = true;
|
||||
try {
|
||||
leanTask.value = await createOrUpdateAdminLeanTrainingWeeklyTask({
|
||||
week_key: leanWeekKey.value,
|
||||
due_at: new Date(leanDueAt.value).toISOString(),
|
||||
video_resource_ids: leanVideoResourceIds.value,
|
||||
target_roles: leanTargetRoles.value,
|
||||
target_user_ids: leanTargetUserIds.value,
|
||||
});
|
||||
msg.success(t('admin.trainingConfig.messages.leanTaskSaved'));
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.saveFailed'));
|
||||
} finally {
|
||||
isSavingLeanTask.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 创建新增培训类型所需的完整默认配置,确保沿用后端既有字段契约。 */
|
||||
function emptyForm(): TrainingConfigPayload {
|
||||
@@ -181,6 +279,7 @@ const selectConfig = (config: TrainingConfig) => {
|
||||
questionJsonText.value = JSON.stringify(questions, null, 2);
|
||||
questionSourceVersionId.value = null;
|
||||
questionParseMeta.value = null;
|
||||
void loadLeanTask();
|
||||
};
|
||||
|
||||
/** 从已选择的员工培训知识库当前 PDF 解析题库,并将结果回填到可继续手工编辑的 JSON。 */
|
||||
@@ -428,6 +527,54 @@ const updateResourceType = (resource: TrainingConfigPayload['resources'][number]
|
||||
resource.kb_document_version_id = undefined;
|
||||
};
|
||||
|
||||
const openVideoUpload = () => videoInput.value?.click();
|
||||
|
||||
const uploadTrainingVideo = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!file) return;
|
||||
if (!file.type.startsWith('video/')) {
|
||||
msg.warning(t('admin.trainingConfig.messages.videoFileRequired'));
|
||||
return;
|
||||
}
|
||||
isUploadingVideo.value = true;
|
||||
try {
|
||||
const trainingAgent = (await listAdminAgents()).find((agent) => (
|
||||
agent.handler_config?.content_profile === 'training'
|
||||
|| agent.extra_config?.training_workspace_enabled === true
|
||||
|| agent.extra_config?.training_mode === true
|
||||
|| agent.extra_config?.training_agent === true
|
||||
));
|
||||
if (!trainingAgent) throw new Error(t('admin.trainingConfig.messages.trainingAgentRequired'));
|
||||
const uploaded = await uploadAdminAgentGuideFile(file);
|
||||
const created = await createAdminAgentGuide({
|
||||
agent_id: trainingAgent.id,
|
||||
file_name: uploaded.file_name,
|
||||
file_path: uploaded.file_path,
|
||||
file_type: uploaded.file_type,
|
||||
file_size: uploaded.file_size,
|
||||
guide_usage: 'training_video',
|
||||
sort_order: candidates.value.guides.length,
|
||||
status: 1,
|
||||
}) as { id: number };
|
||||
candidates.value = await listAdminTrainingResourceCandidates();
|
||||
form.value.resources.push({
|
||||
resource_type: 'agent_guide',
|
||||
agent_guide_id: created.id,
|
||||
training_level: 'company',
|
||||
title: uploaded.file_name,
|
||||
required_duration: 0,
|
||||
sort_order: form.value.resources.length,
|
||||
});
|
||||
msg.success(t('admin.trainingConfig.messages.videoUploaded'));
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.videoUploadFailed'));
|
||||
} finally {
|
||||
isUploadingVideo.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const scrollToSection = (sectionId: string) => {
|
||||
activeSection.value = sectionId;
|
||||
document.getElementById(`training-section-${sectionId}`)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
@@ -614,7 +761,26 @@ onMounted(() => void load());
|
||||
<p class="mt-1 text-xs text-muted">{{ t('admin.trainingConfig.resourcesEmptyHint') }}</p>
|
||||
</div>
|
||||
<div class="flex flex-col gap-5">
|
||||
<article v-if="supportsDirectVideoUpload" class="w-full overflow-hidden rounded-2xl border border-violet-200 bg-surface shadow-sm">
|
||||
<div class="flex flex-col gap-3 border-b border-violet-200 bg-violet-50/80 px-5 py-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<h4 class="text-base font-bold text-primary">{{ t('admin.trainingConfig.directVideo.title') }}</h4>
|
||||
<p class="mt-1 text-xs text-muted">{{ t('admin.trainingConfig.directVideo.hint') }}</p>
|
||||
</div>
|
||||
<button class="btn-secondary btn-sm" type="button" :disabled="isUploadingVideo" @click="openVideoUpload"><Plus class="h-4 w-4" />{{ isUploadingVideo ? t('admin.trainingConfig.directVideo.uploading') : t('admin.trainingConfig.directVideo.upload') }}</button>
|
||||
<input ref="videoInput" type="file" accept="video/*" class="hidden" @change="uploadTrainingVideo" />
|
||||
</div>
|
||||
<div class="space-y-3 p-4 md:p-5">
|
||||
<div v-if="!directVideoResources.length" class="rounded-xl border border-dashed border-default bg-surface-soft/50 px-3 py-8 text-center text-xs text-muted">{{ t('admin.trainingConfig.directVideo.empty') }}</div>
|
||||
<div v-for="(resource, index) in directVideoResources" v-else :key="resource.id || `direct-video-${index}`" class="grid gap-3 rounded-xl border border-default bg-white p-4 md:grid-cols-[minmax(0,1fr)_180px_auto] md:items-end">
|
||||
<div class="flex min-w-0 items-center gap-2 text-sm font-medium text-primary"><Video class="h-4 w-4 shrink-0 text-violet-500" /><span class="truncate">{{ resource.title || videoGuideCandidates.find((guide) => guide.id === resource.agent_guide_id)?.file_name || t('admin.trainingConfig.directVideo.unnamed') }}</span></div>
|
||||
<label class="label-field">{{ t('admin.trainingConfig.fields.requiredDuration') }}<input v-model.number="resource.required_duration" type="number" min="0" class="input-field mt-2" /></label>
|
||||
<button class="btn-danger btn-sm" type="button" @click="removeResource(resource)"><Trash2 class="h-4 w-4" />{{ t('admin.delete') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<article
|
||||
v-if="isSafetyConfig"
|
||||
v-for="(level, levelIndex) in trainingLevels"
|
||||
:key="level"
|
||||
class="w-full overflow-hidden rounded-2xl border bg-surface shadow-sm"
|
||||
@@ -667,6 +833,44 @@ onMounted(() => void load());
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="form.training_type === 'lean_management'" id="training-section-lean" class="surface-panel scroll-mt-20 p-5 md:p-7">
|
||||
<div class="mb-6 flex items-start gap-3">
|
||||
<span class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-emerald-50 text-emerald-600"><Video class="h-5 w-5" /></span>
|
||||
<div><h3 class="text-base font-bold text-primary">{{ t('admin.trainingConfig.sections.leanTitle') }}</h3><p class="mt-1 text-sm text-muted">{{ t('admin.trainingConfig.sections.leanDesc') }}</p></div>
|
||||
</div>
|
||||
<div v-if="form.status !== 'published'" class="rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800">{{ t('admin.trainingConfig.lean.publishRequired') }}</div>
|
||||
<div v-else class="space-y-5">
|
||||
<div class="grid gap-5 md:grid-cols-2">
|
||||
<label class="label-field">{{ t('admin.trainingConfig.lean.weekKey') }}<input v-model="leanWeekKey" type="date" class="input-field mt-2" /></label>
|
||||
<label class="label-field">{{ t('admin.trainingConfig.lean.dueAt') }}<input v-model="leanDueAt" type="datetime-local" class="input-field mt-2" /></label>
|
||||
</div>
|
||||
<div class="rounded-xl border border-default bg-surface-soft/40 p-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div><h4 class="text-sm font-semibold text-primary">{{ t('admin.trainingConfig.lean.videosTitle') }}</h4><p class="mt-1 text-xs text-muted">{{ t('admin.trainingConfig.lean.videosHint', { count: leanVideoResourceIds.length }) }}</p></div>
|
||||
<span v-if="leanTask?.week_key === leanWeekKey" class="rounded-full bg-slate-100 px-3 py-1 text-xs font-medium text-slate-600">{{ t('admin.trainingConfig.lean.videosFrozen') }}</span>
|
||||
</div>
|
||||
<div v-if="!leanVideoResources.length" class="mt-4 rounded-lg border border-dashed border-default bg-white px-4 py-5 text-sm text-muted">{{ t('admin.trainingConfig.lean.noVideoResources') }}</div>
|
||||
<div v-else class="mt-4 grid gap-3 md:grid-cols-2">
|
||||
<label v-for="resource in leanVideoResources" :key="resource.id" class="flex cursor-pointer items-center gap-3 rounded-xl border bg-white p-4 transition" :class="leanVideoResourceIds.includes(resource.id as number) ? 'border-emerald-400 ring-1 ring-emerald-200' : 'border-default'">
|
||||
<input :checked="leanVideoResourceIds.includes(resource.id as number)" :disabled="leanTask?.week_key === leanWeekKey" type="checkbox" class="h-4 w-4 rounded border-default text-emerald-600 focus:ring-emerald-500" @change="toggleLeanVideo(resource.id as number)" />
|
||||
<span class="min-w-0 flex-1 truncate text-sm text-primary">{{ leanTaskVideoNames.get(resource.id as number) }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-xl border border-default bg-surface-soft/40 p-4">
|
||||
<div><h4 class="text-sm font-semibold text-primary">{{ t('admin.trainingConfig.lean.targetsTitle') }}</h4><p class="mt-1 text-xs text-muted">{{ t('admin.trainingConfig.lean.targetsHint') }}</p></div>
|
||||
<div class="mt-4 grid gap-4 md:grid-cols-2">
|
||||
<label class="label-field">{{ t('admin.trainingConfig.lean.targetRoles') }}<select v-model="leanTargetRoles" multiple class="select-field mt-2 min-h-28"><option v-for="role in leanRoleOptions" :key="role" :value="role">{{ role }}</option></select></label>
|
||||
<label class="label-field">{{ t('admin.trainingConfig.lean.targetUsers') }}<select v-model="leanTargetUserIds" multiple class="select-field mt-2 min-h-28"><option v-for="user in leanTargetUsers" :key="user.id" :value="user.id">{{ user.real_name || user.username }} · {{ user.username }}</option></select></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 rounded-xl border border-emerald-200 bg-emerald-50/50 p-4">
|
||||
<p class="text-sm text-emerald-800">{{ t('admin.trainingConfig.lean.summaryRule', { count: 50 }) }}</p>
|
||||
<button class="btn-primary btn-sm" type="button" :disabled="isSavingLeanTask || !leanWeekKey || !leanDueAt || leanVideoResourceIds.length !== 2 || (!leanTargetRoles.length && !leanTargetUserIds.length)" @click="saveLeanTask"><Save class="h-4 w-4" />{{ isSavingLeanTask ? t('admin.trainingConfig.saving') : t('admin.trainingConfig.lean.saveTask') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="training-section-exam" class="surface-panel scroll-mt-20 p-5 md:p-7">
|
||||
<div class="mb-6 flex items-start justify-between gap-4">
|
||||
<div class="flex items-start gap-3">
|
||||
|
||||
@@ -58,6 +58,30 @@ export interface TrainingConfigPayload {
|
||||
resources: TrainingConfigResource[];
|
||||
}
|
||||
|
||||
export interface LeanTrainingWeeklyTask {
|
||||
id: number;
|
||||
week_key: string;
|
||||
due_at: string;
|
||||
video_resource_ids: number[];
|
||||
target_roles: string[];
|
||||
target_user_ids: number[];
|
||||
videos: Array<{ id: number; name: string }>;
|
||||
status: string;
|
||||
min_summary_length: number;
|
||||
}
|
||||
|
||||
export interface LeanTrainingWeeklyTaskPayload {
|
||||
week_key: string;
|
||||
due_at: string;
|
||||
video_resource_ids: number[];
|
||||
target_roles: string[];
|
||||
target_user_ids: number[];
|
||||
}
|
||||
|
||||
export interface LeanTrainingDashboard {
|
||||
task: LeanTrainingWeeklyTask | null;
|
||||
}
|
||||
|
||||
export interface TrainingResourceCandidates {
|
||||
guides: Array<{
|
||||
id: number;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/api/training.api.ts
|
||||
* 用途:培训工作区专用 HTTP API,负责员工进度读取/保存、HR 记录查询、统计和导出。
|
||||
* 用途:培训工作区专用 HTTP API,负责员工进度读取/保存、HR 记录查询、统计导出和精益任务提醒。
|
||||
* 依赖:shared/api/client、auth headers、training.types。
|
||||
* 逻辑:把后端 training 领域的 snake_case 返回值统一映射成前端工作区需要的 camelCase 结构。
|
||||
* 逻辑:把后端 training 领域的 snake_case 返回值统一映射成前端工作区需要的 camelCase 结构,并提交精益未完成人员提醒请求。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
@@ -15,10 +15,37 @@ import type {
|
||||
TrainingRecord,
|
||||
TrainingStage,
|
||||
TrainingStats,
|
||||
LeanTrainingDashboard,
|
||||
LeanTrainingDashboardRow,
|
||||
LeanTrainingWeeklyTask,
|
||||
TrainingType,
|
||||
TrainingTypeOption,
|
||||
} from '../training/training.types';
|
||||
|
||||
type LeanTrainingTaskApi = {
|
||||
id: number; week_key: string; due_at: string; video_resource_ids: number[];
|
||||
target_roles: string[]; target_user_ids: number[];
|
||||
videos: Array<{ id: number; name: string }>; status: string; min_summary_length: number;
|
||||
};
|
||||
|
||||
type LeanTrainingDashboardRowApi = {
|
||||
id?: number; user_id: number; employee_id?: string | null; name: string; department?: string | null;
|
||||
videos: Array<{ name: string; watched_at?: string | null }>;
|
||||
summary_text?: string | null; status: 'completed' | 'incomplete'; completed_at?: string | null;
|
||||
};
|
||||
|
||||
const mapLeanTask = (data: LeanTrainingTaskApi): LeanTrainingWeeklyTask => ({
|
||||
id: data.id, weekKey: data.week_key, dueAt: data.due_at, videoResourceIds: data.video_resource_ids || [],
|
||||
targetRoles: data.target_roles || [], targetUserIds: data.target_user_ids || [],
|
||||
videos: data.videos || [], status: data.status, minSummaryLength: data.min_summary_length,
|
||||
});
|
||||
|
||||
const mapLeanDashboardRow = (data: LeanTrainingDashboardRowApi): LeanTrainingDashboardRow => ({
|
||||
id: data.id, userId: data.user_id, employeeId: data.employee_id, name: data.name, department: data.department,
|
||||
videos: (data.videos || []).map((item) => ({ name: item.name, watchedAt: item.watched_at })),
|
||||
summaryText: data.summary_text, status: data.status, completedAt: data.completed_at,
|
||||
});
|
||||
|
||||
type TrainingRecordApi = {
|
||||
id: number;
|
||||
user_id?: number;
|
||||
@@ -229,6 +256,31 @@ export async function getMyTrainingTypes(): Promise<TrainingTypeOption[]> {
|
||||
return requestJson<TrainingTypeOption[]>('/api/user/training-types', authHeaders());
|
||||
}
|
||||
|
||||
export async function getCurrentLeanTrainingTask(): Promise<LeanTrainingWeeklyTask | null> {
|
||||
const response = await requestJson<LeanTrainingTaskApi | null>('/api/user/lean-training/current-task', authHeaders());
|
||||
return response ? mapLeanTask(response) : null;
|
||||
}
|
||||
|
||||
export async function saveMyLeanTrainingCompletion(payload: { weeklyTaskId: number; watchedAt: Record<string, string>; summaryText: string }): Promise<LeanTrainingDashboardRow> {
|
||||
const response = await requestJson<LeanTrainingDashboardRowApi>('/api/user/lean-training/completions', {
|
||||
method: 'PUT', ...jsonAuthHeaders(), body: JSON.stringify({ weekly_task_id: payload.weeklyTaskId, watched_at: payload.watchedAt, summary_text: payload.summaryText }),
|
||||
});
|
||||
return mapLeanDashboardRow(response);
|
||||
}
|
||||
|
||||
export async function getLeanTrainingDashboard(): Promise<LeanTrainingDashboard> {
|
||||
const response = await requestJson<{ task: LeanTrainingTaskApi | null; completed: LeanTrainingDashboardRowApi[]; incomplete: LeanTrainingDashboardRowApi[] }>('/api/admin/lean-training/dashboard', authHeaders());
|
||||
return { task: response.task ? mapLeanTask(response.task) : null, completed: (response.completed || []).map(mapLeanDashboardRow), incomplete: (response.incomplete || []).map(mapLeanDashboardRow) };
|
||||
}
|
||||
|
||||
export async function sendLeanTrainingReminders(weeklyTaskId: number, userIds: number[]): Promise<{ created: number; skipped: number; failed: number }> {
|
||||
return requestJson<{ created: number; skipped: number; failed: number }>(`/api/admin/lean-training/weekly-tasks/${weeklyTaskId}/reminders`, {
|
||||
method: 'POST',
|
||||
...jsonAuthHeaders(),
|
||||
body: JSON.stringify({ user_ids: userIds }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function getMyTrainingProgress(type: string = 'onboarding'): Promise<TrainingProgressRecord | null> {
|
||||
const data = await requestJson<TrainingRecordApi | null>(`/api/user/training-record?type=${encodeURIComponent(type)}`, authHeaders());
|
||||
return data ? mapTrainingProgressRecord(data) : null;
|
||||
|
||||
@@ -11,6 +11,7 @@ import { computed, reactive, ref, watch, type ShallowUnwrapRef } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
BookOpen,
|
||||
Bell,
|
||||
CheckCircle2,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
@@ -33,9 +34,9 @@ import { resolveTrainingExamPdfGuide, type TrainingGuideLike } from '@/features/
|
||||
import { getMyTrainingConfig } from '@/features/chat/api/training.api';
|
||||
import type { TrainingAnswerRecord, TrainingRecord, TrainingQuestion } from '@/features/chat/training/training.types';
|
||||
import html2pdf from 'html2pdf.js';
|
||||
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
|
||||
const props = defineProps<{
|
||||
currentAgent: Record<string, unknown> | null;
|
||||
currentUser: Record<string, unknown> | null;
|
||||
@@ -326,7 +327,7 @@ const applyDefaultExpandedState = () => {
|
||||
|
||||
// 监听 Agent/角色切换,重置本地展开态:培训角色首次进入默认展开工作区。
|
||||
watch(
|
||||
() => [props.currentAgent?.id, workspace.isAdminViewer],
|
||||
() => [props.currentAgent?.id, workspace.canManageTrainingWorkspace],
|
||||
() => {
|
||||
userExpandedOverride.value = null;
|
||||
applyDefaultExpandedState();
|
||||
@@ -414,6 +415,40 @@ const isMaterialCompleted = (material: any) => {
|
||||
};
|
||||
|
||||
const currentPreviewVideoUrl = ref('');
|
||||
const activeNonSafetyVideoId = ref<number | null>(null);
|
||||
const nonSafetyVideoMaterials = computed(() => workspace.publishedTrainingMaterials.filter((material) => (
|
||||
material.resource?.fileType === 'video' && Boolean(material.resource.fileUrl)
|
||||
)));
|
||||
const activeNonSafetyVideo = computed(() => (
|
||||
nonSafetyVideoMaterials.value.find((material) => material.id === activeNonSafetyVideoId.value)
|
||||
|| nonSafetyVideoMaterials.value[0]
|
||||
|| null
|
||||
));
|
||||
|
||||
const selectNonSafetyVideo = (material: { id?: number | null; resource?: { fileUrl?: string } | null }) => {
|
||||
if (!material.resource?.fileUrl) return;
|
||||
if (workspace.currentViewingMaterialId !== material.id) {
|
||||
workspace.stopMaterialTimer();
|
||||
}
|
||||
activeNonSafetyVideoId.value = material.id ?? null;
|
||||
workspace.currentViewingMaterialId = material.id ?? null;
|
||||
};
|
||||
|
||||
const startNonSafetyVideoTimer = () => {
|
||||
if (activeNonSafetyVideo.value?.id != null) {
|
||||
workspace.startMaterialTimer(activeNonSafetyVideo.value.id);
|
||||
}
|
||||
};
|
||||
|
||||
const stopNonSafetyVideoTimer = () => {
|
||||
workspace.stopMaterialTimer();
|
||||
};
|
||||
|
||||
watch([() => workspace.learnerTab, nonSafetyVideoMaterials], () => {
|
||||
if (!nonSafetyVideoMaterials.value.some((material) => material.id === activeNonSafetyVideoId.value)) {
|
||||
activeNonSafetyVideoId.value = nonSafetyVideoMaterials.value[0]?.id ?? null;
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
const videoCountdownSeconds = ref(0);
|
||||
let videoCountdownTimer: ReturnType<typeof setInterval> | null = null;
|
||||
@@ -533,7 +568,7 @@ const currentSafetyStageText = computed(() => {
|
||||
{{ $t('chat.training.tabs.learner') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="workspace.isAdminViewer"
|
||||
v-if="workspace.canManageTrainingWorkspace"
|
||||
type="button"
|
||||
class="rounded-full px-3 py-1.5 text-xs font-medium transition"
|
||||
:class="workspace.activeView === 'admin' ? 'bg-brand-600 text-white' : 'bg-surface-soft text-secondary hover:bg-slate-100'"
|
||||
@@ -546,7 +581,7 @@ const currentSafetyStageText = computed(() => {
|
||||
|
||||
<div class="flex flex-wrap items-center justify-end gap-2">
|
||||
<button
|
||||
v-if="trainingExamPdfGuide"
|
||||
v-if="trainingExamPdfGuide && workspace.learnerTab === 'safety'"
|
||||
type="button"
|
||||
class="inline-flex h-9 items-center gap-2 rounded-xl border border-default bg-white px-3.5 text-xs font-medium leading-none text-secondary transition hover:bg-surface-soft"
|
||||
@click="emit('open-guide', Number(trainingExamPdfGuide.id))"
|
||||
@@ -555,7 +590,7 @@ const currentSafetyStageText = computed(() => {
|
||||
<span class="leading-none">{{ $t('chat.training.actions.viewExamPdf') }}</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="workspace.stage === 'video'"
|
||||
v-if="workspace.learnerTab === 'safety' && workspace.safetyViewStage !== 'exam' && workspace.safetyViewStage !== 'result'"
|
||||
type="button"
|
||||
class="inline-flex min-h-9 items-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-700 transition hover:bg-brand-100"
|
||||
@click="showVideoModal = true"
|
||||
@@ -619,7 +654,7 @@ const currentSafetyStageText = computed(() => {
|
||||
{{ $t('chat.training.tabs.learner') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="workspace.isAdminViewer"
|
||||
v-if="workspace.canManageTrainingWorkspace"
|
||||
type="button"
|
||||
class="rounded-full px-3 py-1.5 text-xs font-medium transition"
|
||||
:class="workspace.activeView === 'admin' ? 'bg-brand-600 text-white' : 'bg-surface-soft text-secondary hover:bg-slate-100'"
|
||||
@@ -632,7 +667,7 @@ const currentSafetyStageText = computed(() => {
|
||||
|
||||
<div class="flex flex-wrap items-center justify-end gap-2">
|
||||
<button
|
||||
v-if="trainingExamPdfGuide"
|
||||
v-if="trainingExamPdfGuide && workspace.learnerTab === 'safety'"
|
||||
type="button"
|
||||
class="inline-flex h-9 items-center gap-2 rounded-xl border border-default bg-white px-3.5 text-xs font-medium leading-none text-secondary transition hover:bg-surface-soft"
|
||||
@click="emit('open-guide', Number(trainingExamPdfGuide.id))"
|
||||
@@ -708,7 +743,27 @@ const currentSafetyStageText = computed(() => {
|
||||
<div class="mt-3 text-base font-semibold text-primary">{{ $t('chat.training.noContent.title') }}</div>
|
||||
<div class="mt-1 text-sm">{{ $t('chat.training.noContent.description') }}</div>
|
||||
</div>
|
||||
<template v-else-if="workspace.learnerTab !== 'safety'">
|
||||
<div v-if="workspace.learnerTab === 'lean_management' && workspace.leanTask" class="col-span-full rounded-2xl border border-emerald-200 bg-emerald-50/40 p-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<div class="text-base font-semibold text-primary">{{ $t('chat.training.lean.learner.title') }}</div>
|
||||
<div class="mt-1 text-xs text-secondary">{{ $t('chat.training.lean.learner.description', { count: workspace.leanTask.videos.length, minSummaryLength: workspace.leanTask.minSummaryLength }) }}</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.leanTask.dueAt.slice(0, 16).replace('T', ' ') }) }}</div>
|
||||
</div>
|
||||
<div class="mt-4 grid gap-3 md:grid-cols-2">
|
||||
<button v-for="video in workspace.leanTask.videos" :key="video.id" type="button" class="rounded-xl border border-default bg-white p-3 text-left hover:border-emerald-400" @click="workspace.markLeanVideoWatched(video.id)">
|
||||
<div class="flex items-center gap-2 text-sm font-medium text-primary"><Video class="h-4 w-4 text-emerald-600" />{{ video.name }}</div>
|
||||
<div class="mt-1 text-xs text-secondary">{{ workspace.leanWatchedAt[String(video.id)] ? $t('chat.training.lean.watchedAt', { time: (workspace.leanWatchedAt[String(video.id)] || '').slice(0, 19).replace('T', ' ') }) : $t('chat.training.lean.markVideoWatched') }}</div>
|
||||
</button>
|
||||
</div>
|
||||
<textarea v-model="workspace.leanSummaryText" rows="4" class="mt-3 w-full rounded-xl border border-default bg-white p-3 text-sm" :placeholder="$t('chat.training.lean.summaryPlaceholder', { minSummaryLength: workspace.leanTask.minSummaryLength })" />
|
||||
<div class="mt-2 flex items-center justify-between gap-3">
|
||||
<span class="text-xs" :class="workspace.leanSummaryText.length >= workspace.leanTask.minSummaryLength ? 'text-emerald-600' : 'text-amber-600'">{{ $t('chat.training.lean.summaryLength', { current: workspace.leanSummaryText.length, minSummaryLength: workspace.leanTask.minSummaryLength }) }}</span>
|
||||
<button type="button" class="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white disabled:cursor-not-allowed disabled:opacity-50" :disabled="workspace.leanSummaryText.trim().length < workspace.leanTask.minSummaryLength || Object.keys(workspace.leanWatchedAt).length < workspace.leanTask.videos.length" @click="workspace.submitLeanTrainingCompletion">{{ $t('chat.training.lean.submitSummary') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="workspace.learnerTab !== 'safety' && workspace.learnerTab !== 'lean_management'">
|
||||
<div :class="learnerWorkspaceMainClass">
|
||||
<div v-if="showLearnerProgressModule" :class="progressCardClass">
|
||||
<div class="flex flex-col gap-1.5 lg:flex-row lg:items-start lg:justify-between">
|
||||
@@ -762,31 +817,34 @@ const currentSafetyStageText = computed(() => {
|
||||
<p v-if="learnerStepIntroDescription" class="mt-1 whitespace-pre-line text-sm leading-6 text-secondary">{{ learnerStepIntroDescription }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<ul v-if="workspace.publishedTrainingMaterials.length" class="space-y-2">
|
||||
<li
|
||||
v-for="material in workspace.publishedTrainingMaterials"
|
||||
:key="material.id || `${material.resourceType}-${material.sortOrder}`"
|
||||
class="flex items-center justify-between gap-3 rounded-xl border border-slate-100 bg-slate-50 px-3 py-2.5 cursor-pointer transition hover:bg-slate-100"
|
||||
@click="handleMaterialClick(material)"
|
||||
>
|
||||
<div class="flex min-w-0 items-center gap-2 text-sm font-medium text-primary hover:text-brand-600">
|
||||
<Video v-if="material.resource?.fileType === 'video'" class="h-4 w-4 text-brand-500" />
|
||||
<FileText v-else class="h-4 w-4 text-slate-400" />
|
||||
<span class="truncate">{{ material.title || material.resource?.fileName || $t('chat.training.video.playerTitle') }}</span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-if="activeNonSafetyVideo" class="mt-3 overflow-hidden rounded-2xl border border-default bg-black shadow-lg">
|
||||
<video
|
||||
:key="activeNonSafetyVideo.id ?? activeNonSafetyVideo.resource?.fileUrl"
|
||||
controls
|
||||
playsinline
|
||||
preload="metadata"
|
||||
class="aspect-video w-full"
|
||||
:src="activeNonSafetyVideo.resource?.fileUrl"
|
||||
@play="startNonSafetyVideoTimer"
|
||||
@pause="stopNonSafetyVideoTimer"
|
||||
@ended="stopNonSafetyVideoTimer"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 relative group cursor-pointer overflow-hidden rounded-2xl border border-default bg-slate-900 shadow-lg aspect-video flex items-center justify-center" @click="showVideoModal = true">
|
||||
<img src="https://coresg-normal.trae.ai/api/ide/v1/text_to_image?prompt=Professional%20corporate%20training%20video%20cover%2C%20high-quality%2C%20modern%20office%20background%2C%20play%20button%20overlay&image_size=landscape_16_9" class="absolute inset-0 w-full h-full object-cover opacity-60 group-hover:scale-105 transition-transform duration-500" />
|
||||
<div class="relative z-10 flex flex-col items-center gap-3">
|
||||
<div class="h-16 w-16 flex items-center justify-center rounded-full bg-white/20 backdrop-blur-md border border-white/30 group-hover:bg-brand-600 group-hover:border-brand-500 transition-all duration-300">
|
||||
<PlayCircle class="h-8 w-8 text-white fill-white/20" />
|
||||
</div>
|
||||
<span class="text-white font-medium drop-shadow-md">{{ $t('chat.training.video.playerTitle') }}</span>
|
||||
</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">
|
||||
{{ $t('chat.training.video.empty') }}
|
||||
</div>
|
||||
<div v-if="nonSafetyVideoMaterials.length > 1" class="mt-3 grid gap-2 sm:grid-cols-2">
|
||||
<button
|
||||
v-for="(material, index) in nonSafetyVideoMaterials"
|
||||
:key="material.id || `${material.resourceType}-${material.sortOrder}`"
|
||||
type="button"
|
||||
class="flex min-w-0 items-center gap-2 rounded-xl border px-3 py-2.5 text-left text-sm transition"
|
||||
:class="activeNonSafetyVideo?.id === material.id ? 'border-brand-300 bg-brand-50 text-brand-700' : 'border-default bg-white text-primary hover:border-brand-200'"
|
||||
@click="selectNonSafetyVideo(material)"
|
||||
>
|
||||
<Video class="h-4 w-4 shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate">{{ material.title || material.resource?.fileName || `${$t('chat.training.video.playerTitle')} ${index + 1}` }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1572,6 +1630,69 @@ const currentSafetyStageText = computed(() => {
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="workspace.canViewLeanDashboard && workspace.leanDashboard.task" class="rounded-2xl border border-emerald-200 bg-emerald-50/40 p-4 shadow-sm">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<div class="flex items-center gap-2 text-base font-semibold text-primary">
|
||||
<BookOpen class="h-4 w-4 text-emerald-600" />
|
||||
{{ $t('chat.training.lean.dashboard.title') }}
|
||||
</div>
|
||||
<div class="mt-1 text-xs text-secondary">{{ $t('chat.training.lean.dashboard.week', { week: workspace.leanDashboard.task.weekKey }) }}</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>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid gap-4 xl:grid-cols-2">
|
||||
<div v-for="group in [{ key: 'completed', rows: workspace.leanDashboard.completed }, { key: 'incomplete', rows: workspace.leanDashboard.incomplete }]" :key="group.key" class="overflow-hidden rounded-2xl border border-default bg-white">
|
||||
<div class="flex items-center justify-between border-b border-default px-4 py-3" :class="group.key === 'completed' ? 'bg-emerald-50/70' : 'bg-amber-50/70'">
|
||||
<div class="text-sm font-semibold text-primary">{{ $t(`chat.training.lean.dashboard.${group.key}`) }}</div>
|
||||
<div class="rounded-full bg-white px-2.5 py-1 text-xs font-medium text-secondary">{{ $t('chat.training.lean.dashboard.count', { count: group.rows.length }) }}</div>
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-[900px] border-collapse text-sm">
|
||||
<thead class="bg-surface-soft">
|
||||
<tr>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.employeeId') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.name') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.department') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.videoName') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.watchedAt') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.status') }}</th>
|
||||
<th class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.summary') }}</th>
|
||||
<th v-if="group.key === 'incomplete'" class="border-b border-default px-3 py-2.5 text-left font-semibold text-primary">{{ $t('chat.training.lean.columns.action') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in group.rows" :key="row.userId" class="odd:bg-white even:bg-surface-soft/30">
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ row.employeeId || '--' }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 font-medium text-primary">{{ row.name }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary">{{ row.department || '--' }}</td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary"><div v-for="video in row.videos" :key="video.name" class="whitespace-nowrap">{{ video.name }}</div><span v-if="!row.videos.length">--</span></td>
|
||||
<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, 19).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' : 'bg-amber-50 text-amber-700'">{{ $t(`chat.training.lean.status.${row.status}`) }}</span></td>
|
||||
<td class="border-b border-default px-3 py-2.5 text-secondary"><div class="min-w-48 whitespace-pre-wrap break-words">{{ row.summaryText || '--' }}</div></td>
|
||||
<td v-if="group.key === 'incomplete'" class="border-b border-default px-3 py-2.5">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-lg bg-amber-500 px-2.5 py-1.5 text-xs font-medium text-white transition hover:bg-amber-600 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="workspace.leanReminderLoading[row.userId]"
|
||||
@click="workspace.remindLeanTrainingMember(row.userId)"
|
||||
>
|
||||
<Bell class="h-3.5 w-3.5" />
|
||||
{{ workspace.leanReminderLoading[row.userId] ? $t('chat.training.lean.reminder.sending') : $t('chat.training.lean.reminder.action') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="group.rows.length === 0">
|
||||
<td :colspan="group.key === 'incomplete' ? 8 : 7" class="px-4 py-6 text-center text-sm text-muted">{{ $t('chat.training.lean.dashboard.empty') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -139,3 +139,33 @@ export interface TrainingStats {
|
||||
passRate: number;
|
||||
averageScore: number;
|
||||
}
|
||||
|
||||
export interface LeanTrainingWeeklyTask {
|
||||
id: number;
|
||||
weekKey: string;
|
||||
dueAt: string;
|
||||
videoResourceIds: number[];
|
||||
targetRoles: string[];
|
||||
targetUserIds: number[];
|
||||
videos: Array<{ id: number; name: string }>;
|
||||
status: string;
|
||||
minSummaryLength: number;
|
||||
}
|
||||
|
||||
export interface LeanTrainingDashboardRow {
|
||||
id?: number;
|
||||
userId: number;
|
||||
employeeId?: string | null;
|
||||
name: string;
|
||||
department?: string | null;
|
||||
videos: Array<{ name: string; watchedAt?: string | null }>;
|
||||
summaryText?: string | null;
|
||||
status: 'completed' | 'incomplete';
|
||||
completedAt?: string | null;
|
||||
}
|
||||
|
||||
export interface LeanTrainingDashboard {
|
||||
task: LeanTrainingWeeklyTask | null;
|
||||
completed: LeanTrainingDashboardRow[];
|
||||
incomplete: LeanTrainingDashboardRow[];
|
||||
}
|
||||
Reference in new issue
Block a user