554 lines
35 KiB
Vue
554 lines
35 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* features/admin/modules/training-config/TrainingConfigPage.vue
|
|
* 用途:提供培训类型、基础规则、三级学习资料、考试题库与复盘内容的一体化后台配置界面。
|
|
* 依赖:admin.api 培训配置接口、training-config.types、TrainingTypeFormModal 与通用消息/删除确认组件。
|
|
* 逻辑:左侧切换培训类型,右侧编辑完整配置;保存时将题目同步到 settings 与内嵌题目资源后提交既有 API。
|
|
*/
|
|
import { computed, onMounted, ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import {
|
|
BookOpen,
|
|
CheckCircle2,
|
|
ChevronRight,
|
|
ClipboardCheck,
|
|
Edit,
|
|
FileQuestion,
|
|
FileText,
|
|
Layers3,
|
|
Library,
|
|
ListChecks,
|
|
Plus,
|
|
Save,
|
|
Settings2,
|
|
ShieldCheck,
|
|
Trash2,
|
|
Video,
|
|
} from 'lucide-vue-next';
|
|
import { useMessage } from '@/shared/composables/useMessage';
|
|
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
|
import {
|
|
createAdminTrainingConfig,
|
|
deleteAdminTrainingConfig,
|
|
listAdminTrainingConfigs,
|
|
listAdminTrainingResourceCandidates,
|
|
parseAdminTrainingQuestionBank,
|
|
updateAdminTrainingConfig,
|
|
} from '../../api/admin.api';
|
|
import type { TrainingConfig, TrainingConfigPayload, TrainingLevel } from '../../types/training-config.types';
|
|
import TrainingTypeFormModal from './components/TrainingTypeFormModal.vue';
|
|
|
|
const { t } = useI18n();
|
|
const msg = useMessage();
|
|
const configs = ref<TrainingConfig[]>([]);
|
|
const selectedId = ref<number | null>(null);
|
|
const isLoading = ref(true);
|
|
const isSaving = ref(false);
|
|
const showTypeEditor = ref(false);
|
|
const editingType = ref(false);
|
|
const deleteTarget = ref<TrainingConfig | null>(null);
|
|
const typeForm = ref({ training_type: '', name: '' });
|
|
const questionJsonText = ref('[]');
|
|
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 selected = computed(() => configs.value.find((item) => item.id === selectedId.value) || null);
|
|
const form = ref<TrainingConfigPayload>(emptyForm());
|
|
const contentResources = computed(() => form.value.resources.filter((resource) => resource.resource_type !== 'inline_questions'));
|
|
const trainingLevels: TrainingLevel[] = ['company', 'department', 'team'];
|
|
const guideGroups = computed(() => {
|
|
const groupUsages = [
|
|
{ key: 'company', usage: 'training_safety_company_video' },
|
|
{ key: 'department', usage: 'training_safety_department_video' },
|
|
{ key: 'team', usage: 'training_safety_team_video' },
|
|
];
|
|
const grouped = groupUsages.map((group) => ({
|
|
key: group.key,
|
|
items: candidates.value.guides.filter((guide) => guide.guide_usage === group.usage),
|
|
}));
|
|
const groupedUsages = new Set(groupUsages.map((group) => group.usage));
|
|
grouped.push({
|
|
key: 'other',
|
|
items: candidates.value.guides.filter((guide) => !groupedUsages.has(guide.guide_usage)),
|
|
});
|
|
return grouped.filter((group) => group.items.length > 0);
|
|
});
|
|
const questionCount = computed(() => {
|
|
try {
|
|
const questions = JSON.parse(questionJsonText.value);
|
|
return Array.isArray(questions) ? questions.length : 0;
|
|
} catch {
|
|
return 0;
|
|
}
|
|
});
|
|
const activeSection = ref('basic');
|
|
const sectionItems = computed(() => [
|
|
{ id: 'basic', label: t('admin.trainingConfig.sections.basicTitle'), icon: Layers3 },
|
|
{ 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 },
|
|
]);
|
|
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);
|
|
|
|
/** 创建新增培训类型所需的完整默认配置,确保沿用后端既有字段契约。 */
|
|
function emptyForm(): TrainingConfigPayload {
|
|
return {
|
|
training_type: '',
|
|
name: '',
|
|
version: 'v1.0',
|
|
status: 'draft',
|
|
pass_score: 90,
|
|
settings: { exam_mode: 'unified', questions: [] },
|
|
resources: [],
|
|
};
|
|
}
|
|
|
|
const showDeleteConfirm = computed({
|
|
get: () => deleteTarget.value !== null,
|
|
set: (visible: boolean) => {
|
|
if (!visible) deleteTarget.value = null;
|
|
},
|
|
});
|
|
|
|
/** 将选中的服务端配置复制到编辑表单,并兼容 settings 与内嵌资源中的历史题库数据。 */
|
|
const selectConfig = (config: TrainingConfig) => {
|
|
const inlineQuestions = config.resources.find((resource) => resource.resource_type === 'inline_questions')?.inline_questions;
|
|
const questions = Array.isArray(inlineQuestions) ? inlineQuestions : Array.isArray(config.settings.questions) ? config.settings.questions : [];
|
|
selectedId.value = config.id;
|
|
form.value = {
|
|
training_type: config.training_type,
|
|
name: config.name,
|
|
version: config.version,
|
|
status: config.status,
|
|
pass_score: config.pass_score,
|
|
settings: { ...config.settings, questions },
|
|
resources: config.resources.map((resource) => ({ ...resource })),
|
|
};
|
|
questionJsonText.value = JSON.stringify(questions, null, 2);
|
|
questionSourceVersionId.value = null;
|
|
questionParseMeta.value = null;
|
|
};
|
|
|
|
/** 从已选择的员工培训知识库当前 PDF 解析题库,并将结果回填到可继续手工编辑的 JSON。 */
|
|
const parseQuestionBank = async () => {
|
|
if (!questionSourceVersionId.value) {
|
|
msg.warning(t('admin.trainingConfig.messages.questionSourceRequired'));
|
|
return;
|
|
}
|
|
isParsingQuestions.value = true;
|
|
try {
|
|
const result = await parseAdminTrainingQuestionBank(questionSourceVersionId.value);
|
|
questionJsonText.value = JSON.stringify(result.question_bank, null, 2);
|
|
questionParseMeta.value = { mode: result.extraction_mode, fileName: result.source_file_name, skipped: result.skipped_question_numbers };
|
|
msg.success(t('admin.trainingConfig.messages.parseSuccess', { count: result.parsed_count }));
|
|
} catch (error) {
|
|
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.parseFailed'));
|
|
} finally {
|
|
isParsingQuestions.value = false;
|
|
}
|
|
};
|
|
|
|
/** 将 settings 中的数组字段转换为多行文本供复盘表单编辑。 */
|
|
const settingText = (key: string) => {
|
|
const value = form.value.settings[key];
|
|
return Array.isArray(value) ? value.join('\n') : String(value || '');
|
|
};
|
|
|
|
/** 将复盘区域的多行文本清洗为非空数组并写回 settings。 */
|
|
const updateSettingText = (key: string, value: string) => {
|
|
form.value.settings[key] = value.split(/\r?\n/).map((item) => item.trim()).filter(Boolean);
|
|
};
|
|
|
|
const settingSummaryByStageText = (level: string) => {
|
|
const summaries = (form.value.settings.summaryByStage as Record<string, string[]>) || {};
|
|
const value = summaries[level];
|
|
return Array.isArray(value) ? value.join('\n') : String(value || '');
|
|
};
|
|
|
|
const updateSettingSummaryByStageText = (level: string, value: string) => {
|
|
if (!form.value.settings.summaryByStage) {
|
|
form.value.settings.summaryByStage = {};
|
|
}
|
|
const summaries = form.value.settings.summaryByStage as Record<string, string[]>;
|
|
summaries[level] = value.split(/\r?\n/).map((item) => item.trim()).filter(Boolean);
|
|
};
|
|
|
|
/** 并行加载培训配置与可选资料,并默认打开首个培训类型。 */
|
|
const load = async () => {
|
|
isLoading.value = true;
|
|
try {
|
|
const [loadedConfigs, loadedCandidates] = await Promise.all([
|
|
listAdminTrainingConfigs(),
|
|
listAdminTrainingResourceCandidates(),
|
|
]);
|
|
configs.value = loadedConfigs;
|
|
candidates.value = loadedCandidates;
|
|
const firstConfig = configs.value[0];
|
|
if (firstConfig) selectConfig(firstConfig);
|
|
} catch (error) {
|
|
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.loadFailed'));
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
};
|
|
|
|
/** 打开新增培训类型弹窗并重置类型表单。 */
|
|
const openCreate = () => {
|
|
editingType.value = false;
|
|
typeForm.value = { training_type: '', name: '' };
|
|
showTypeEditor.value = true;
|
|
};
|
|
|
|
/** 使用当前培训类型信息打开编辑弹窗。 */
|
|
const editType = () => {
|
|
if (selected.value) {
|
|
editingType.value = true;
|
|
typeForm.value = { training_type: selected.value.training_type, name: selected.value.name };
|
|
showTypeEditor.value = true;
|
|
}
|
|
};
|
|
|
|
/** 校验并新增或更新培训类型,成功后刷新列表并保持当前选中项。 */
|
|
const saveType = async () => {
|
|
const rawType = typeForm.value.training_type.trim();
|
|
typeForm.value.training_type = ({
|
|
'入职培训': 'onboarding',
|
|
'新人培训': 'onboarding',
|
|
'安全培训': 'safety',
|
|
} as Record<string, string>)[rawType] || rawType.toLowerCase();
|
|
if (!['onboarding', 'safety'].includes(typeForm.value.training_type) || !typeForm.value.name.trim()) {
|
|
msg.warning(t('admin.trainingConfig.messages.typeRequired'));
|
|
return;
|
|
}
|
|
isSaving.value = true;
|
|
try {
|
|
const existing = editingType.value ? selected.value : null;
|
|
const payload = existing ? { ...form.value, training_type: typeForm.value.training_type, name: typeForm.value.name } : {
|
|
...emptyForm(), training_type: typeForm.value.training_type, name: typeForm.value.name,
|
|
};
|
|
const saved = existing ? await updateAdminTrainingConfig(existing.id, payload) : await createAdminTrainingConfig(payload);
|
|
await load();
|
|
selectConfig(saved);
|
|
showTypeEditor.value = false;
|
|
msg.success(t('admin.trainingConfig.messages.saved'));
|
|
} catch (error) {
|
|
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.saveFailed'));
|
|
} finally {
|
|
isSaving.value = false;
|
|
}
|
|
};
|
|
|
|
/** 校验题目 JSON,将题库双写至兼容字段后通过既有更新接口保存完整配置。 */
|
|
const saveConfig = async () => {
|
|
if (!selected.value) return;
|
|
try {
|
|
const questions = JSON.parse(questionJsonText.value);
|
|
if (!Array.isArray(questions)) throw new Error();
|
|
form.value.settings.questions = questions;
|
|
const inlineResource = form.value.resources.find((resource) => resource.resource_type === 'inline_questions');
|
|
if (questions.length) {
|
|
if (inlineResource) inlineResource.inline_questions = questions;
|
|
else form.value.resources.push({ resource_type: 'inline_questions', title: t('admin.trainingConfig.questionBankTitle'), sort_order: 1000, inline_questions: questions });
|
|
} else if (inlineResource) {
|
|
form.value.resources = form.value.resources.filter((resource) => resource !== inlineResource);
|
|
}
|
|
} catch {
|
|
msg.warning(t('admin.trainingConfig.messages.invalidQuestions'));
|
|
return;
|
|
}
|
|
isSaving.value = true;
|
|
try {
|
|
const saved = await updateAdminTrainingConfig(selected.value.id, form.value);
|
|
await load();
|
|
selectConfig(saved);
|
|
msg.success(t('admin.trainingConfig.messages.saved'));
|
|
} catch (error) {
|
|
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.saveFailed'));
|
|
} finally {
|
|
isSaving.value = false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 向指定培训级别新增一条资料绑定。
|
|
* AI 触发时机:管理员点击三级卡片内的“添加资料”时调用,新增项必须携带对应 training_level,避免员工端跨级展示。
|
|
*/
|
|
const addResource = (trainingLevel: TrainingLevel) => {
|
|
form.value.resources.push({ resource_type: 'agent_guide', training_level: trainingLevel, title: '', required_duration: 0, sort_order: form.value.resources.length });
|
|
};
|
|
|
|
/** 返回指定级别的资料,供三级卡片独立渲染与增删。 */
|
|
const resourcesByLevel = (trainingLevel: TrainingLevel) => contentResources.value.filter((resource) => resource.training_level === trainingLevel);
|
|
|
|
/** 从当前编辑表单中移除指定资料绑定。 */
|
|
const removeResource = (resource: TrainingConfigPayload['resources'][number]) => {
|
|
form.value.resources = form.value.resources.filter((item) => item !== resource);
|
|
};
|
|
|
|
/** 切换资料类型时清空旧关联主键,避免提交互斥资源字段。 */
|
|
const updateResourceType = (resource: TrainingConfigPayload['resources'][number]) => {
|
|
resource.agent_guide_id = undefined;
|
|
resource.kb_document_version_id = undefined;
|
|
};
|
|
|
|
const scrollToSection = (sectionId: string) => {
|
|
activeSection.value = sectionId;
|
|
document.getElementById(`training-section-${sectionId}`)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
};
|
|
|
|
/** 按发布状态返回统一的后台状态标签颜色。 */
|
|
const statusClass = (status: TrainingConfig['status']) => {
|
|
if (status === 'published') return 'alert-success';
|
|
if (status === 'archived') return 'bg-surface-strong text-muted ring-1 ring-inset ring-default';
|
|
return 'alert-warning';
|
|
};
|
|
|
|
/** 删除确认后的当前培训配置,并刷新左侧类型列表。 */
|
|
const deleteType = async () => {
|
|
if (!deleteTarget.value) return;
|
|
try {
|
|
await deleteAdminTrainingConfig(deleteTarget.value.id);
|
|
deleteTarget.value = null;
|
|
await load();
|
|
msg.success(t('admin.trainingConfig.messages.deleted'));
|
|
} catch (error) {
|
|
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.saveFailed'));
|
|
}
|
|
};
|
|
|
|
onMounted(() => void load());
|
|
</script>
|
|
|
|
<template>
|
|
<section class="page-shell min-h-full px-1 py-1 animate-fade-in-up">
|
|
<div class="mb-6 flex flex-col gap-1 px-1 sm:px-2">
|
|
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-brand-600">{{ t('admin.trainingConfig.eyebrow') }}</p>
|
|
<div class="flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
|
|
<div>
|
|
<h1 class="page-title">{{ t('admin.trainingConfig.title') }}</h1>
|
|
<p class="section-desc mt-2 max-w-2xl leading-6">{{ t('admin.trainingConfig.subtitle') }}</p>
|
|
</div>
|
|
<div class="hidden items-center gap-2 text-xs text-slate-400 lg:flex"><ShieldCheck class="h-4 w-4 text-emerald-500" />{{ t('admin.trainingConfig.pageHint') }}</div>
|
|
</div>
|
|
</div>
|
|
<div v-if="!isLoading" class="mb-5 grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
|
<div v-for="stat in [
|
|
{ label: t('admin.trainingConfig.stats.total'), value: configs.length, icon: Settings2, tone: 'bg-blue-50 text-blue-600' },
|
|
{ label: t('admin.trainingConfig.stats.published'), value: publishedCount, icon: CheckCircle2, tone: 'bg-emerald-50 text-emerald-600' },
|
|
{ label: t('admin.trainingConfig.stats.resources'), value: resourceCount, icon: Library, tone: 'bg-violet-50 text-violet-600' },
|
|
{ label: t('admin.trainingConfig.stats.levels'), value: configuredLevelCount, icon: Layers3, tone: 'bg-amber-50 text-amber-600' },
|
|
]" :key="stat.label" class="flex items-center gap-4 rounded-xl border border-slate-200 bg-white px-5 py-4 shadow-sm">
|
|
<span class="flex h-10 w-10 items-center justify-center rounded-xl" :class="stat.tone"><component :is="stat.icon" class="h-5 w-5" /></span>
|
|
<div><p class="text-xs font-medium text-muted">{{ stat.label }}</p><p class="mt-1 text-2xl font-bold tracking-tight text-primary">{{ stat.value }}</p></div>
|
|
</div>
|
|
</div>
|
|
<div v-if="isLoading" class="flex items-center justify-center py-24">
|
|
<div class="h-10 w-10 animate-spin rounded-full border-b-2 border-brand-600" />
|
|
</div>
|
|
<div v-else class="grid items-start gap-5 xl:grid-cols-[248px_minmax(0,1fr)]">
|
|
<aside class="surface-panel overflow-hidden xl:sticky xl:top-6">
|
|
<div class="border-b border-subtle bg-surface-soft px-4 py-5">
|
|
<div class="flex items-center justify-between gap-3">
|
|
<div>
|
|
<h2 class="text-sm font-bold text-primary">{{ t('admin.trainingConfig.types') }}</h2>
|
|
<p class="mt-1 text-xs text-muted">{{ t('admin.trainingConfig.typeCount', { count: configs.length }) }}</p>
|
|
</div>
|
|
<button class="btn-primary btn-icon" type="button" :title="t('admin.trainingConfig.addType')" @click="openCreate">
|
|
<Plus class="h-4 w-4" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="space-y-1.5 p-2.5">
|
|
<div v-if="!configs.length" class="px-3 py-10 text-center text-sm text-slate-500">{{ t('admin.trainingConfig.empty') }}</div>
|
|
<button v-for="item in configs" :key="item.id" type="button" class="group flex w-full items-center gap-3 rounded-lg border px-3 py-3 text-left transition" :class="item.id === selectedId ? 'border-brand-200 bg-brand-50 text-brand-700 shadow-sm' : 'border-transparent text-secondary hover:border-default hover:bg-surface-soft'" @click="selectConfig(item)">
|
|
<span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg" :class="item.id === selectedId ? 'bg-surface text-brand-600 shadow-sm' : 'bg-surface-strong text-muted'">
|
|
<ShieldCheck v-if="item.training_type === 'safety'" class="h-4.5 w-4.5" />
|
|
<BookOpen v-else class="h-4.5 w-4.5" />
|
|
</span>
|
|
<span class="min-w-0 flex-1">
|
|
<span class="block truncate text-sm font-semibold">{{ item.name }}</span>
|
|
<span class="mt-0.5 block truncate text-xs opacity-70">{{ item.training_type }} · {{ item.version }}</span>
|
|
</span>
|
|
<ChevronRight class="h-4 w-4 shrink-0 opacity-50 transition group-hover:translate-x-0.5" />
|
|
</button>
|
|
</div>
|
|
</aside>
|
|
|
|
<main v-if="selected" class="min-w-0 space-y-5">
|
|
<header class="surface-panel px-5 py-5 md:px-7">
|
|
<div class="flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between">
|
|
<div class="flex min-w-0 items-center gap-4">
|
|
<div class="flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-brand-50 text-brand-600">
|
|
<Settings2 class="h-6 w-6" />
|
|
</div>
|
|
<div class="min-w-0">
|
|
<div class="flex flex-wrap items-center gap-2.5">
|
|
<h2 class="truncate text-xl font-bold tracking-tight text-primary md:text-2xl">{{ form.name }}</h2>
|
|
<span class="inline-flex items-center rounded-full px-2.5 py-1 text-xs font-semibold ring-1 ring-inset" :class="statusClass(form.status)">
|
|
{{ t(`admin.trainingConfig.status.${form.status}`) }}
|
|
</span>
|
|
</div>
|
|
<p class="mt-1.5 text-sm text-slate-500">{{ t('admin.trainingConfig.headerMeta', { type: selected.training_type, version: form.version }) }}</p>
|
|
</div>
|
|
</div>
|
|
<div class="flex flex-wrap items-center gap-2">
|
|
<button class="btn-secondary btn-sm" type="button" @click="editType"><Edit class="h-4 w-4" />{{ t('admin.edit') }}</button>
|
|
<button class="btn-danger btn-sm" type="button" @click="deleteTarget = selected"><Trash2 class="h-4 w-4" />{{ t('admin.delete') }}</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<nav class="surface-panel sticky top-2 z-10 flex gap-2 overflow-x-auto p-2" aria-label="Training configuration sections">
|
|
<button v-for="item in sectionItems" :key="item.id" type="button" class="segment-item shrink-0" :class="activeSection === item.id ? 'segment-item--active' : ''" @click="scrollToSection(item.id)">
|
|
<component :is="item.icon" class="h-4 w-4" />{{ item.label }}
|
|
</button>
|
|
</nav>
|
|
|
|
<section id="training-section-basic" 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-blue-50 text-blue-600"><Layers3 class="h-5 w-5" /></span>
|
|
<div><h3 class="text-base font-bold text-primary">{{ t('admin.trainingConfig.sections.basicTitle') }}</h3><p class="mt-1 text-sm text-muted">{{ t('admin.trainingConfig.sections.basicDesc') }}</p></div>
|
|
</div>
|
|
<div class="grid gap-x-5 gap-y-4 md:grid-cols-2 xl:grid-cols-3">
|
|
<label class="label-field">{{ t('admin.trainingConfig.fields.name') }}<input v-model="form.name" class="input-field mt-2" /></label>
|
|
<label class="label-field">{{ t('admin.trainingConfig.fields.version') }}<input v-model="form.version" class="input-field mt-2" /></label>
|
|
<label class="label-field">{{ t('admin.trainingConfig.fields.status') }}<select v-model="form.status" class="select-field mt-2"><option value="draft">{{ t('admin.trainingConfig.status.draft') }}</option><option value="published">{{ t('admin.trainingConfig.status.published') }}</option><option value="archived">{{ t('admin.trainingConfig.status.archived') }}</option></select></label>
|
|
<label class="label-field">{{ t('admin.trainingConfig.fields.passScore') }}<div class="relative mt-2"><input v-model.number="form.pass_score" type="number" min="0" max="100" class="input-field pr-10" /><span class="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-sm text-muted">%</span></div></label>
|
|
<label class="label-field md:col-span-2 xl:col-span-2">{{ t('admin.trainingConfig.fields.examMode') }}<select v-model="form.settings.exam_mode" class="select-field mt-2"><option value="unified">{{ t('admin.trainingConfig.examMode.unified') }}</option><option value="per_level">{{ t('admin.trainingConfig.examMode.perLevel') }}</option></select></label>
|
|
</div>
|
|
</section>
|
|
|
|
<section id="training-section-resources" class="surface-panel scroll-mt-20 p-5 md:p-7">
|
|
<div class="mb-6 flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
|
<div class="flex items-start gap-3">
|
|
<span class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-violet-50 text-violet-600"><Library class="h-5 w-5" /></span>
|
|
<div><h3 class="text-base font-bold text-primary">{{ t('admin.trainingConfig.sections.resourcesTitle') }}</h3><p class="mt-1 text-sm text-muted">{{ t('admin.trainingConfig.sections.resourcesDesc') }}</p></div>
|
|
</div>
|
|
</div>
|
|
<div v-if="!contentResources.length" class="rounded-2xl border border-dashed border-default bg-surface-soft/50 px-5 py-10 text-center">
|
|
<Library class="mx-auto h-8 w-8 text-muted" />
|
|
<p class="mt-3 text-sm font-medium text-secondary">{{ t('admin.trainingConfig.resourcesEmpty') }}</p>
|
|
<p class="mt-1 text-xs text-muted">{{ t('admin.trainingConfig.resourcesEmptyHint') }}</p>
|
|
</div>
|
|
<div class="flex flex-col gap-5">
|
|
<article
|
|
v-for="(level, levelIndex) in trainingLevels"
|
|
:key="level"
|
|
class="w-full overflow-hidden rounded-2xl border bg-surface shadow-sm"
|
|
:class="level === 'company' ? 'border-emerald-200' : level === 'department' ? 'border-blue-200' : 'border-orange-200'"
|
|
>
|
|
<div
|
|
class="flex flex-col gap-4 border-b px-5 py-4 sm:flex-row sm:items-center sm:justify-between"
|
|
:class="level === 'company' ? 'border-emerald-200 bg-emerald-50/80' : level === 'department' ? 'border-blue-200 bg-blue-50/80' : 'border-orange-200 bg-orange-50/80'"
|
|
>
|
|
<div class="flex items-center gap-3">
|
|
<span
|
|
class="flex h-10 min-w-10 items-center justify-center rounded-xl px-2 text-sm font-bold text-white shadow-sm"
|
|
:class="level === 'company' ? 'bg-emerald-500' : level === 'department' ? 'bg-blue-500' : 'bg-orange-500'"
|
|
>L{{ levelIndex + 1 }}</span>
|
|
<div>
|
|
<h4 class="text-base font-bold text-primary">{{ t(`admin.trainingConfig.guideGroups.${level}`) }}</h4>
|
|
<div class="mt-1 flex items-center gap-1.5 text-xs font-medium text-muted">
|
|
<Library class="h-3.5 w-3.5" />
|
|
<span>{{ resourcesByLevel(level).length }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<button class="btn-secondary btn-sm self-start sm:self-auto" type="button" @click="addResource(level)"><Plus class="h-4 w-4" />{{ t('admin.trainingConfig.addResource') }}</button>
|
|
</div>
|
|
<div class="p-4 md:p-5">
|
|
<div v-if="!resourcesByLevel(level).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.resourcesEmpty') }}</div>
|
|
<div v-else class="space-y-4">
|
|
<div v-for="(resource, index) in resourcesByLevel(level)" :key="resource.id || `${level}-resource-${index}`" class="rounded-lg border border-default bg-surface p-3 shadow-sm">
|
|
<div class="grid gap-x-5 gap-y-4 md:grid-cols-2 xl:grid-cols-5">
|
|
<label class="label-field">{{ t('admin.trainingConfig.resourceKind') }}<select v-model="resource.resource_type" class="select-field mt-2" @change="updateResourceType(resource)"><option value="agent_guide">{{ t('admin.trainingConfig.resourceTypes.guide') }}</option><option value="kb_document_version">{{ t('admin.trainingConfig.resourceTypes.document') }}</option></select></label>
|
|
<label class="label-field">{{ t('admin.trainingConfig.resourceFile') }}
|
|
<select v-if="resource.resource_type === 'agent_guide'" v-model.number="resource.agent_guide_id" class="select-field mt-2">
|
|
<option :value="undefined">{{ t('admin.trainingConfig.selectResource') }}</option>
|
|
<optgroup v-for="group in guideGroups" :key="group.key" :label="t(`admin.trainingConfig.guideGroups.${group.key}`)">
|
|
<option v-for="guide in group.items" :key="guide.id" :value="guide.id">{{ guide.file_name }}</option>
|
|
</optgroup>
|
|
</select>
|
|
<select v-else v-model.number="resource.kb_document_version_id" class="select-field mt-2"><option :value="undefined">{{ t('admin.trainingConfig.selectResource') }}</option><option v-for="document in candidates.documents" :key="document.id" :value="document.id">{{ document.file_name }} · v{{ document.version_no }}</option></select>
|
|
</label>
|
|
<label class="label-field">{{ t('admin.trainingConfig.resourceTitle') }}<input v-model="resource.title" class="input-field mt-2" :placeholder="t('admin.trainingConfig.resourceTitlePlaceholder')" /></label>
|
|
<label class="label-field">所需时间(分钟)<input v-model.number="resource.required_duration" type="number" min="0" class="input-field mt-2" placeholder="0表示不限制" /></label>
|
|
<button class="flex h-10 w-full items-center justify-center gap-2 rounded-xl text-red-500 transition hover:bg-red-50 hover:text-red-600 mt-auto" type="button" :title="t('admin.delete')" @click="removeResource(resource)"><Trash2 class="h-4 w-4" />{{ t('admin.delete') }}</button>
|
|
</div>
|
|
<div v-if="resource.resource_type === 'agent_guide'" class="mt-3 flex items-center gap-2 text-xs text-muted"><Video class="h-3.5 w-3.5" />{{ t('admin.trainingConfig.guideGroupingHint') }}</div>
|
|
<div v-else class="mt-3 flex items-center gap-2 text-xs text-muted"><FileText class="h-3.5 w-3.5" />{{ t('admin.trainingConfig.documentVersionHint') }}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</article>
|
|
</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">
|
|
<span class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-amber-50 text-amber-600"><FileQuestion class="h-5 w-5" /></span>
|
|
<div><h3 class="text-base font-bold text-primary">{{ t('admin.trainingConfig.sections.examTitle') }}</h3><p class="mt-1 text-sm text-muted">{{ t('admin.trainingConfig.sections.examDesc') }}</p></div>
|
|
</div>
|
|
<span class="inline-flex shrink-0 items-center gap-1.5 rounded-full bg-amber-50 px-3 py-1.5 text-xs font-semibold text-amber-700"><CheckCircle2 class="h-3.5 w-3.5" />{{ t('admin.trainingConfig.questionCount', { count: questionCount }) }}</span>
|
|
</div>
|
|
<div class="mb-4 rounded-xl border border-amber-200 bg-amber-50/60 p-4">
|
|
<div class="grid gap-3 md:grid-cols-[minmax(0,1fr)_auto] md:items-end">
|
|
<label class="label-field">{{ t('admin.trainingConfig.questionSource') }}<select v-model.number="questionSourceVersionId" class="select-field mt-2"><option :value="null">{{ t('admin.trainingConfig.selectQuestionSource') }}</option><option v-for="document in candidates.training_exam_documents" :key="document.id" :value="document.id">{{ document.file_name }} · v{{ document.version_no }}</option></select></label>
|
|
<button class="btn-primary btn-sm" type="button" :disabled="isParsingQuestions || !questionSourceVersionId" @click="parseQuestionBank"><FileQuestion class="h-4 w-4" />{{ isParsingQuestions ? t('admin.trainingConfig.parsingQuestions') : t('admin.trainingConfig.parseQuestions') }}</button>
|
|
</div>
|
|
<p class="mt-2 text-xs text-muted">{{ t('admin.trainingConfig.questionSourceHint') }}</p>
|
|
<p v-if="questionParseMeta" class="mt-2 text-xs text-emerald-700">{{ t('admin.trainingConfig.parseStatus', { fileName: questionParseMeta.fileName, mode: questionParseMeta.mode }) }}<span v-if="questionParseMeta.skipped.length">{{ t('admin.trainingConfig.parseSkipped', { numbers: questionParseMeta.skipped.join(', ') }) }}</span></p>
|
|
</div>
|
|
<label class="label-field">{{ t('admin.trainingConfig.questionJson') }}<textarea v-model="questionJsonText" class="input-field mt-2 min-h-64 font-mono text-xs leading-5" spellcheck="false" /></label>
|
|
<p class="mt-2 text-xs text-muted">{{ t('admin.trainingConfig.questionJsonHint') }}</p>
|
|
</section>
|
|
|
|
<section id="training-section-review" 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"><ClipboardCheck class="h-5 w-5" /></span>
|
|
<div><h3 class="text-base font-bold text-primary">{{ t('admin.trainingConfig.sections.reviewTitle') }}</h3><p class="mt-1 text-sm text-muted">{{ t('admin.trainingConfig.sections.reviewDesc') }}</p></div>
|
|
</div>
|
|
|
|
<template v-if="form.training_type === 'safety'">
|
|
<div class="mb-5 text-sm font-semibold text-primary">分级培训总结 (按行分隔)</div>
|
|
<div class="grid gap-5 md:grid-cols-3 mb-8">
|
|
<label class="label-field"><span class="flex items-center gap-2"><BookOpen class="h-4 w-4 text-emerald-500" />公司级总结</span><textarea :value="settingSummaryByStageText('company')" class="input-field mt-2 min-h-32" :placeholder="t('admin.trainingConfig.placeholders.onePerLine')" @input="updateSettingSummaryByStageText('company', ($event.target as HTMLTextAreaElement).value)" /></label>
|
|
<label class="label-field"><span class="flex items-center gap-2"><BookOpen class="h-4 w-4 text-blue-500" />部门级总结</span><textarea :value="settingSummaryByStageText('department')" class="input-field mt-2 min-h-32" :placeholder="t('admin.trainingConfig.placeholders.onePerLine')" @input="updateSettingSummaryByStageText('department', ($event.target as HTMLTextAreaElement).value)" /></label>
|
|
<label class="label-field"><span class="flex items-center gap-2"><BookOpen class="h-4 w-4 text-orange-500" />班组级总结</span><textarea :value="settingSummaryByStageText('team')" class="input-field mt-2 min-h-32" :placeholder="t('admin.trainingConfig.placeholders.onePerLine')" @input="updateSettingSummaryByStageText('team', ($event.target as HTMLTextAreaElement).value)" /></label>
|
|
</div>
|
|
</template>
|
|
|
|
<div class="grid gap-5 md:grid-cols-2">
|
|
<label v-if="form.training_type !== 'safety'" class="label-field"><span class="flex items-center gap-2"><BookOpen class="h-4 w-4 text-brand-500" />{{ t('admin.trainingConfig.fields.summaryPoints') }}</span><textarea :value="settingText('summary_points')" class="input-field mt-2 min-h-32" :placeholder="t('admin.trainingConfig.placeholders.onePerLine')" @input="updateSettingText('summary_points', ($event.target as HTMLTextAreaElement).value)" /></label>
|
|
<label v-if="form.training_type !== 'safety'" class="label-field"><span class="flex items-center gap-2"><ListChecks class="h-4 w-4 text-brand-500" />{{ t('admin.trainingConfig.fields.summaryChecklist') }}</span><textarea :value="settingText('summary_checklist')" class="input-field mt-2 min-h-32" :placeholder="t('admin.trainingConfig.placeholders.onePerLine')" @input="updateSettingText('summary_checklist', ($event.target as HTMLTextAreaElement).value)" /></label>
|
|
<label class="label-field"><span class="flex items-center gap-2"><FileQuestion class="h-4 w-4 text-brand-500" />{{ t('admin.trainingConfig.fields.employeeQuestions') }}</span><textarea :value="settingText('employee_chat_suggested_questions')" class="input-field mt-2 min-h-32" :placeholder="t('admin.trainingConfig.placeholders.oneQuestionPerLine')" @input="updateSettingText('employee_chat_suggested_questions', ($event.target as HTMLTextAreaElement).value)" /></label>
|
|
<label class="label-field"><span class="flex items-center gap-2"><FileQuestion class="h-4 w-4 text-brand-500" />{{ t('admin.trainingConfig.fields.hrQuestions') }}</span><textarea :value="settingText('hr_chat_suggested_questions')" class="input-field mt-2 min-h-32" :placeholder="t('admin.trainingConfig.placeholders.oneQuestionPerLine')" @input="updateSettingText('hr_chat_suggested_questions', ($event.target as HTMLTextAreaElement).value)" /></label>
|
|
</div>
|
|
</section>
|
|
|
|
<div class="h-16" />
|
|
</main>
|
|
<div v-else class="flex min-h-[520px] flex-col items-center justify-center rounded-xl border border-slate-200 bg-white text-slate-400 shadow-sm">
|
|
<Settings2 class="h-10 w-10" />
|
|
<p class="mt-4 text-sm">{{ t('admin.trainingConfig.selectHint') }}</p>
|
|
</div>
|
|
</div>
|
|
<div v-if="!isLoading && selected" class="fixed inset-x-0 bottom-0 z-20 border-t border-slate-200 bg-white/95 px-4 py-3 shadow-[0_-8px_24px_rgba(15,23,42,0.08)] backdrop-blur md:left-[var(--sidebar-width,0px)] md:px-8">
|
|
<div class="mx-auto flex max-w-[1440px] items-center justify-between gap-4">
|
|
<div class="hidden items-center gap-2 text-xs text-slate-500 sm:flex"><CheckCircle2 class="h-4 w-4 text-emerald-500" />{{ t('admin.trainingConfig.footerHint') }}</div>
|
|
<div class="ml-auto flex items-center gap-2">
|
|
<button class="btn-secondary btn-sm" type="button" @click="editType"><Edit class="h-4 w-4" />{{ t('admin.edit') }}</button>
|
|
<button class="btn-primary min-w-32" type="button" :disabled="isSaving" @click="saveConfig"><Save class="h-4 w-4" />{{ isSaving ? t('admin.trainingConfig.saving') : t('admin.save') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<TrainingTypeFormModal :visible="showTypeEditor" :editing="editingType" :form="typeForm" :is-saving="isSaving" @close="showTypeEditor = false" @save="saveType" />
|
|
<DeleteConfirmDialog v-model="showDeleteConfirm" :message="t('admin.trainingConfig.confirmDelete')" @confirm="deleteType" />
|
|
</section>
|
|
</template>
|