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