fix(课程管理):CourseCatalog.vue:删除客户端权限复算(服务端 scope=catalog 是唯一权威口径);目录加载失败时空态明确提示「课程目录加载失败…请联系管理员检查服务版本与数据库迁移」,不再静默显示“暂无课程”。
deploy-hxtesting / build-and-deploy (push) Successful in 1m13s

后端权限 SQL:部门命中增加部门名回退(调用方部门名与权限部门按 org_depts 反查同名即命中,仍是同部门,无越权)。
迁移 000164 增补存量回填:旧版本时代“已审核+已有课件”但停在待发布的课程自动补发布(新流程没有发布按钮,这批课不回填会永远卡住)。
前端 onPublish:授课时间/地点校验改为“课程级字段 或 场次排期值”任一存在即放行(新增 firstUsableSession,与列表列同一取值逻辑)。
后端 PublishCourse:同样在校验前以 FirstCourseSession(新增仓储方法,排期中优先)兜底,防止前端放过、后端仍拦截。
This commit is contained in:
runny committed 2026-11-26 11:38:46 +08:00
1 parent 6defb1f2c6
commit a448598df5
7 files changed
+112 -38

No files matched your search

@@ -99,7 +99,7 @@
<t-empty
v-if="!loading && !visibleCards.length"
class="catalog-empty"
:description="filter === 'mine' ? '暂无与我相关的课程' : '暂无已发布课程(课程管理发布后在此展示)'"
:description="emptyText"
/>
<!-- 共用分页(000163):课程卡片默认每页 15 条 -->
<TrainingPagination v-model:current="cardPage" v-model:page-size="cardPageSize" :total="cardTotal" />
@@ -265,37 +265,26 @@ const FILTERS = [
// 工作台进目录默认落在「我的培训」(与我相关的课优先展示)
const filter = ref<string>('mine')
const keyword = ref('')
// 和信课程目录加载失败标记:目录查询异常(如服务版本与数据库迁移不一致)时
// 空态给出明确提示,不再静默显示「暂无课程」误导排查方向
const catalogLoadFailed = ref(false)
// 目录空态文案:按页签与加载状态区分(加载失败时优先提示)
const emptyText = computed(() => {
if (filter.value !== 'mine' && filter.value !== 'exam' && catalogLoadFailed.value) {
return '课程目录加载失败,请刷新重试;若持续出现请联系管理员检查服务版本与数据库迁移'
}
return filter.value === 'mine' ? '暂无与我相关的课程' : '暂无已发布课程(课程管理发布后在此展示)'
})
// 目录页面向全体员工:仅展示已发布课程(草稿/待审在「培训课程」维护)
const publishedCourses = computed(() => courses.value.filter((c) => c.status === 'published'))
// 「和信课程」(000160):已发布 + 课程权限覆盖查看人。000163 权限口径:
// perm_dept_ids 含我的部门 id 或 perm_user_ids 含我的用户 id 即可见;perm 两列
// 为空的存量课程沿用适合人员老口径 —— 「全部」全员可见,000159 多部门口径按
// 「、」拆分(逗号/分号兼容归一)后与我的部门名成员匹配;未设置适合人员的
// 存量课程沿用原部门范围口径(所属部门为空 = 全员,否则须与我的部门一致)。
// 后端 scope=catalog 已按同口径过滤,此处保留客户端兜底。
const myDeptId = computed(() => myProfile.value?.dept_id || '')
const myDeptName = computed(() => (myProfile.value?.dept_name || '').trim())
const myPermUserId = computed(() => myProfile.value?.user_id || '')
const splitNames = (v: string) =>
(v || '').split(/[、,,;;]/).map((s) => s.trim()).filter(Boolean)
const inPermIds = (ids: string, want: string) =>
Boolean(want) && ids.split(',').map((s) => s.trim()).includes(want)
// 「和信课程」(000160):已发布课程目录。课程权限(000163)由后端 scope=catalog
// 按调用方部门/人员统一过滤,此处只保留发布状态过滤 —— 不再做客户端权限复算:
// 此前按我的档案部门/用户 id 复算,调用方档案缺部门(或 id 口径不一致)时会把
// 服务端已授权的课程误杀,表现为「审核通过后和信课程看不到」(2026-11-26 复测修复)。
const hexinCourses = computed<TrainingLibraryCourse[]>(() =>
libraryItems.value.filter((c) => {
if (c.publish_status !== 'published') return false
// 新口径(000163):perm 任一列非空按 id 精确匹配
if ((c.perm_dept_ids || '').trim() || (c.perm_user_ids || '').trim()) {
return inPermIds(c.perm_dept_ids || '', myDeptId.value) || inPermIds(c.perm_user_ids || '', myPermUserId.value)
}
// 存量老口径:suitable_members 文本 / 所属部门兜底
const suitableNames = splitNames(c.suitable_members || '')
if (suitableNames.length) {
return suitableNames.includes('全部') || (!!myDeptName.value && suitableNames.includes(myDeptName.value))
}
return !c.owner_dept_id || !myDeptId.value || c.owner_dept_id === myDeptId.value
}),
libraryItems.value.filter((c) => c.publish_status === 'published'),
)
const statsText = computed(() => {
@@ -595,6 +584,7 @@ watch([examRows, visibleCards, filter], () => {
const loadAll = async () => {
loading.value = true
catalogLoadFailed.value = false
try {
// 讲师/管理角色额外拉维护视角课程(纯讲师=自己名下含草稿;管理=全部,下方按讲师 id 过滤),
// 供「我的培训」展示我主讲(含未发布)课程与「待维护」统计;纯学员无此视角,跳过。
@@ -606,9 +596,14 @@ const loadAll = async () => {
listSessions({ year: 0, month: 0, scope: 'student' }).catch(() => null),
getMyProfile().catch(() => null),
needMaintainView ? listCourses({ page_size: 100 }).catch(() => null) : Promise.resolve(null),
// 和信课程目录(000160):scope=catalog —— 已发布 + 适合人员覆盖查看人
// (全部/本部门;未设置沿用部门范围口径),不按维护角色收窄,全体员工同源
listCourseLibrary({ page_size: 500, scope: 'catalog' }).catch(() => null),
// 和信课程目录(000160):scope=catalog —— 已发布 + 课程权限覆盖查看人
// (000163 部门/人员 id 精确匹配;存量课程沿用老口径),后端按权限过滤
listCourseLibrary({ page_size: 500, scope: 'catalog' }).catch(() => {
// 目录查询失败不再静默吞成「暂无课程」(此前服务版本与数据库迁移不一致
// 时表现为「审核通过后和信课程看不到」且无任何提示,2026-11-26 复测修复)
catalogLoadFailed.value = true
return null
}),
// 我的考试记录(000154)
listMyExamRecords().catch(() => null),
// 我经场次学员名单报名的课程 id(「我参加」判定;旧后端无此接口时回退空集)
@@ -1345,6 +1345,16 @@ const courseLocation = (row: TrainingCourse) => {
// 回退课程自身地点(来自需求确认同步落库的 course.location)
return nearest?.location || row.location || ''
}
// 最靠前的有效场次(带授课时间或地点):发布前置校验与列表展示同口径用
// (课程级授课时间/地点为空的存量草稿,场次已排期即视为已维护,2026-11-26)
const firstUsableSession = (row: TrainingCourse) => {
const list = courseSessions.value[row.id] || []
return (
list.find((s) => s.status === 'scheduled' && (s.start_at || s.location)) ||
list.find((s) => s.start_at || s.location) ||
null
)
}
// 授课时间展示:期望月份默认值(YYYY-MM)→「2026/11」;具体时间 → 北京时间无秒;线上课默认「长期」
const teachTimeText = (row: TrainingCourse) => {
if (row.mode === 'online') return row.teach_time ? teachTimeDisplay(row.teach_time) : '长期'
@@ -1582,11 +1592,15 @@ const onPublish = async (row: TrainingCourse) => {
MessagePlugin.warning(`「${row.name}」是线下计划,发布前需先在「调整」中指定讲师`)
return
}
if (!row.teach_time) {
// 授课时间/地点与列表展示同口径(场次排期优先,课程级字段兜底):存量草稿
// 课程级字段为空但场次已排期时不再误报「未设置」(2026-11-26 复测修复,
// 后端 PublishCourse 同口径兜底)
const session = firstUsableSession(row)
if (!row.teach_time && !session?.start_at) {
MessagePlugin.warning(`「${row.name}」是线下计划,发布前需先在「调整」中设置授课时间`)
return
}
if (!row.location) {
if (!courseLocation(row)) {
MessagePlugin.warning(`「${row.name}」是线下计划,发布前需先在「调整」中设置授课地点`)
return
}