feat(training): 课程管理新增核验状态流转与权限细化(000157)
deploy-hxtesting / build-and-deploy (push) Failing after 0s

核验状态(verify_status,迁移 000157):
- 新字段 pending 待核验(初始)/confirmed 已确认,附核验人/核验时间审计列,存量数据回填待核验
- 新增/导入/编辑(含重新上传课件)一律重置为待核验,原核验结论作废
- 发布前置校验:课程发布、月培训计划「发布/保存并发布」关联课程必须已确认,否则友好提示核验入口

核验/删除权限(仅本部门课长/经理):
- 新端点 POST /training/course-library/verify 单个/批量共用,越权/已确认行跳过不阻断
- 核验与删除严格按课长身份所在部门收窄,人事/讲师/学员/空间管理员均无跨部门操作权
- 删除仅限待核验状态(已确认课程不可删,须走核验流程)

列表数据范围与页签:
- 课程管理列表按角色注入过滤:人事/空间管理员全部,课长/经理本部门,讲师/学员仅「与我相关」(本人创建或本人授课)
- 课程管理页签对学员开放;无维护角色用户仅可编辑本人创建/授课课程(不可新增)

前端:
- 发布状态「草稿」文案改为「待发布」;新增「状态」列固定右侧置于操作列前
- 列表勾选 + 批量核验/批量删除(仅本部门待核验行提交);发布按钮前置核验校验未核验友好提示;按钮按角色/部门/状态动态显隐
This commit is contained in:
runny committed 2026-11-21 11:00:58 +08:00
1 parent 168057db78
commit 80deef9c53
13 files changed
+418 -21

No files matched your search

