feat(培训课程相关调整):1.培训计划中的形式”线上/线下“与课程中的”线上/线下“独立字段!,培训计划中是指线上培训还是线下培训,课程中是指该课程是线上课还是线下课,两者不能共用相互独立!
deploy-hxtesting / build-and-deploy (push) Successful in 1m18s

2.创建课程时课程默认是”线上“,发布课程时必须要有课件!
3.课程管理中的课件上传预览下载交互样式,按维护”试题“交互样式风格来!列表中增加一列”试题“,列表中”试题“、”课件“按实际情况只展示”有/无“即可!
This commit is contained in:
runny committed 2026-11-25 10:23:10 +08:00
1 parent ea0524c445
commit 9950a28346
13 files changed
+769 -169

No files matched your search

+8
View File
@@ -474,6 +474,8 @@ export interface TrainingLibraryCourse {
creator_id?: string
/** 创建人姓名(联查 users 只读;导入/新增时落 creator_id 后带出) */
creator_name?: string
/** 关联题库数(联查只读;列表「试题」有/无展示) */
question_bank_count?: number
created_at?: string
updated_at?: string
}
@@ -526,6 +528,12 @@ export const attachCourseLibraryMaterialFromKb = (id: string, payload: { knowled
export const downloadCourseLibraryMaterial = (id: string) =>
getDown(`${base}/course-library/${enc(id)}/material/file`)
/** 移除课件原始文件/知识库挂接(名称登记保留;课件变更即回待核验)。 */
export const removeCourseLibraryMaterial = (id: string) =>
post<{ success: boolean; data: TrainingLibraryCourse }>(
`${base}/course-library/${enc(id)}/material/remove`,
)
export const listSessions = (query?: ListQuery) =>
get<{ success: boolean; data: TrainingCourseSession[] }>(`${base}/sessions`, { params: query })
+23 -3
View File
@@ -165,9 +165,9 @@ export const TRAINING_MOCK = {
// 课程管理(课程资产主数据):预览 harness 演示数据(编号 CRS-#### 与后端一致)
const COURSE_LIBRARY_MOCK = [
{ id: 'lib-1', code: 'CRS-0001', name: '新员工入职通识培训', owner_dept_id: 'dept-b', owner_dept_name: '技术部', description: '公司制度、企业文化与办公系统入门', suitable_members: '新入职员工', category: '企业文化与制度类', type: 'required', mode: 'online', lecturer_id: 'u-m1', hours: 2, material_name: '入职通识手册.pptx', file_name: '', file_size: 0, lecturer_name: '', created_at: month(-3, 1), updated_at: month(0, 2) },
{ id: 'lib-2', code: 'CRS-0002', name: '冲压设备安全操作实操', owner_dept_id: 'dept-a', owner_dept_name: '冲压车间', description: '冲压机安全操作与应急处置实操训练', suitable_members: '冲压操作员', category: '安全与健康类', type: 'required', mode: 'offline', lecturer_id: 'u-m2', hours: 4, material_name: '安全操作规程.docx、实操考核表.xlsx', file_name: '', file_size: 0, lecturer_name: '', created_at: month(-2, 5), updated_at: month(-1, 8) },
{ id: 'lib-3', code: 'CRS-0003', name: 'TS16949 质量体系知识', owner_dept_id: '', owner_dept_name: '', description: 'IATF 16949 体系条款与内审要点', suitable_members: '品质岗', category: '专业技能类', type: 'elective', mode: 'online', lecturer_id: '', lecturer_external: '王顾问', hours: 3, material_name: '', file_name: '', file_size: 0, lecturer_name: '', created_at: month(-1, 12), updated_at: month(-1, 12) },
{ id: 'lib-1', code: 'CRS-0001', name: '新员工入职通识培训', owner_dept_id: 'dept-b', owner_dept_name: '技术部', description: '公司制度、企业文化与办公系统入门', suitable_members: '新入职员工', category: '企业文化与制度类', type: 'required', mode: 'online', lecturer_id: 'u-m1', hours: 2, material_name: '入职通识手册.pptx', file_name: '入职通识手册.pptx', file_size: 839680, knowledge_id: 'kb-lib1', question_bank_count: 1, verify_status: 'confirmed', publish_status: 'draft', lecturer_name: '', created_at: month(-3, 1), updated_at: month(0, 2) },
{ id: 'lib-2', code: 'CRS-0002', name: '冲压设备安全操作实操', owner_dept_id: 'dept-a', owner_dept_name: '冲压车间', description: '冲压机安全操作与应急处置实操训练', suitable_members: '冲压操作员', category: '安全与健康类', type: 'required', mode: 'offline', lecturer_id: 'u-m2', hours: 4, material_name: '安全操作规程.docx、实操考核表.xlsx', file_name: '安全操作规程.docx', file_size: 512000, question_bank_count: 1, verify_status: 'confirmed', publish_status: 'draft', lecturer_name: '', created_at: month(-2, 5), updated_at: month(-1, 8) },
{ id: 'lib-3', code: 'CRS-0003', name: 'TS16949 质量体系知识', owner_dept_id: '', owner_dept_name: '', description: 'IATF 16949 体系条款与内审要点', suitable_members: '品质岗', category: '专业技能类', type: 'elective', mode: 'online', lecturer_id: '', lecturer_external: '王顾问', hours: 3, material_name: '', file_name: '', file_size: 0, question_bank_count: 0, verify_status: 'confirmed', publish_status: 'draft', lecturer_name: '', created_at: month(-1, 12), updated_at: month(-1, 12) },
]
// 课程管理 · 试题管理(000153):题库与题目演示数据(编号 QB-####)
@@ -313,6 +313,26 @@ export function resolveTrainingMock(method: string, url: string): { status: numb
if (url.includes('/question-banks/') && url.includes('/questions')) {
return ok({ id: `q-new-${Date.now()}`, seq_no: 0 })
}
// 课件管理抽屉:上传/知识库挂接/移除回显对应课程条目并模拟文件字段变更
if (url.includes('/course-library/') && url.includes('/material/remove')) {
const course = COURSE_LIBRARY_MOCK.find((c) => url.includes(`/course-library/${c.id}/`))
if (course) {
course.file_name = ''
course.file_size = 0
course.knowledge_id = ''
course.verify_status = 'pending'
}
return ok(course || { id: `c-new-${Date.now()}` })
}
if (url.includes('/course-library/') && url.includes('/material')) {
const course = COURSE_LIBRARY_MOCK.find((c) => url.includes(`/course-library/${c.id}/`))
if (course) {
course.file_name = '预览课件.pdf'
course.file_size = 1024 * 820
course.verify_status = 'pending'
}
return ok(course || { id: `c-new-${Date.now()}` })
}
if (url.includes('/course-library/') && url.includes('/question-banks/import')) {
return ok({ id: `b-new-${Date.now()}`, code: `QB-${String(QUESTION_BANKS_MOCK.length + 1).padStart(4, '0')}`, name: '新导入题库', question_count: 5 })
}
@@ -98,6 +98,14 @@
</t-select>
<div class="bank-hint">选择后带出课程信息且不可修改,仅可调整下方授课安排;还没有课程?<a class="template-link" href="javascript:void(0)" @click.prevent="goLibrary">前往「课程管理」新增</a></div>
</t-form-item>
<t-form-item label="形式">
<!-- 计划「形式」独立字段(000162):指本次培训线上办还是线下办,与课程
主数据的线上课/线下课口径不同,不随所选课程带出,可在此切换 -->
<t-radio-group v-model="form.mode" variant="default-filled" size="small">
<t-radio-button value="offline">线下(集中授课)</t-radio-button>
<t-radio-button value="online">线上(自主学习)</t-radio-button>
</t-radio-group>
</t-form-item>
<t-form-item label="类型">
<t-input :value="formTypeDisplay" disabled />
</t-form-item>
@@ -202,8 +210,9 @@
<t-input :value="activeCourse?.plan_code || '-'" disabled />
</t-form-item>
<t-form-item label="课程名称">
<!-- 000161 可切换关联课程:改选即换 library_course_id,类型/形式随新课程带出;
讲师改动保存后回写课程管理并重置待核验,发布前须重新签核 -->
<!-- 000161 可切换关联课程:改选即换 library_course_id,名称/类型随新课程带出
(形式为计划侧独立字段,000162 起不随课程联动);讲师改动保存后回写
课程管理并重置待核验,发布前须重新签核 -->
<t-select
v-model="editForm.library_course_id"
:disabled="!canManage"
@@ -216,6 +225,13 @@
<t-option v-for="c in libraryCourses" :key="c.id" :value="c.id" :label="`${c.name}${c.category ? `(${c.category})` : ''}`" />
</t-select>
</t-form-item>
<t-form-item label="形式">
<!-- 计划「形式」独立字段(000162):可改线下/线上,不随所选课程带出 -->
<t-radio-group v-model="editForm.mode" variant="default-filled" size="small" :disabled="!canManage">
<t-radio-button value="offline">线下(集中授课)</t-radio-button>
<t-radio-button value="online">线上(自主学习)</t-radio-button>
</t-radio-group>
</t-form-item>
<t-form-item label="类型">
<t-input :value="formTypeDisplay" disabled />
</t-form-item>
@@ -873,12 +889,12 @@ const form = ref({
description: '',
})
// 从课程管理选择课程:带出课程信息(类型/形式/讲师/学时/所属部门/说明)并锁定,
// 计划侧仅维护授课安排(学时学分/时间/地点/通知/参加人员)
// 从课程管理选择课程:带出课程信息(名称/类型/讲师/学时/所属部门/说明)并锁定,
// 计划侧仅维护授课安排(学时学分/时间/地点/通知/参加人员);
// 「形式」为计划侧独立字段(000162),不随所选课程带出,由表单自行选择
const onLibraryCourseChange = (libraryCourseId: unknown) => {
const lc = libraryCourses.value.find((c) => c.id === libraryCourseId)
form.value.name = lc?.name || ''
form.value.mode = lc?.mode === 'online' ? 'online' : 'offline'
form.value.type = lc?.type === 'elective' ? 'elective' : 'required'
form.value.hours = lc?.hours || form.value.hours
form.value.lecturer_id = lc?.lecturer_id || ''
@@ -1294,12 +1310,11 @@ const openDetail = async (row: TrainingCourse) => {
}
}
// 详情弹窗(未关联课程管理的计划)选定课程:带出课程信息并锁定,
// 适用部门变化经 watcher 自动同步参加人员名单
// 详情弹窗(未关联课程管理的计划)选定课程:带出课程信息并锁定(形式除外,
// 000162 计划形式独立可改),适用部门变化经 watcher 自动同步参加人员名单
const onDetailLibraryCourseChange = (libraryCourseId: unknown) => {
const lc = libraryCourses.value.find((c) => c.id === libraryCourseId)
editForm.value.name = lc?.name || ''
editForm.value.mode = lc?.mode === 'online' ? 'online' : 'offline'
editForm.value.type = lc?.type === 'elective' ? 'elective' : 'required'
editForm.value.hours = lc?.hours || editForm.value.hours
editForm.value.lecturer_id = lc?.lecturer_id || ''
@@ -78,9 +78,14 @@
<span v-else>-</span>
</template>
<template #material="{ row }">
<span v-if="row.material_name" class="clamp-2" :title="row.material_name">{{ row.material_name }}</span>
<span v-else>-</span>
<t-tag v-if="row.file_name" theme="success" variant="light" size="small" class="material-file-tag">附件</t-tag>
<!-- 课件只展示有/无:有=已上传文件或已挂接知识库课件,点击直达课件管理抽屉 -->
<t-tag v-if="hasMaterial(row)" theme="success" variant="light" size="small" class="cell-link" @click="openMaterialDrawer(row)">有</t-tag>
<t-tag v-else theme="default" variant="light" size="small">无</t-tag>
</template>
<template #question="{ row }">
<!-- 试题只展示有/无:有=课程已关联题库,点击直达试题管理抽屉 -->
<t-tag v-if="(row.question_bank_count || 0) > 0" theme="success" variant="light" size="small" class="cell-link" @click="openQuestions(row)">有</t-tag>
<t-tag v-else theme="default" variant="light" size="small">无</t-tag>
</template>
<template #created_at="{ row }">{{ fmtBeijingTime(row.created_at) || '-' }}</template>
<!-- 创建人(联查 users):记录课程由谁录入 -->
@@ -99,6 +104,7 @@
</template>
<template #op="{ row }">
<t-button v-if="canEditCourse(row)" variant="text" theme="primary" size="small" @click="openForm(row)">编辑</t-button>
<t-button variant="text" size="small" @click="openMaterialDrawer(row)">课件</t-button>
<t-button variant="text" size="small" @click="openQuestions(row)">试题</t-button>
<t-popconfirm
v-if="canVerifyCourse(row)"
@@ -127,7 +133,6 @@
>
<t-button variant="text" theme="danger" size="small">删除</t-button>
</t-popconfirm>
<t-button v-if="row.file_name" variant="text" size="small" @click="onDownloadMaterial(row)">下载课件</t-button>
</template>
</t-table>
</div>
@@ -191,50 +196,8 @@
<t-form-item label="时长(学时)">
<t-input-number v-model="form.hours" :min="0" :step="0.5" style="width: 100%" />
</t-form-item>
<t-form-item label="课件">
<div class="material-field">
<t-input v-model="form.material_name" placeholder="课件名称登记,多个用、分隔(选填)" />
<div class="material-upload-row">
<input ref="materialInputRef" type="file" class="material-upload-input" @change="onMaterialFileChange" />
<t-button variant="outline" size="small" @click="materialInputRef?.click()">上传课件文件</t-button>
<t-button variant="outline" size="small" :loading="kbDocsLoading" @click="toggleKbDocSelect">从知识库选择</t-button>
<template v-if="pendingMaterialFile">
<span class="material-file-name">{{ pendingMaterialFile.name }}</span>
<t-button variant="text" size="small" @click="clearPendingMaterialFile">移除</t-button>
</template>
<template v-else-if="pendingKbDoc">
<span class="material-file-name">{{ pendingKbDoc.name }}</span>
<t-button variant="text" size="small" @click="clearPendingKbDoc">移除</t-button>
</template>
<template v-else-if="form.file_name && !form.clear_file">
<span class="material-file-name">{{ form.file_name }}</span>
<t-button variant="text" size="small" @click="form.clear_file = true">移除</t-button>
</template>
<span v-else class="material-placeholder">未选择课件(可选;上传文档自动同步知识库,也可从知识库选择已有课件)</span>
</div>
<!-- 知识库文档下拉:点击「从知识库选择」展开(数据源:企业培训(课件)) -->
<div v-if="kbSelectVisible" class="material-upload-row">
<t-select
v-model="pendingKbDocId"
filterable
clearable
:loading="kbDocsLoading"
placeholder="选择「企业培训(课件)」知识库中的课件文档"
style="flex: 1; min-width: 0"
size="small"
>
<t-option v-for="d in kbDocs" :key="d.id" :value="d.id" :label="d.file_name" />
</t-select>
<t-button theme="primary" size="small" :disabled="!pendingKbDocId" @click="confirmKbDoc">确定</t-button>
<t-button variant="text" size="small" @click="kbSelectVisible = false">收起</t-button>
</div>
<div v-if="kbSelectVisible" class="form-hint">
数据来源:知识库「{{ coursewareKbRef?.name || '企业培训(课件)' }}」共 {{ kbDocs.length }} 个文档;保存后与上传课件同口径(下载/月培训计划带出/AI 出题共用)。
</div>
</div>
</t-form-item>
</t-form>
<div class="form-hint">分类选项由配置中心「课程分类」维护,支持手动输入保存;讲师可为员工名册内人员或外部讲师;月培训计划「课程名称」将从本页课程中选择并自动带出此处维护的信息(不可修改);试题经列表「试题」入口维护。</div>
<div class="form-hint">分类选项由配置中心「课程分类」维护,支持手动输入保存;讲师可为员工名册内人员或外部讲师;月培训计划「课程名称」将从本页课程中选择并自动带出此处维护的信息(不可修改);课件上传/预览/下载经列表「课件」入口、试题经列表「试题」入口维护;发布课程前必须已上传课件。</div>
<template #footer>
<t-button variant="outline" @click="formVisible = false">取消</t-button>
<t-button theme="primary" :loading="saving" @click="onSave">保存</t-button>
@@ -258,6 +221,60 @@
</template>
</t-dialog>
<!-- 课件管理抽屉:上传/知识库选择/预览/下载/移除(交互与试题维护抽屉同风格) -->
<t-drawer
v-model:visible="materialVisible"
:header="`课件管理 · ${materialCourse?.name || ''}${materialCourse?.code ? `(${materialCourse.code})` : ''}`"
size="72%"
placement="right"
attach="body"
:z-index="2600"
:footer="false"
>
<div class="bank-toolbar">
<t-radio-group :value="materialSourceMode" variant="default-filled" size="small" @change="onMaterialModeChange">
<t-radio-button value="upload">上传课件</t-radio-button>
<t-radio-button value="kb">从知识库选择</t-radio-button>
</t-radio-group>
<template v-if="materialSourceMode === 'upload'">
<input ref="materialFileInputRef" type="file" class="bank-upload-input" @change="onMaterialPicked" />
<t-button variant="outline" size="small" @click="materialFileInputRef?.click()">选择文件</t-button>
<span v-if="materialFile" class="bank-file-name">{{ materialFile.name }}</span>
<span v-else class="bank-file-placeholder">未选择文件</span>
<t-button theme="primary" size="small" :loading="materialUploading" :disabled="!materialFile" @click="onUploadMaterial">上传并关联课件</t-button>
</template>
<template v-else>
<t-select
v-model="materialKbDocId"
filterable
clearable
:loading="kbDocsLoading"
placeholder="选择「企业培训(课件)」知识库中的课件文档"
style="width: 260px"
size="small"
>
<t-option v-for="d in kbDocs" :key="d.id" :value="d.id" :label="d.file_name" />
</t-select>
<t-button theme="primary" size="small" :loading="materialUploading" :disabled="!materialKbDocId" @click="onAttachMaterialKb">确定挂接</t-button>
</template>
</div>
<div class="form-hint">
数据来源:知识库「{{ coursewareKbRef?.name || '企业培训(课件)' }}」共 {{ kbDocs.length }} 个文档;课件变更后课程回「待核验」,重新核验后方可发布;文档类课件上传后自动同步知识库(月培训计划带出/AI 出题/对话问答共用);发布课程前必须已上传课件。
</div>
<t-table v-if="materialCourse" :data="materialRows" :columns="materialColumns" row-key="key" size="small">
<template #size="{ row }">{{ row.size ? fmtSize(row.size) : '-' }}</template>
<template #op>
<t-button variant="text" theme="primary" size="small" @click="onPreviewMaterial">预览</t-button>
<t-button variant="text" theme="primary" size="small" @click="onDownloadMaterial(materialCourse)">下载</t-button>
<t-popconfirm content="移除后课程回「待核验」,需重新上传课件方可发布,确定移除?" theme="danger" @confirm="onRemoveMaterial">
<t-button variant="text" theme="danger" size="small">移除</t-button>
</t-popconfirm>
</template>
</t-table>
<t-empty v-if="materialCourse && !hasMaterial(materialCourse)" description="暂无课件,可在上方上传文件或从知识库选择;发布课程前必须已上传课件" />
</t-drawer>
<!-- 试题管理抽屉:题库与试题随课程条目增删改查(上传 Excel/知识库导入/AI 出题) -->
<t-drawer
v-model:visible="questionsVisible"
@@ -506,6 +523,7 @@ import {
listQuestions,
offlineCourseLibraryItem,
publishCourseLibraryItem,
removeCourseLibraryMaterial,
saveCourseLibraryItem,
saveQuestion,
uploadCourseLibraryMaterial,
@@ -624,7 +642,9 @@ const columns = [
{ colKey: 'mode', title: '线上/线下', width: 92 },
{ colKey: 'lecturer', title: '讲师', width: 110 },
{ colKey: 'hours', title: '时长', width: 84 },
{ colKey: 'material', title: '课件', minWidth: 150 },
// 课件/试题只展示有/无:有=已上传课件或已关联题库,点击直达对应维护抽屉
{ colKey: 'material', title: '课件', width: 70 },
{ colKey: 'question', title: '试题', width: 70 },
// 发布状态(000154):已发布的课程进入培训中心「和信课程」目录
{ colKey: 'publish_status', title: '发布状态', width: 90 },
{ colKey: 'created_at', title: '创建时间', width: 140 },
@@ -665,7 +685,9 @@ const loadAll = async () => {
// ---- 新增/编辑 ----
const formVisible = ref(false)
// lecturer 表单值:id(名册内)/姓名(外部讲师,creatable 直接输入);保存时解析
// lecturer 表单值:id(名册内)/姓名(外部讲师,creatable 直接输入);保存时解析。
// material_name 为隐藏保留字段:课件维护移至「课件」抽屉后,编辑保存仍原值回传,
// 防止全量更新把名称登记误清(000162)。
const form = ref({
id: '',
code: '',
@@ -675,43 +697,19 @@ const form = ref({
suitable_members: '',
category: '',
type: 'required' as 'required' | 'elective',
mode: 'offline' as 'offline' | 'online',
// 新增默认「线上」(000162):线上课为常规形态;编辑随原值
mode: 'online' as 'offline' | 'online',
lecturer: '',
hours: 0,
material_name: '',
file_name: '',
clear_file: false,
})
// 待上传课件文件(保存成功后随行上传)
const materialInputRef = ref<HTMLInputElement | null>(null)
const pendingMaterialFile = ref<File | null>(null)
const onMaterialFileChange = (e: Event) => {
const input = e.target as HTMLInputElement
pendingMaterialFile.value = input.files?.[0] || null
input.value = ''
// 上传文件与知识库课件二选一:选择文件即清掉已选知识库文档
clearPendingKbDoc()
}
const clearPendingMaterialFile = () => {
pendingMaterialFile.value = null
if (materialInputRef.value) materialInputRef.value.value = ''
}
// ---- 从知识库选择课件(企业培训(课件)) ----
const kbSelectVisible = ref(false)
const pendingKbDocId = ref('')
const pendingKbDoc = ref<{ id: string; name: string } | null>(null)
// ---- 「企业培训(课件)」知识库文档(课件抽屉「从知识库选择」数据源) ----
const kbDocs = ref<{ id: string; file_name: string }[]>([])
const kbDocsLoading = ref(false)
const coursewareKbRef = ref<{ id: string; name: string } | null>(null)
let kbDocsLoaded = false
const toggleKbDocSelect = async () => {
kbSelectVisible.value = !kbSelectVisible.value
if (kbSelectVisible.value) await loadCoursewareKbDocs()
}
// 拉取「企业培训(课件)」知识库文档列表(惰性加载一次)
const loadCoursewareKbDocs = async () => {
if (kbDocsLoaded) return
@@ -739,24 +737,6 @@ const loadCoursewareKbDocs = async () => {
}
}
const confirmKbDoc = () => {
const doc = kbDocs.value.find((d) => d.id === pendingKbDocId.value)
if (!doc) {
MessagePlugin.warning('请先选择知识库课件文档')
return
}
pendingKbDoc.value = { id: doc.id, name: doc.file_name }
// 与上传文件互斥:选定知识库文档即清掉待上传文件与已有文件移除标记
clearPendingMaterialFile()
form.value.clear_file = false
kbSelectVisible.value = false
}
const clearPendingKbDoc = () => {
pendingKbDoc.value = null
pendingKbDocId.value = ''
}
// 讲师下拉选项:全体员工(id=平台用户 id,与课程/需求讲师字段口径一致);
// 编辑外部讲师(非 id 值)时追加临时选项避免回显裸文本丢失
const lecturerSelectOptions = computed(() => {
@@ -771,9 +751,6 @@ const lecturerSelectOptions = computed(() => {
})
const openForm = (row?: TrainingLibraryCourse) => {
clearPendingMaterialFile()
clearPendingKbDoc()
kbSelectVisible.value = false
form.value = {
id: row?.id || '',
code: row?.code || '',
@@ -785,12 +762,11 @@ const openForm = (row?: TrainingLibraryCourse) => {
suitable_members: row?.suitable_members || (row ? '' : myDeptName.value),
category: row?.category || '',
type: row?.type === 'elective' ? 'elective' : 'required',
mode: row?.mode === 'online' ? 'online' : 'offline',
// 新增默认「线上」(000162);编辑随原值
mode: row ? (row.mode === 'online' ? 'online' : 'offline') : 'online',
lecturer: row?.lecturer_id || row?.lecturer_external || '',
hours: row?.hours || 0,
material_name: row?.material_name || '',
file_name: row?.file_name || '',
clear_file: false,
}
// 适合人员多选回显(000159):落库串「、」join → 数组;新增默认本部门
suitableList.value = splitSuitable(form.value.suitable_members)
@@ -827,21 +803,10 @@ const onSave = async () => {
lecturer_id: lecturer.lecturer_id || undefined,
lecturer_external: lecturer.lecturer_external || undefined,
hours: form.value.hours,
// 隐藏保留字段:课件维护已移至「课件」抽屉,编辑保存原值回传防误清(000162)
material_name: form.value.material_name.trim(),
clear_file: form.value.clear_file || undefined,
})
const saved = unwrap(res)
// 待上传课件文件:条目已落库后随行上传(名称登记为空时后端以文件名兜底;
// 文档类自动同步知识库「企业培训(课件)」,支持 AI 对话与出题)
if (pendingMaterialFile.value && saved?.id) {
const fd = new FormData()
fd.append('file', pendingMaterialFile.value)
await uploadCourseLibraryMaterial(saved.id, fd)
}
// 从知识库选择的课件:保存后挂接知识库文档(与上传同步同口径)
if (pendingKbDoc.value && saved?.id) {
await attachCourseLibraryMaterialFromKb(saved.id, { knowledge_id: pendingKbDoc.value.id })
}
MessagePlugin.success(
form.value.id
? saved?.code
@@ -852,8 +817,6 @@ const onSave = async () => {
: '课程已创建,可在「月培训计划」中引用',
)
formVisible.value = false
clearPendingMaterialFile()
clearPendingKbDoc()
loadAll()
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '保存失败,请稍后重试'))
@@ -946,6 +909,11 @@ const onSetPublishStatus = async (row: TrainingLibraryCourse, status: 'published
MessagePlugin.warning('该课程尚未核验,请先由本部门课长/经理核验确认后再发布')
return
}
// 发布前置校验(000162):必须有课件(名称登记不算,后端兜底同样拦截)
if (status === 'published' && !hasMaterial(row)) {
MessagePlugin.warning('该课程尚未上传课件,请先在「课件」入口上传课件文件(或从知识库选择)后再发布')
return
}
try {
const updated = unwrap(
status === 'published' ? await publishCourseLibraryItem(row.id) : await offlineCourseLibraryItem(row.id),
@@ -964,7 +932,11 @@ const onSetPublishStatus = async (row: TrainingLibraryCourse, status: 'published
}
}
const onDownloadMaterial = async (row: TrainingLibraryCourse) => {
// 课件有无口径:已上传原始文件或已挂接知识库课件文档(名称登记不算,与发布校验同口径)
const hasMaterial = (row: TrainingLibraryCourse) => Boolean(row.file_name || row.knowledge_id)
const onDownloadMaterial = async (row: TrainingLibraryCourse | null) => {
if (!row) return
try {
// getDown 直接返回 Blob(trainingTemplates 同款消费方式)
const blob = await downloadCourseLibraryMaterial(row.id)
@@ -979,6 +951,142 @@ const onDownloadMaterial = async (row: TrainingLibraryCourse) => {
}
}
// ---------------------------------------------------------------------------
// 课件管理抽屉(000162):上传/知识库选择/预览/下载/移除,交互与试题抽屉同风格
// ---------------------------------------------------------------------------
const materialVisible = ref(false)
const materialCourse = ref<TrainingLibraryCourse | null>(null)
const materialUploading = ref(false)
type MaterialSourceMode = 'upload' | 'kb'
const materialSourceMode = ref<MaterialSourceMode>('upload')
const materialFileInputRef = ref<HTMLInputElement | null>(null)
const materialFile = ref<File | null>(null)
const materialKbDocId = ref('')
const materialColumns = [
{ colKey: 'name', title: '课件名称', minWidth: 220 },
{ colKey: 'size', title: '大小', width: 110 },
{ colKey: 'source', title: '来源', width: 130 },
{ colKey: 'op', title: '操作', width: 190 },
]
const fmtSize = (size: number) => {
if (size >= 1024 * 1024) return `${(size / 1024 / 1024).toFixed(1)} MB`
if (size >= 1024) return `${Math.round(size / 1024)} KB`
return `${size} B`
}
// 抽屉内课件信息行:与列表「有」口径一致(文件或知识库文档任一存在)
const materialRows = computed(() => {
const c = materialCourse.value
if (!c || !hasMaterial(c)) return []
return [
{
key: 'material',
name: c.file_name || c.material_name || '知识库课件文档',
size: c.file_size || 0,
source: c.file_name ? '本地上传文件' : '知识库文档',
},
]
})
// 列表行原位替换:课件变更回「待核验」等状态随接口响应同步到列表与抽屉
const replaceLibraryRow = (updated?: TrainingLibraryCourse | null) => {
if (!updated) return
const idx = items.value.findIndex((it) => it.id === updated.id)
if (idx >= 0) items.value.splice(idx, 1, updated)
if (materialCourse.value?.id === updated.id) materialCourse.value = updated
if (questionsCourse.value?.id === updated.id) questionsCourse.value = updated
}
const openMaterialDrawer = (row: TrainingLibraryCourse) => {
materialCourse.value = row
materialVisible.value = true
materialSourceMode.value = 'upload'
materialFile.value = null
materialKbDocId.value = ''
if (materialFileInputRef.value) materialFileInputRef.value.value = ''
}
const onMaterialModeChange = (mode: unknown) => {
materialSourceMode.value = mode as MaterialSourceMode
if (materialSourceMode.value === 'kb') void loadCoursewareKbDocs()
}
const onMaterialPicked = (e: Event) => {
const input = e.target as HTMLInputElement
materialFile.value = input.files?.[0] || null
}
const onUploadMaterial = async () => {
const course = materialCourse.value
const file = materialFile.value
if (!course || !file) return
materialUploading.value = true
try {
const fd = new FormData()
fd.append('file', file)
// 名称登记为空时后端以文件名兜底;文档类自动同步知识库「企业培训(课件)」
const updated = unwrap<TrainingLibraryCourse>(await uploadCourseLibraryMaterial(course.id, fd))
replaceLibraryRow(updated)
materialFile.value = null
if (materialFileInputRef.value) materialFileInputRef.value.value = ''
MessagePlugin.success(`课件「${updated?.file_name || file.name}」已上传;课程回「待核验」,核验后方可发布`)
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '课件上传失败'))
} finally {
materialUploading.value = false
}
}
const onAttachMaterialKb = async () => {
const course = materialCourse.value
const doc = kbDocs.value.find((d) => d.id === materialKbDocId.value)
if (!course || !doc) return
materialUploading.value = true
try {
const updated = unwrap<TrainingLibraryCourse>(
await attachCourseLibraryMaterialFromKb(course.id, { knowledge_id: doc.id }),
)
replaceLibraryRow(updated)
materialKbDocId.value = ''
MessagePlugin.success(`课件「${updated?.file_name || doc.file_name}」已挂接;课程回「待核验」,核验后方可发布`)
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '课件挂接失败'))
} finally {
materialUploading.value = false
}
}
// 预览:取回 Blob 后新开页签展示(文件端点对安全类型 inline,浏览器按类型渲染;
// 不可预览类型浏览器按附件处理,回退下载)
const onPreviewMaterial = async () => {
const course = materialCourse.value
if (!course) return
try {
const blob = await downloadCourseLibraryMaterial(course.id)
const url = URL.createObjectURL(blob)
window.open(url, '_blank')
// 延迟回收对象 URL,留足新页签加载时间
setTimeout(() => URL.revokeObjectURL(url), 60_000)
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '课件预览失败'))
}
}
const onRemoveMaterial = async () => {
const course = materialCourse.value
if (!course) return
try {
const updated = unwrap<TrainingLibraryCourse>(await removeCourseLibraryMaterial(course.id))
replaceLibraryRow(updated)
MessagePlugin.success('课件已移除;课程回「待核验」,需重新上传课件后方可发布')
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '课件移除失败'))
}
}
// ---- 导出(当前筛选结果,列口径与模板一致) ----
const onExport = async () => {
@@ -1196,6 +1304,10 @@ const loadBanks = async () => {
try {
const res = await listLibraryCourseQuestionBanks(course.id)
banks.value = unwrap(res) || []
// 题库增删后同步列表「试题」有/无计数(该端点即本课程全部题库)
course.question_bank_count = banks.value.length
const idx = items.value.findIndex((it) => it.id === course.id)
if (idx >= 0) items.value[idx].question_bank_count = banks.value.length
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '题库加载失败'))
} finally {
@@ -1380,7 +1492,7 @@ const onGenerateQuestions = async () => {
const course = questionsCourse.value
if (!course) return
if (!course.knowledge_id) {
MessagePlugin.warning('该课程课件未同步知识库,请先在课程表单中上传课件文档后再 AI 出题')
MessagePlugin.warning('该课程课件未同步知识库,请先在「课件」入口上传课件文档后再 AI 出题')
return
}
genLoading.value = true
@@ -1583,39 +1695,9 @@ onMounted(loadAll)
font-size: var(--app-text-sm);
}
// 课件字段:名称登记 + 文件上传行
.material-field {
width: 100%;
}
.material-upload-row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
margin-top: 8px;
}
.material-upload-input {
display: none;
}
.material-file-name {
max-width: 220px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--td-text-color-secondary);
font-size: var(--app-text-sm);
}
.material-placeholder {
color: var(--td-text-color-placeholder);
font-size: var(--app-text-sm);
}
.material-file-tag {
margin-left: 6px;
// 列表「有」标签可点击直达维护抽屉
.cell-link {
cursor: pointer;
}
// 批量导入弹窗:模板下载 + Excel 上传一行排布(与培训计划导入同款)