+12
View File
@@ -458,10 +458,18 @@ export interface TrainingLibraryCourse {
knowledge_id?: string
/** 发布状态(000154):draft 草稿/published 已发布/offline 已下线 */
publish_status?: string
/** 核验状态(000157):pending 待核验/confirmed 已确认;发布前必须已确认 */
verify_status?: string
/** 核验人(课长/经理用户 id,联查展示用;仅审计) */
confirmed_by?: string
/** 核验时间 */
confirmed_at?: string
/** 移除课件文件标记(保存时置 true 强制清空文件) */
clear_file?: boolean
/** 讲师姓名(联查 users 只读) */
lecturer_name?: string
/** 创建人用户 id(学员「与我相关」列表的编辑权限判断用) */
creator_id?: string
/** 创建人姓名(联查 users 只读;导入/新增时落 creator_id 后带出) */
creator_name?: string
created_at?: string
@@ -485,6 +493,10 @@ export const publishCourseLibraryItem = (id: string) =>
export const offlineCourseLibraryItem = (id: string) =>
post<{ success: boolean; data: TrainingLibraryCourse }>(`${base}/course-library/${enc(id)}/offline`)
/** 课程条目核验(000157,单个/批量共用):仅课长/经理限本部门;返回核验/跳过条数。 */
export const verifyCourseLibraryItems = (ids: string[]) =>
post<{ success: boolean; data: { verified: number; skipped: number } }>(`${base}/course-library/verify`, { ids })
/** 批量导入(前端解析 Excel 后逐行提交,与需求导入同口径;返回导入条数)。 */
export const importCourseLibrary = (items: Partial<TrainingLibraryCourse>[]) =>
post<{ success: boolean; data: { imported: number } }>(`${base}/course-library/import`, { items })
+3 -2
View File
@@ -51,8 +51,9 @@
<t-empty v-else class="training-empty" description="月培训计划仅课长/经理/人事/讲师可见,学员请前往培训中心课程目录" />
</template>
<template v-else-if="activeTab === 'library'">
<LibraryPanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
<t-empty v-else class="training-empty" description="课程管理仅课长/经理/人事/讲师可见" />
<!-- 课程管理全员可见(000157):数据范围与按钮权限按角色细分(人事全部/
课长经理本部门/讲师学员仅「与我相关」),细控在 LibraryPanel 与后端 -->
<LibraryPanel :roles="myRoles" :admin="isAdmin" />
</template>
<template v-else-if="activeTab === 'sign'">
<SignPanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
@@ -29,9 +29,22 @@
</t-select>
<t-button variant="text" theme="primary" size="small" @click="resetFilters">重置</t-button>
<span class="library-filter-count">共 {{ filteredItems.length }} 门</span>
<!-- 批量操作(000157):核验/删除均仅课长/经理限本部门,且仅待核验行可删 -->
<t-button
v-if="canVerify" variant="outline" theme="primary" size="small"
:disabled="!selectedKeys.length" :loading="batchSaving" @click="onBatchVerify"
>批量核验</t-button>
<t-button
v-if="canDelete" variant="outline" theme="danger" size="small"
:disabled="!selectedKeys.length" :loading="batchSaving" @click="onBatchDelete"
>批量删除</t-button>
<span v-if="selectedKeys.length" class="library-filter-count">已选 {{ selectedKeys.length }} 项</span>
</div>
<t-table :data="filteredItems" :columns="columns" row-key="id" size="small" :loading="loading">
<t-table
v-model:selected-row-keys="selectedKeys"
:data="filteredItems" :columns="columns" row-key="id" size="small" :loading="loading"
>
<template #code="{ row }">{{ row.code || '-' }}</template>
<template #name="{ row }"><span class="clamp-2">{{ row.name }}</span></template>
<template #description="{ row }">
@@ -78,9 +91,22 @@
variant="light" size="small"
>{{ publishStatusText(row.publish_status) }}</t-tag>
</template>
<!-- 核验状态(000157):新增/编辑后待核验,课长/经理核验确认后方可发布 -->
<template #verify_status="{ row }">
<t-tag :theme="row.verify_status === 'confirmed' ? 'success' : 'warning'" variant="light" size="small">
{{ row.verify_status === 'confirmed' ? '已确认' : '待核验' }}
</t-tag>
</template>
<template #op="{ row }">
<t-button v-if="canManage" variant="text" theme="primary" size="small" @click="openForm(row)">编辑</t-button>
<t-button v-if="canEditCourse(row)" variant="text" theme="primary" size="small" @click="openForm(row)">编辑</t-button>
<t-button variant="text" size="small" @click="openQuestions(row)">试题</t-button>
<t-popconfirm
v-if="canVerifyCourse(row)"
content="核验确认后该课程方可发布,确认核验通过?" theme="primary"
@confirm="onVerify(row)"
>
<t-button variant="text" theme="primary" size="small">核验</t-button>
</t-popconfirm>
<t-popconfirm
v-if="canManage && row.publish_status !== 'published'"
content="发布后该课程进入培训中心「和信课程」目录(本部门可见)。" theme="primary"
@@ -95,7 +121,10 @@
>
<t-button variant="text" theme="danger" size="small">下线</t-button>
</t-popconfirm>
<t-popconfirm v-if="canManage" content="确定删除该课程?已创建的月培训计划不受影响。" theme="danger" @confirm="onDelete(row)">
<t-popconfirm
v-if="canDeleteCourse(row)"
content="仅待核验状态的课程可删除,确定删除该课程?已创建的月培训计划不受影响。" theme="danger" @confirm="onDelete(row)"
>
<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>
@@ -470,6 +499,7 @@ import {
saveCourseLibraryItem,
saveQuestion,
uploadCourseLibraryMaterial,
verifyCourseLibraryItems,
type TrainingDept,
type TrainingLibraryCourse,
type TrainingMember,
@@ -479,7 +509,8 @@ import {
} from '@/api/training'
const props = defineProps<{ roles: string[]; admin?: boolean }>()
// 课程维护:人事/课长/讲师(roles 已按权限组展开,经理经课长继承自动命中)
// 课程维护(新增/编辑/发布/导入/导出):人事/课长/讲师(roles 已按权限组展开,
// 经理经课长继承自动命中)。人事无核验/删除权限(000157)。
const canManage = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'lecturer'))
const loading = ref(false)
@@ -492,6 +523,28 @@ const depts = ref<TrainingDept[]>([])
const configCategories = ref<string[]>([])
// 本人所在部门 id:新增课程「所属部门」默认当前登录用户所在部门(getMyProfile)
const myDeptId = ref('')
// 本人用户 id:学员「与我相关」课程的编辑权限判断(创建人/讲师为本人)
const myUserId = ref('')
// 核验/删除权限(000157):严格限「本部门课长/经理」——人事/空间管理员一律无
// 跨部门核验/删除权(roles 已按权限组展开,经理经课长继承自动命中 supervisor)。
const canVerify = computed(() => props.roles.includes('supervisor'))
const canDelete = canVerify
// 仅本部门「待核验」课程可核验/删除;与后端 callerVerifyDeptScope 同口径:
// 无部门身份或课程所属部门与本人不一致时一律不可操作。
const canVerifyCourse = (row: TrainingLibraryCourse) =>
canVerify.value &&
row.verify_status === 'pending' &&
Boolean(myDeptId.value) &&
Boolean(row.owner_dept_id) &&
row.owner_dept_id === myDeptId.value
const canDeleteCourse = canVerifyCourse
// 编辑权限:维护角色可编辑可见课程;无维护角色的学员仅可编辑「与我相关」课程
// (本人创建或本人授课,后端兜底校验同口径)
const canEditCourse = (row: TrainingLibraryCourse) =>
canManage.value ||
(Boolean(myUserId.value) && (row.creator_id === myUserId.value || row.lecturer_id === myUserId.value))
// ---- 查询条件(编号/名称/分类/类型/形式;列表全量加载,本地过滤) ----
const filters = ref({ keyword: '', category: '', type: '', mode: '' })
@@ -520,6 +573,8 @@ const filteredItems = computed(() => {
})
const columns = [
// 批量勾选列(000157):配合批量核验/批量删除
{ colKey: 'row-select', type: 'multiple', width: 44 },
// 左侧列不固定(000154):课程编号/课程名称随横向滚动,操作仍固定右侧
{ colKey: 'code', title: '课程编号', width: 105 },
{ colKey: 'name', title: '课程名称', width: 170 },
@@ -537,7 +592,9 @@ const columns = [
{ colKey: 'created_at', title: '创建时间', width: 140 },
// 创建人(联查 users):记录课程录入人员
{ colKey: 'creator_name', title: '创建人', width: 96 },
{ colKey: 'op', title: '操作', width: 280, fixed: 'right' },
// 核验状态(000157):固定右侧置于操作列前
{ colKey: 'verify_status', title: '状态', width: 90, fixed: 'right' },
{ colKey: 'op', title: '操作', width: 340, fixed: 'right' },
]
const lecturerText = (row: TrainingLibraryCourse) =>
@@ -558,7 +615,9 @@ const loadAll = async () => {
members.value = (m && unwrap(m)?.items) || []
depts.value = (d && unwrap(d)) || []
configCategories.value = cats
myDeptId.value = (me && unwrap(me)?.dept_id) || ''
const meBody = me && unwrap(me)
myDeptId.value = meBody?.dept_id || ''
myUserId.value = meBody?.user_id || ''
} finally {
loading.value = false
}
@@ -769,12 +828,80 @@ const onDelete = async (row: TrainingLibraryCourse) => {
}
}
// 发布状态展示文案(000154)
// ---- 核验(000157):待核验 → 已确认,单个/批量共用核验端点(仅课长/经理限本部门) ----
const selectedKeys = ref<string[]>([])
const batchSaving = ref(false)
const onVerify = async (row: TrainingLibraryCourse) => {
try {
await verifyCourseLibraryItems([row.id])
row.verify_status = 'confirmed'
MessagePlugin.success(`课程「${row.name}」已核验确认,可发布`)
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '核验失败'))
}
}
const onBatchVerify = async () => {
// 与后端口径一致:仅本部门待核验行提交,已确认/越权行直接跳过
const rows = filteredItems.value.filter(
(r) => selectedKeys.value.includes(r.id) && r.verify_status !== 'confirmed' && canVerifyCourse(r),
)
if (!rows.length) {
MessagePlugin.warning('请先勾选本部门待核验状态的课程')
return
}
batchSaving.value = true
try {
const { verified, skipped } = unwrap(await verifyCourseLibraryItems(rows.map((r) => r.id)))
MessagePlugin.success(`批量核验完成:成功 ${verified} 条${skipped ? `,跳过 ${skipped} 条` : ''}`)
selectedKeys.value = []
loadAll()
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '批量核验失败'))
} finally {
batchSaving.value = false
}
}
const onBatchDelete = async () => {
// 与后端口径一致:仅本部门待核验行提交(已确认/越权行跳过)
const rows = filteredItems.value.filter((r) => selectedKeys.value.includes(r.id) && canDeleteCourse(r))
if (!rows.length) {
MessagePlugin.warning('请先勾选本部门待核验状态的课程')
return
}
batchSaving.value = true
let ok = 0
let fail = 0
try {
for (const row of rows) {
try {
await deleteCourseLibraryItem(row.id)
ok += 1
} catch {
fail += 1
}
}
MessagePlugin.success(`批量删除完成:成功 ${ok} 条${fail ? `,失败 ${fail} 条` : ''}`)
selectedKeys.value = []
loadAll()
} finally {
batchSaving.value = false
}
}
// 发布状态展示文案(000154;000157 起草稿文案调整为「待发布」)
const publishStatusText = (status?: string) =>
({ published: '已发布', offline: '已下线', draft: '草稿' }[status || 'draft'] || '草稿')
({ published: '已发布', offline: '已下线', draft: '待发布' }[status || 'draft'] || '待发布')
// 发布/下线(000154):发布后进入培训中心「和信课程」目录,下线即从目录撤回
const onSetPublishStatus = async (row: TrainingLibraryCourse, status: 'published' | 'offline') => {
// 发布前置校验(000157):仅「已确认」课程可发布(后端兜底同样拦截)
if (status === 'published' && row.verify_status !== 'confirmed') {
MessagePlugin.warning('该课程尚未核验,请先由本部门课长/经理核验确认后再发布')
return
}
try {
const updated = unwrap(
status === 'published' ? await publishCourseLibraryItem(row.id) : await offlineCourseLibraryItem(row.id),