feat(优化):年培训计划:已确认行的删除按钮、勾选框、批量删除均仅超级管理员可见/可用;提示文案随角色变化
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s
课程管理:canDeleteCourse 超管不限状态/部门(已审核/已发布行可删,确认弹窗文案区分);批量删除按钮超管可见 月培训计划:已发布行的「删除」仅超管可见(普通维护角色仍只能删未发布计划),行内确认弹窗替代原 window.confirm,失败时透出后端文案 Training.vue:canManageTabs 加入 super_admin,纯超管(未兼其他角色)也能进入这三个页面执行删除
This commit is contained in:
1 parent
a448598df5
commit
2f1cda34da
19 files changed
+589
-278
No files matched your search
@@ -1250,22 +1250,28 @@ export const ROLE_DICT_RULE_KEY = 'role_dict'
|
||||
export const TRAINEE_LABEL = '学员'
|
||||
|
||||
/** 系统默认职称角色(与后端 DefaultRoleDict 一致;字典缺失/损坏时兜底)。
|
||||
* 角色体系 v2:学员(隐式)/课长/经理/人事/讲师;经理继承课长全部权限并叠加审批决策。 */
|
||||
* 角色体系 v2:学员(隐式)/课长/经理/人事/讲师;经理继承课长全部权限并叠加审批决策。
|
||||
* v2.1 增补超级管理员:不继承任何权限组,仅承载终态数据(已确认需求/已审核课程/
|
||||
* 已发布计划)的删除权,组织架构「设置角色」可分配。 */
|
||||
export const DEFAULT_ROLE_DICT: TrainingRoleDef[] = [
|
||||
{ key: 'hr', label: '人事', short: '人事', system: true },
|
||||
{ key: 'supervisor', label: '课长', short: '课长', system: true },
|
||||
{ key: 'lecturer', label: '讲师', short: '讲师', system: true },
|
||||
{ key: 'exec', label: '经理', short: '经理', system: true, inherits: ['supervisor'] },
|
||||
{ key: 'super_admin', label: '超级管理员', short: '超管', system: true },
|
||||
]
|
||||
|
||||
/** 存量角色别名:部门文员(clerk)已移除,按课长对待(与后端 LegacyRoleAlias 同构) */
|
||||
const LEGACY_ROLE_ALIAS: Record<string, string> = { clerk: 'supervisor' }
|
||||
|
||||
/** 角色体系 v2 升级判定:经理(exec)必须继承课长,否则视为旧字典(与后端 NeedsRoleDictUpgrade 同构) */
|
||||
/** 角色体系升级判定(与后端 NeedsRoleDictUpgrade 同构):
|
||||
* 经理(exec)未继承课长视为 v1 旧字典;v2 口径但缺 v2.1 增补的超级管理员
|
||||
* 同样需要读时升级补齐(存量租户免迁移)。 */
|
||||
export function needsRoleDictUpgrade(dict: TrainingRoleDef[]): boolean {
|
||||
const mgr = dict.find((r) => r.key === 'exec')
|
||||
if (!mgr) return true
|
||||
return !(mgr.inherits || []).includes('supervisor')
|
||||
if (!(mgr.inherits || []).includes('supervisor')) return true
|
||||
return !dict.some((r) => r.key === 'super_admin')
|
||||
}
|
||||
|
||||
/** v1 存量字典升级为 v2 视图(与后端 UpgradeRoleDictV2 同构,幂等):
|
||||
|
||||
@@ -21,14 +21,17 @@
|
||||
<span class="panel-box__title">部门</span>
|
||||
<t-button theme="primary" @click="openCreateDept">新增部门</t-button>
|
||||
</div>
|
||||
<t-table :data="pagedDepts" :columns="deptColumns" row-key="id" size="small">
|
||||
<template #op="{ row }">
|
||||
<div class="op-group">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onEditDept(row)">修改</t-button>
|
||||
<t-button variant="text" theme="danger" size="small" @click="onDeleteDept(row)">删除</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 表格滚动区:面板满屏,表头/分页固定,仅数据行滚动(height=100% 启用固定表头) -->
|
||||
<div class="table-scroll">
|
||||
<t-table :data="pagedDepts" :columns="deptColumns" row-key="id" size="small" height="100%">
|
||||
<template #op="{ row }">
|
||||
<div class="op-group">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onEditDept(row)">修改</t-button>
|
||||
<t-button variant="text" theme="danger" size="small" @click="onDeleteDept(row)">删除</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-table>
|
||||
</div>
|
||||
<!-- 共用分页(000164):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="deptPage" v-model:page-size="deptPageSize" :total="deptTotal" />
|
||||
</div>
|
||||
@@ -66,32 +69,35 @@
|
||||
<t-button theme="primary" @click="importVisible = true">批量导入</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<t-table :data="pagedEmployees" :columns="employeeColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #user_name="{ row }">
|
||||
<t-tooltip :content="employeeName(row)" :disabled="!employeeName(row)">
|
||||
<span class="employee-name">{{ employeeName(row) || '-' }}</span>
|
||||
</t-tooltip>
|
||||
</template>
|
||||
<template #dept_name="{ row }">{{ row.dept_name || '-' }}</template>
|
||||
<template #wecom_userid="{ row }">
|
||||
<span :class="row.wecom_userid ? '' : 'wecom-missing'">{{ row.wecom_userid || '未绑定' }}</span>
|
||||
</template>
|
||||
<template #roles="{ row }">
|
||||
<t-tag v-for="r in row.roles || []" :key="r" variant="light" size="small" class="role-tag">{{ roleText(r) }}</t-tag>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag v-if="row.status === 'active'" theme="success" variant="light" size="small">在职</t-tag>
|
||||
<t-tag v-else-if="row.status === 'inactive'" theme="danger" variant="light" size="small">离职</t-tag>
|
||||
<t-tag v-else theme="default" variant="light" size="small">{{ row.status || '-' }}</t-tag>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<div class="op-group">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onEditEmployee(row)">修改</t-button>
|
||||
<t-button v-if="canManage" variant="text" theme="primary" size="small" @click="openWecom(row)">企微账号</t-button>
|
||||
<t-button v-if="canManage" variant="text" theme="primary" size="small" @click="openRoles(row)">设置角色</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 表格滚动区:面板满屏,表头/分页固定,仅数据行滚动(height=100% 启用固定表头) -->
|
||||
<div class="table-scroll">
|
||||
<t-table :data="pagedEmployees" :columns="employeeColumns" row-key="id" size="small" height="100%" :loading="loading">
|
||||
<template #user_name="{ row }">
|
||||
<t-tooltip :content="employeeName(row)" :disabled="!employeeName(row)">
|
||||
<span class="employee-name">{{ employeeName(row) || '-' }}</span>
|
||||
</t-tooltip>
|
||||
</template>
|
||||
<template #dept_name="{ row }">{{ row.dept_name || '-' }}</template>
|
||||
<template #wecom_userid="{ row }">
|
||||
<span :class="row.wecom_userid ? '' : 'wecom-missing'">{{ row.wecom_userid || '未绑定' }}</span>
|
||||
</template>
|
||||
<template #roles="{ row }">
|
||||
<t-tag v-for="r in row.roles || []" :key="r" variant="light" size="small" class="role-tag">{{ roleText(r) }}</t-tag>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag v-if="row.status === 'active'" theme="success" variant="light" size="small">在职</t-tag>
|
||||
<t-tag v-else-if="row.status === 'inactive'" theme="danger" variant="light" size="small">离职</t-tag>
|
||||
<t-tag v-else theme="default" variant="light" size="small">{{ row.status || '-' }}</t-tag>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<div class="op-group">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onEditEmployee(row)">修改</t-button>
|
||||
<t-button v-if="canManage" variant="text" theme="primary" size="small" @click="openWecom(row)">企微账号</t-button>
|
||||
<t-button v-if="canManage" variant="text" theme="primary" size="small" @click="openRoles(row)">设置角色</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-table>
|
||||
</div>
|
||||
<!-- 共用分页(000164):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="employeePage" v-model:page-size="employeePageSize" :total="employeeTotal" />
|
||||
</div>
|
||||
@@ -854,15 +860,23 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
// 分栏:部门列收窄为固定宽度(000164,原 3fr 过宽且编码列留白明显),
|
||||
// 员工档案占剩余全部宽度;窄屏退化为单列
|
||||
// 员工档案占剩余全部宽度;窄屏退化为单列。
|
||||
// 满屏布局(000164 布局诉求):栅格占满页身剩余高度,两面板各自内部滚动 ——
|
||||
// 面板头(标题/操作/查找)/表头/分页固定,仅表格数据区滚动;窄屏单列回退整页滚动
|
||||
.org-layout {
|
||||
display: grid;
|
||||
grid-template-columns: 280px minmax(0, 1fr);
|
||||
// 满屏关键:行高锁定为容器高(grid 行默认 auto 会被内容撑开,面板 height:100%
|
||||
// 的百分比链随之失效,表头/分页固定就不生效了)
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
gap: 12px;
|
||||
align-items: start;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-rows: none;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
// 000164 栅格子项收敛:员工档案表格/工具行较宽,缺省 min-width 会把
|
||||
@@ -875,6 +889,31 @@ onMounted(() => {
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
|
||||
.org-layout & {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
// 面板头固定,表格滚动区撑满剩余高度(表格 height=100% 启用 TDesign 固定表头;
|
||||
// .t-table 根也要撑满 100%,否则百分比退化为内容高、表头固定不生效)
|
||||
.org-layout & > .table-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
> .t-table {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.org-layout & > .training-pagination {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
|
||||
@@ -124,11 +124,11 @@ const isAdmin = computed(() =>
|
||||
myRoles.value.some((r) => r === 'hr') ||
|
||||
authStore.hasRole('admin'))
|
||||
|
||||
// 培训管理页签(培训计划/培训课程/培训签到)门槛:课长/经理/人事/讲师
|
||||
// 培训管理页签(培训计划/培训课程/培训签到)门槛:课长/经理/人事/讲师/超级管理员
|
||||
// (myRoles 已按权限组展开,自定义角色继承系统角色后自动生效)。
|
||||
const canManageTabs = computed(() =>
|
||||
isAdmin.value ||
|
||||
myRoles.value.some((r) => ['hr', 'supervisor', 'exec', 'lecturer'].includes(r)))
|
||||
myRoles.value.some((r) => ['hr', 'supervisor', 'exec', 'lecturer', 'super_admin'].includes(r)))
|
||||
|
||||
// 配置中心门槛(000158):人事/空间管理员之外,经理职称角色同权查看与维护。
|
||||
const canManageConfig = computed(() =>
|
||||
|
||||
@@ -36,54 +36,64 @@
|
||||
<span class="course-filter-count">共 {{ filteredCourses.length }} 门</span>
|
||||
</div>
|
||||
|
||||
<t-table :data="pagedCourses" :columns="courseColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #plan_code="{ row }">{{ row.plan_code || '-' }}</template>
|
||||
<template #name="{ row }">
|
||||
<span class="course-name-link clamp-2" title="点击前往培训签到" @click="goSignTab(row)">{{ row.name }}</span>
|
||||
<!-- 课程已下线(000163):关联课程管理条目 offline 时标注(计划行保留,
|
||||
学习入口提示「该课程已下线」) -->
|
||||
<t-tag v-if="row.library_offline" theme="danger" variant="outline" size="small" class="offline-flag">课程已下线</t-tag>
|
||||
</template>
|
||||
<template #mode="{ row }">
|
||||
<t-tag :theme="row.mode === 'online' ? 'primary' : 'default'" variant="light" size="small" :class="{ 'course-tag-offline': row.mode !== 'online' }">
|
||||
{{ row.mode === 'online' ? '线上' : '线下' }}
|
||||
</t-tag>
|
||||
</template>
|
||||
<template #type="{ row }">{{ typeText(row.type) }}</template>
|
||||
<template #reporter="{ row }"><span class="clamp-2">{{ row.reporter_dept_name || '-' }}</span></template>
|
||||
<template #teachTime="{ row }"><span class="clamp-2">{{ teachTimeText(row) }}</span></template>
|
||||
<template #plannedTime="{ row }"><span class="clamp-2">{{ row.planned_time || '-' }}</span></template>
|
||||
<template #lecturer="{ row }">{{ lectNameMap[row.lecturer_id] || row.lecturer_name || row.lecturer_external || '-' }}</template>
|
||||
<template #location="{ row }"><span class="clamp-2">{{ courseLocation(row) || '-' }}</span></template>
|
||||
<template #expected="{ row }">{{ row.actual_count ?? 0 }}/{{ row.expected_count ?? 0 }} 人</template>
|
||||
<template #learnStatus="{ row }">
|
||||
<t-tag
|
||||
:theme="learnStatusTheme(row.learning_status)"
|
||||
variant="light" size="small" class="status-link"
|
||||
@click="goStudyStatus(row, 'learning')"
|
||||
>{{ learnStatusText(row.learning_status) }}</t-tag>
|
||||
</template>
|
||||
<template #examStatus="{ row }">
|
||||
<t-tag
|
||||
:theme="examStatusTheme(row.exam_status)"
|
||||
variant="light" size="small" class="status-link"
|
||||
@click="goStudyStatus(row, 'exam')"
|
||||
>{{ examStatusText(row.exam_status) }}</t-tag>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag :theme="statusTheme(row.status)" variant="light" size="small">{{ statusText(row.status) }}</t-tag>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<t-button
|
||||
v-if="canManage && row.status !== 'published'"
|
||||
variant="text" theme="primary" size="small" :disabled="saving"
|
||||
@click="onPublish(row)"
|
||||
>发布</t-button>
|
||||
<t-button variant="text" size="small" @click="openDetail(row)">调整</t-button>
|
||||
<t-button variant="text" size="small" @click="openChangeLogs(row)">记录</t-button>
|
||||
<t-button v-if="canManage" variant="text" theme="danger" size="small" @click="onDelete(row)">删除</t-button>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 表格滚动区:面板满屏,筛选/表头/分页固定,仅数据行滚动(height=100% 启用固定表头) -->
|
||||
<div class="table-scroll">
|
||||
<t-table :data="pagedCourses" :columns="courseColumns" row-key="id" size="small" height="100%" :loading="loading">
|
||||
<template #plan_code="{ row }">{{ row.plan_code || '-' }}</template>
|
||||
<template #name="{ row }">
|
||||
<span class="course-name-link clamp-2" title="点击前往培训签到" @click="goSignTab(row)">{{ row.name }}</span>
|
||||
<!-- 课程已下线(000163):关联课程管理条目 offline 时标注(计划行保留,
|
||||
学习入口提示「该课程已下线」) -->
|
||||
<t-tag v-if="row.library_offline" theme="danger" variant="outline" size="small" class="offline-flag">课程已下线</t-tag>
|
||||
</template>
|
||||
<template #mode="{ row }">
|
||||
<t-tag :theme="row.mode === 'online' ? 'primary' : 'default'" variant="light" size="small" :class="{ 'course-tag-offline': row.mode !== 'online' }">
|
||||
{{ row.mode === 'online' ? '线上' : '线下' }}
|
||||
</t-tag>
|
||||
</template>
|
||||
<template #type="{ row }">{{ typeText(row.type) }}</template>
|
||||
<template #reporter="{ row }"><span class="clamp-2">{{ row.reporter_dept_name || '-' }}</span></template>
|
||||
<template #teachTime="{ row }"><span class="clamp-2">{{ teachTimeText(row) }}</span></template>
|
||||
<template #plannedTime="{ row }"><span class="clamp-2">{{ row.planned_time || '-' }}</span></template>
|
||||
<template #lecturer="{ row }">{{ lectNameMap[row.lecturer_id] || row.lecturer_name || row.lecturer_external || '-' }}</template>
|
||||
<template #location="{ row }"><span class="clamp-2">{{ courseLocation(row) || '-' }}</span></template>
|
||||
<template #expected="{ row }">{{ row.actual_count ?? 0 }}/{{ row.expected_count ?? 0 }} 人</template>
|
||||
<template #learnStatus="{ row }">
|
||||
<t-tag
|
||||
:theme="learnStatusTheme(row.learning_status)"
|
||||
variant="light" size="small" class="status-link"
|
||||
@click="goStudyStatus(row, 'learning')"
|
||||
>{{ learnStatusText(row.learning_status) }}</t-tag>
|
||||
</template>
|
||||
<template #examStatus="{ row }">
|
||||
<t-tag
|
||||
:theme="examStatusTheme(row.exam_status)"
|
||||
variant="light" size="small" class="status-link"
|
||||
@click="goStudyStatus(row, 'exam')"
|
||||
>{{ examStatusText(row.exam_status) }}</t-tag>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag :theme="statusTheme(row.status)" variant="light" size="small">{{ statusText(row.status) }}</t-tag>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<t-button
|
||||
v-if="canManage && row.status !== 'published'"
|
||||
variant="text" theme="primary" size="small" :disabled="saving"
|
||||
@click="onPublish(row)"
|
||||
>发布</t-button>
|
||||
<t-button variant="text" size="small" @click="openDetail(row)">调整</t-button>
|
||||
<t-button variant="text" size="small" @click="openChangeLogs(row)">记录</t-button>
|
||||
<!-- 已发布计划仅超级管理员职称角色可删(后端 DeleteCourse 同口径兜底);
|
||||
普通维护角色仅可删未发布计划 -->
|
||||
<t-popconfirm
|
||||
v-if="isSuperAdmin || (canManage && row.status !== 'published')"
|
||||
content="确定删除该培训计划?" theme="danger" @confirm="onDelete(row)"
|
||||
>
|
||||
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
</div>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="coursePage" v-model:page-size="coursePageSize" :total="courseTotal" />
|
||||
</div>
|
||||
@@ -585,6 +595,9 @@ const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
// 课程维护:人事/课长/讲师(roles 已按权限组展开,经理经课长继承自动命中);
|
||||
// 纯讲师的课程列表范围由后端按 lecturer_id 强制收窄。
|
||||
const canManage = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'lecturer'))
|
||||
// 超级管理员职称角色(super_admin):已发布计划的终态删除权唯一入口
|
||||
// (roles 已按权限组展开,自定义角色继承「超级管理员」权限组后同样命中)
|
||||
const isSuperAdmin = computed(() => props.roles.includes('super_admin'))
|
||||
// 纯讲师视角隐藏「按讲师查询」筛选(列表已固定为自己的课程)
|
||||
const isLecturerOnly = computed(() => !canManage.value || (props.roles.includes('lecturer') && !props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'exec')))
|
||||
const router = useRouter()
|
||||
@@ -1619,13 +1632,13 @@ const onPublish = async (row: TrainingCourse) => {
|
||||
}
|
||||
|
||||
const onDelete = async (row: TrainingCourse) => {
|
||||
if (!window.confirm(`确认删除计划「${row.name}」?`)) return
|
||||
try {
|
||||
await deleteCourse(row.id)
|
||||
MessagePlugin.success('已删除')
|
||||
loadAll()
|
||||
} catch {
|
||||
MessagePlugin.error('删除失败')
|
||||
} catch (e: any) {
|
||||
// 已发布计划仅超级管理员可删,后端拦截时透出统一文案
|
||||
MessagePlugin.error(apiErrorMessage(e, '删除失败'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1914,6 +1927,12 @@ watch(() => route?.query?.courseId, openDetailFromRoute)
|
||||
.training-form-hints-below();
|
||||
}
|
||||
|
||||
// 满屏列表布局(000164):页头固定,面板占满页身剩余高度,
|
||||
// 筛选区/表头/分页固定,仅表格数据区滚动
|
||||
.course-panel {
|
||||
.training-fill-panel();
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
margin-top: 8px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
|
||||
@@ -46,97 +46,103 @@
|
||||
<span v-if="selectedKeys.length" class="library-filter-count">已选 {{ selectedKeys.length }} 项</span>
|
||||
</div>
|
||||
|
||||
<t-table
|
||||
v-model:selected-row-keys="selectedKeys"
|
||||
:data="pagedItems" :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 }">
|
||||
<t-tooltip v-if="row.description" :content="row.description">
|
||||
<span class="cell-ellipsis">{{ row.description }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #category="{ row }">
|
||||
<t-tag v-if="row.category" theme="primary" variant="light" size="small">{{ row.category }}</t-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #type="{ row }">
|
||||
<t-tag :theme="row.type === 'elective' ? 'default' : 'warning'" variant="light" size="small">
|
||||
{{ row.type === 'elective' ? '选修课' : '必修课' }}
|
||||
</t-tag>
|
||||
</template>
|
||||
<template #mode="{ row }">
|
||||
<t-tag :theme="row.mode === 'online' ? 'primary' : 'default'" variant="light" size="small">
|
||||
{{ row.mode === 'online' ? '线上' : '线下' }}
|
||||
</t-tag>
|
||||
</template>
|
||||
<template #lecturer="{ row }">{{ lecturerText(row) }}</template>
|
||||
<template #hours="{ row }">{{ row.hours ? `${row.hours} 学时` : '-' }}</template>
|
||||
<template #owner_dept="{ row }">
|
||||
<span v-if="row.owner_dept_name" class="cell-ellipsis" :title="row.owner_dept_name">{{ row.owner_dept_name }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #suitable_members="{ row }">
|
||||
<!-- 课程权限(000163,原「适合人员」):部门+人员展示文本 -->
|
||||
<span v-if="permissionText(row)" class="cell-ellipsis" :title="permissionText(row)">{{ permissionText(row) }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #material="{ row }">
|
||||
<!-- 课件只展示有/无:有=已上传文件或已挂接知识库课件,点击直达课件管理抽屉 -->
|
||||
<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):记录课程由谁录入 -->
|
||||
<template #creator_name="{ row }">{{ row.creator_name || '-' }}</template>
|
||||
<template #publish_status="{ row }">
|
||||
<t-tag
|
||||
:theme="row.publish_status === 'published' ? 'success' : row.publish_status === 'offline' ? 'default' : 'warning'"
|
||||
variant="light" size="small"
|
||||
>{{ publishStatusText(row.publish_status) }}</t-tag>
|
||||
</template>
|
||||
<!-- 审核状态(000157/000163):新增/编辑后待审核,课长/经理审核确认后
|
||||
即自动发布(无需再点发布) -->
|
||||
<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="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)"
|
||||
content="审核通过后将立即发布(权限范围内的部门和人员可在培训中心/培训计划中查看),确认审核通过?" theme="primary"
|
||||
@confirm="onVerify(row)"
|
||||
>
|
||||
<t-button variant="text" theme="primary" size="small">审核</t-button>
|
||||
</t-popconfirm>
|
||||
<!-- 下线(000163):下线后课程不能再被使用 —— 和信课程撤回、计划不可
|
||||
再选用、已建计划学习时提示「该课程已下线」;存量培训计划保留 -->
|
||||
<t-popconfirm
|
||||
v-if="canManage && row.publish_status === 'published'"
|
||||
content="下线后该课程不能再被使用:培训中心「和信课程」不再展示,培训计划不可再选用,已建计划学习时提示「该课程已下线」(已有培训计划不会消失)。确定下线?" theme="danger"
|
||||
@confirm="onSetPublishStatus(row, 'offline')"
|
||||
>
|
||||
<t-button variant="text" theme="danger" size="small">下线</t-button>
|
||||
</t-popconfirm>
|
||||
<!-- 表格滚动区:面板满屏,筛选/表头/分页固定,仅数据行滚动(height=100% 启用固定表头) -->
|
||||
<div class="table-scroll">
|
||||
<t-table
|
||||
v-model:selected-row-keys="selectedKeys"
|
||||
:data="pagedItems" :columns="columns" row-key="id" size="small" height="100%" :loading="loading"
|
||||
>
|
||||
<template #code="{ row }">{{ row.code || '-' }}</template>
|
||||
<template #name="{ row }"><span class="clamp-2">{{ row.name }}</span></template>
|
||||
<template #description="{ row }">
|
||||
<t-tooltip v-if="row.description" :content="row.description">
|
||||
<span class="cell-ellipsis">{{ row.description }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #category="{ row }">
|
||||
<t-tag v-if="row.category" theme="primary" variant="light" size="small">{{ row.category }}</t-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #type="{ row }">
|
||||
<t-tag :theme="row.type === 'elective' ? 'default' : 'warning'" variant="light" size="small">
|
||||
{{ row.type === 'elective' ? '选修课' : '必修课' }}
|
||||
</t-tag>
|
||||
</template>
|
||||
<template #mode="{ row }">
|
||||
<t-tag :theme="row.mode === 'online' ? 'primary' : 'default'" variant="light" size="small">
|
||||
{{ row.mode === 'online' ? '线上' : '线下' }}
|
||||
</t-tag>
|
||||
</template>
|
||||
<template #lecturer="{ row }">{{ lecturerText(row) }}</template>
|
||||
<template #hours="{ row }">{{ row.hours ? `${row.hours} 学时` : '-' }}</template>
|
||||
<template #owner_dept="{ row }">
|
||||
<span v-if="row.owner_dept_name" class="cell-ellipsis" :title="row.owner_dept_name">{{ row.owner_dept_name }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #suitable_members="{ row }">
|
||||
<!-- 课程权限(000163,原「适合人员」):部门+人员展示文本 -->
|
||||
<span v-if="permissionText(row)" class="cell-ellipsis" :title="permissionText(row)">{{ permissionText(row) }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #material="{ row }">
|
||||
<!-- 课件只展示有/无:有=已上传文件或已挂接知识库课件,点击直达课件管理抽屉 -->
|
||||
<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):记录课程由谁录入 -->
|
||||
<template #creator_name="{ row }">{{ row.creator_name || '-' }}</template>
|
||||
<template #publish_status="{ row }">
|
||||
<t-tag
|
||||
:theme="row.publish_status === 'published' ? 'success' : row.publish_status === 'offline' ? 'default' : 'warning'"
|
||||
variant="light" size="small"
|
||||
>{{ publishStatusText(row.publish_status) }}</t-tag>
|
||||
</template>
|
||||
<!-- 审核状态(000157/000163):新增/编辑后待审核,课长/经理审核确认后
|
||||
即自动发布(无需再点发布) -->
|
||||
<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="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)"
|
||||
content="审核通过后将立即发布(权限范围内的部门和人员可在培训中心/培训计划中查看),确认审核通过?" theme="primary"
|
||||
@confirm="onVerify(row)"
|
||||
>
|
||||
<t-button variant="text" theme="primary" size="small">审核</t-button>
|
||||
</t-popconfirm>
|
||||
<!-- 下线(000163):下线后课程不能再被使用 —— 和信课程撤回、计划不可
|
||||
再选用、已建计划学习时提示「该课程已下线」;存量培训计划保留 -->
|
||||
<t-popconfirm
|
||||
v-if="canManage && row.publish_status === 'published'"
|
||||
content="下线后该课程不能再被使用:培训中心「和信课程」不再展示,培训计划不可再选用,已建计划学习时提示「该课程已下线」(已有培训计划不会消失)。确定下线?" theme="danger"
|
||||
@confirm="onSetPublishStatus(row, 'offline')"
|
||||
>
|
||||
<t-button variant="text" theme="danger" size="small">下线</t-button>
|
||||
</t-popconfirm>
|
||||
<t-popconfirm
|
||||
v-if="canDeleteCourse(row)"
|
||||
content="仅待审核状态的课程可删除,确定删除该课程?已创建的月培训计划不受影响。" theme="danger" @confirm="onDelete(row)"
|
||||
:content="row.verify_status === 'pending'
|
||||
? '确定删除该课程?已创建的月培训计划不受影响。'
|
||||
: '该课程已审核,删除后已创建的月培训计划不受影响但课程不可恢复,确定删除?'"
|
||||
theme="danger" @confirm="onDelete(row)"
|
||||
>
|
||||
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
</div>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="itemPage" v-model:page-size="itemPageSize" :total="itemTotal" />
|
||||
</div>
|
||||
@@ -725,16 +731,19 @@ const hasPermSet = (row: TrainingLibraryCourse) =>
|
||||
// 审核/删除权限(000157):严格限「本部门课长/经理」——人事/空间管理员一律无
|
||||
// 跨部门审核/删除权(roles 已按权限组展开,经理经课长继承自动命中 supervisor)。
|
||||
const canVerify = computed(() => props.roles.includes('supervisor'))
|
||||
const canDelete = canVerify
|
||||
// 超级管理员职称角色(super_admin):终态数据删除权唯一入口,已审核/已发布课程
|
||||
// 与跨部门均可删(后端 DeleteCourseLibraryItem 同口径兜底);审核权不放宽
|
||||
const isSuperAdmin = computed(() => props.roles.includes('super_admin'))
|
||||
const canDelete = computed(() => canVerify.value || isSuperAdmin.value)
|
||||
// 仅本部门「待审核」课程可审核/删除;与后端 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 canDeleteCourse = (row: TrainingLibraryCourse) => isSuperAdmin.value || canVerifyCourse(row)
|
||||
|
||||
// 编辑权限:维护角色可编辑可见课程;无维护角色的学员仅可编辑「与我相关」课程
|
||||
// (本人创建或本人授课,后端兜底校验同口径)
|
||||
@@ -1057,10 +1066,11 @@ const onBatchVerify = async () => {
|
||||
}
|
||||
|
||||
const onBatchDelete = async () => {
|
||||
// 与后端口径一致:仅本部门待审核行提交(已审核/越权行跳过)
|
||||
// 与后端口径一致:普通角色仅本部门待审核行提交(已审核/越权行跳过);
|
||||
// 超级管理员不限状态/部门(canDeleteCourse 按角色过滤,终态行可整批删除)
|
||||
const rows = filteredItems.value.filter((r) => selectedKeys.value.includes(r.id) && canDeleteCourse(r))
|
||||
if (!rows.length) {
|
||||
MessagePlugin.warning('请先勾选本部门待审核状态的课程')
|
||||
MessagePlugin.warning(isSuperAdmin.value ? '请先勾选要删除的课程' : '请先勾选本部门待审核状态的课程')
|
||||
return
|
||||
}
|
||||
batchSaving.value = true
|
||||
@@ -1897,6 +1907,10 @@ onMounted(loadAll)
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
}
|
||||
|
||||
// 满屏列表布局(000164):页头固定,面板占满页身剩余高度,
|
||||
// 筛选区/表头/分页固定,仅表格数据区滚动
|
||||
.training-fill-panel();
|
||||
}
|
||||
|
||||
.library-filters {
|
||||
|
||||
@@ -41,49 +41,52 @@
|
||||
<t-button variant="outline" @click="onSearchDemands">查询</t-button>
|
||||
<t-button variant="outline" @click="onResetDemandSearch">重置</t-button>
|
||||
<t-button v-if="canConfirm" theme="primary" variant="outline" :disabled="!selectedDemandKeys.length" :loading="batchSaving" @click="onBatchConfirm">批量确认</t-button>
|
||||
<t-button v-if="canManage" theme="danger" variant="outline" :disabled="!selectedDemandKeys.length" :loading="batchSaving" @click="onBatchDelete">批量删除</t-button>
|
||||
<span class="demand-selected-hint">已选 {{ selectedDemandKeys.length }} 项(可批量确认/删除未确认需求)</span>
|
||||
<t-button v-if="canManage || isSuperAdmin" theme="danger" variant="outline" :disabled="!selectedDemandKeys.length" :loading="batchSaving" @click="onBatchDelete">批量删除</t-button>
|
||||
<span class="demand-selected-hint">已选 {{ selectedDemandKeys.length }} 项(可批量确认/删除未确认需求{{ isSuperAdmin ? ';超级管理员可删除已确认需求' : '' }})</span>
|
||||
</div>
|
||||
<t-table
|
||||
v-model:selected-row-keys="selectedDemandKeys"
|
||||
:data="pagedDemands"
|
||||
:columns="demandColumns"
|
||||
row-key="id"
|
||||
size="small"
|
||||
:loading="loading"
|
||||
>
|
||||
<template #dept_name="{ row }">{{ row.dept_name || '-' }}</template>
|
||||
<template #code="{ row }">
|
||||
<t-tooltip v-if="row.code" :content="row.code">
|
||||
<span class="cell-ellipsis">{{ row.code }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #lecturer_name="{ row }">{{ row.lecturer_name || '-' }}</template>
|
||||
<!-- 计划培训月份入库格式「YYYY-M」(如 2027-1),原样展示 -->
|
||||
<template #planned_time="{ row }">{{ row.planned_time || '-' }}</template>
|
||||
<template #location="{ row }">{{ row.location || '-' }}</template>
|
||||
<!-- 适合人员/备注可能很长:单行省略,悬停浮出全部内容 -->
|
||||
<template #post_scope="{ row }">
|
||||
<t-tooltip v-if="row.post_scope" :content="row.post_scope">
|
||||
<span class="cell-ellipsis">{{ row.post_scope }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #remark="{ row }">
|
||||
<t-tooltip v-if="row.remark" :content="row.remark">
|
||||
<span class="cell-ellipsis">{{ row.remark }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<!-- 创建人(提报人姓名)/创建时间:记录需求由谁何时录入 -->
|
||||
<template #submitter_name="{ row }">{{ row.submitter_name || '-' }}</template>
|
||||
<template #created_at="{ row }">{{ fmtBeijingTime(row.created_at) || '-' }}</template>
|
||||
<template #check_status="{ row }">
|
||||
<t-tag v-if="row.check_status === 'passed'" theme="success" variant="light" size="small">已确认</t-tag>
|
||||
<t-tag v-else-if="row.check_status === 'pending'" theme="warning" variant="light" size="small">待核验</t-tag>
|
||||
<t-tag v-else theme="default" variant="light" size="small">已修正</t-tag>
|
||||
</template>
|
||||
<!-- 表格滚动区:面板满屏,筛选/表头/分页固定,仅数据行滚动(height=100% 启用固定表头) -->
|
||||
<div class="table-scroll">
|
||||
<t-table
|
||||
v-model:selected-row-keys="selectedDemandKeys"
|
||||
:data="pagedDemands"
|
||||
:columns="demandColumns"
|
||||
row-key="id"
|
||||
size="small"
|
||||
height="100%"
|
||||
:loading="loading"
|
||||
>
|
||||
<template #dept_name="{ row }">{{ row.dept_name || '-' }}</template>
|
||||
<template #code="{ row }">
|
||||
<t-tooltip v-if="row.code" :content="row.code">
|
||||
<span class="cell-ellipsis">{{ row.code }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #lecturer_name="{ row }">{{ row.lecturer_name || '-' }}</template>
|
||||
<!-- 计划培训月份入库格式「YYYY-M」(如 2027-1),原样展示 -->
|
||||
<template #planned_time="{ row }">{{ row.planned_time || '-' }}</template>
|
||||
<template #location="{ row }">{{ row.location || '-' }}</template>
|
||||
<!-- 适合人员/备注可能很长:单行省略,悬停浮出全部内容 -->
|
||||
<template #post_scope="{ row }">
|
||||
<t-tooltip v-if="row.post_scope" :content="row.post_scope">
|
||||
<span class="cell-ellipsis">{{ row.post_scope }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template #remark="{ row }">
|
||||
<t-tooltip v-if="row.remark" :content="row.remark">
|
||||
<span class="cell-ellipsis">{{ row.remark }}</span>
|
||||
</t-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<!-- 创建人(提报人姓名)/创建时间:记录需求由谁何时录入 -->
|
||||
<template #submitter_name="{ row }">{{ row.submitter_name || '-' }}</template>
|
||||
<template #created_at="{ row }">{{ fmtBeijingTime(row.created_at) || '-' }}</template>
|
||||
<template #check_status="{ row }">
|
||||
<t-tag v-if="row.check_status === 'passed'" theme="success" variant="light" size="small">已确认</t-tag>
|
||||
<t-tag v-else-if="row.check_status === 'pending'" theme="warning" variant="light" size="small">待核验</t-tag>
|
||||
<t-tag v-else theme="default" variant="light" size="small">已修正</t-tag>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<template v-if="row.status !== 'confirmed'">
|
||||
<t-button
|
||||
@@ -97,8 +100,16 @@
|
||||
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
<!-- 已确认需求纳入年度排期,普通角色不可删;超级管理员职称角色放开终态删除 -->
|
||||
<t-popconfirm
|
||||
v-else-if="isSuperAdmin"
|
||||
content="该需求已确认,删除后不可恢复,确定删除?" theme="danger" @confirm="onDeleteDemand(row)"
|
||||
>
|
||||
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
</t-table>
|
||||
</div>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="demandPage" v-model:page-size="demandPageSize" :total="demandTotal" />
|
||||
</div>
|
||||
@@ -421,8 +432,14 @@ const deptDisplay = computed(() => {
|
||||
return myDeptName.value
|
||||
})
|
||||
|
||||
const demandColumns = [
|
||||
{ colKey: 'row-select', type: 'multiple', width: 44, disabled: ({ row }: { row: TrainingDemand }) => row.status === 'confirmed' },
|
||||
// 超级管理员职称角色(super_admin):终态数据(已确认需求等)删除权唯一入口;
|
||||
// roles 已按权限组展开,自定义角色继承「超级管理员」权限组后同样命中
|
||||
const isSuperAdmin = computed(() => props.roles.includes('super_admin'))
|
||||
|
||||
// 已确认行默认禁止勾选(批量确认/删除仅作用于未确认需求);超级管理员可勾选
|
||||
// 以批量删除,故勾选禁用按角色动态计算(computed 随 props.roles 就绪刷新)
|
||||
const demandColumns = computed(() => [
|
||||
{ colKey: 'row-select', type: 'multiple', width: 44, disabled: ({ row }: { row: TrainingDemand }) => row.status === 'confirmed' && !isSuperAdmin.value },
|
||||
// 年计划编号(AP-<year>-####,创建时由服务端生成)
|
||||
{ colKey: 'code', title: '编号', width: 130 },
|
||||
{ colKey: 'course_name', title: '课程名称' },
|
||||
@@ -439,7 +456,7 @@ const demandColumns = [
|
||||
// 状态/操作固定在列表右侧,横向滚动时始终可见
|
||||
{ colKey: 'check_status', title: '状态', width: 84, fixed: 'right' },
|
||||
{ colKey: 'op', title: '操作', width: 160, fixed: 'right' },
|
||||
]
|
||||
])
|
||||
|
||||
// 批量确认/删除(仅作用于未确认需求,已确认行不可勾选)
|
||||
const selectedDemandKeys = ref<string[]>([])
|
||||
@@ -482,9 +499,11 @@ const onBatchConfirm = async () => {
|
||||
}
|
||||
|
||||
const onBatchDelete = async () => {
|
||||
const rows = demands.value.filter((d) => selectedDemandKeys.value.includes(d.id) && d.status !== 'confirmed')
|
||||
// 勾选口径:未确认行全员可勾;已确认行仅超级管理员可勾(isSuperAdmin 放开勾选),
|
||||
// 后端按行校验终态删除权,越权行整批报错提示
|
||||
const rows = demands.value.filter((d) => selectedDemandKeys.value.includes(d.id))
|
||||
if (!rows.length) {
|
||||
MessagePlugin.warning('请先勾选未确认的需求')
|
||||
MessagePlugin.warning('请先勾选要删除的需求')
|
||||
return
|
||||
}
|
||||
batchSaving.value = true
|
||||
@@ -1043,6 +1062,12 @@ onMounted(() => {
|
||||
.training-form-hints-below();
|
||||
}
|
||||
|
||||
// 满屏列表布局(000164):页头固定,面板占满页身剩余高度,
|
||||
// 筛选区/表头/分页固定,仅表格数据区滚动
|
||||
.plan-panel {
|
||||
.training-fill-panel();
|
||||
}
|
||||
|
||||
// 已确认行不做整行置灰:t-table 行选择列 disabled 命中时会加 __row--disabled
|
||||
// 类(整行 text-color-disabled),业务上已确认行仅禁止勾选,文字保持正常色
|
||||
:deep(.t-table__row--disabled) {
|
||||
|
||||
@@ -1052,8 +1052,30 @@ watch(pushScene, () => loadPushLogs())
|
||||
display: none;
|
||||
}
|
||||
|
||||
// ---- tab 化布局:tab 内容区与 panel-box 间距 ----
|
||||
// ---- tab 化布局:页头与页签条固定,仅 tab 内容区滚动(000164 布局诉求) ----
|
||||
.rule-panel {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.rule-tabs {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:deep(.t-tabs__header) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:deep(.t-tabs__content) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
:deep(.t-tab-panel) {
|
||||
padding: 12px 0 0;
|
||||
}
|
||||
|
||||
@@ -124,6 +124,45 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 列表页满屏布局(年培训计划/月培训计划/课程管理):页头(标题)固定不动,
|
||||
// 面板占满页身剩余高度,内部「面板标题/筛选区/分页」固定,仅表格数据区滚动。
|
||||
// 约定:panel-box 收为 flex 列,表格外包一层 .table-scroll(flex:1 撑满剩余
|
||||
// 高度),表格传 height="100%" 启用 TDesign 固定表头(thead sticky + 数据行滚动)。
|
||||
.training-fill-panel() {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
> .panel-box {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
> .panel-box > .panel-box__header,
|
||||
> .panel-box > .panel-box__sub {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
> .panel-box > .table-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
// 满屏关键:TDesign 的 height="100%" 落在内部 .t-table__content 上,而其父级
|
||||
// .t-table 根默认 auto 高,百分比会退化为内容高(表头固定不生效);给根也撑满
|
||||
// 100% 形成确定高度链,数据区才会真正滚动
|
||||
> .t-table {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
> .panel-box > .training-pagination {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 内容卡片:对齐知识库 resource-card 规范(描边 + 8px 圆角 + 容器底色)
|
||||
.training-panel-box() {
|
||||
background: var(--td-bg-color-container);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// TestCourseLibraryPermissionCondBalanced 2026-11-26 复测根因:权限 SQL 括号不配平
|
||||
// (少一个右括号)导致 scope=catalog / PermFilter 查询整体 500
|
||||
// 「syntax error at end of input」,前端 catch 后和信课程恒为空。
|
||||
// 本测试锁定:生成 SQL 括号必须配平,占位符数量与参数数量必须一致。
|
||||
func TestCourseLibraryPermissionCondBalanced(t *testing.T) {
|
||||
q := &interfaces.TrainingListQuery{
|
||||
PermFilter: true,
|
||||
PermDeptID: "dept-1",
|
||||
PermUserID: "user-1",
|
||||
CatalogDeptID: "dept-1",
|
||||
CatalogDeptName: "资讯组",
|
||||
PermIncludeCreator: true,
|
||||
}
|
||||
cond, args := courseLibraryPermissionCond(q)
|
||||
opens := strings.Count(cond, "(")
|
||||
closes := strings.Count(cond, ")")
|
||||
if opens != closes {
|
||||
t.Fatalf("括号不配平: '('=%d ')'=%d\nSQL=%s", opens, closes, cond)
|
||||
}
|
||||
placeholders := strings.Count(cond, "?")
|
||||
if placeholders != len(args) {
|
||||
t.Fatalf("占位符(%d)与参数(%d)数量不一致\nSQL=%s", placeholders, len(args), cond)
|
||||
}
|
||||
t.Logf("OK opens=%d closes=%d placeholders=%d args=%d", opens, closes, placeholders, len(args))
|
||||
}
|
||||
@@ -31,7 +31,7 @@ const courseLibraryPermissionMatchSQL = "(tr_course_library.perm_dept_ids <> ''
|
||||
"tr_course_library.suitable_members = ? " +
|
||||
"OR (? <> '' AND ? = ANY(string_to_array(replace(replace(replace(replace(tr_course_library.suitable_members, ',', '、'), ',', '、'), ';', '、'), ';', '、'), '、'))) " +
|
||||
"OR (tr_course_library.suitable_members = '' AND (tr_course_library.owner_dept_id = '' " +
|
||||
"OR (? <> '' AND tr_course_library.owner_dept_id = ?))))"
|
||||
"OR (? <> '' AND tr_course_library.owner_dept_id = ?)))))"
|
||||
|
||||
// courseLibraryPermissionCond 组装课程权限匹配条件与参数(000163;handler 注入
|
||||
// 调用方部门 id/部门名/用户 id,PermIncludeCreator 时创建人/讲师放行)。
|
||||
|
||||
@@ -599,13 +599,14 @@ func (s *trainingService) ConfirmDemand(ctx context.Context, tenantID uint64, id
|
||||
}
|
||||
|
||||
// DeleteDemand soft-deletes one unconfirmed demand.
|
||||
// 状态「已确认」的需求不可删除,避免误删已纳入年度排期的口径。
|
||||
func (s *trainingService) DeleteDemand(ctx context.Context, tenantID uint64, id string) error {
|
||||
// 状态「已确认」的需求不可删除,避免误删已纳入年度排期的口径;仅超级管理员
|
||||
// (bySuperAdmin:super_admin 职称角色或空间 Owner 兜底)放开终态删除。
|
||||
func (s *trainingService) DeleteDemand(ctx context.Context, tenantID uint64, id string, bySuperAdmin bool) error {
|
||||
demand, err := s.repo.GetDemand(ctx, tenantID, id)
|
||||
if err != nil {
|
||||
return errors.NewNotFoundError("需求不存在")
|
||||
}
|
||||
if demand.Status == types.TrainingDemandConfirmed {
|
||||
if demand.Status == types.TrainingDemandConfirmed && !bySuperAdmin {
|
||||
return errors.NewBadRequestError("已确认的需求不可删除")
|
||||
}
|
||||
return s.repo.DeleteDemand(ctx, tenantID, id)
|
||||
|
||||
@@ -422,7 +422,16 @@ func courseTypeLabel(t string) string {
|
||||
}
|
||||
|
||||
// DeleteCourse soft-deletes one course.
|
||||
func (s *trainingService) DeleteCourse(ctx context.Context, tenantID uint64, id string) error {
|
||||
// 已发布计划不可普通删除(避免误删已排期/已通知的计划);仅超级管理员
|
||||
// (bySuperAdmin:super_admin 职称角色或空间 Owner 兜底)放开终态删除。
|
||||
func (s *trainingService) DeleteCourse(ctx context.Context, tenantID uint64, id string, bySuperAdmin bool) error {
|
||||
course, err := s.GetCourse(ctx, tenantID, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if course.Status == types.TrainingCoursePublished && !bySuperAdmin {
|
||||
return errors.NewBadRequestError("已发布的培训计划不可删除,仅超级管理员可删除")
|
||||
}
|
||||
return s.repo.DeleteCourse(ctx, tenantID, id)
|
||||
}
|
||||
|
||||
|
||||
@@ -202,14 +202,15 @@ func (s *trainingService) SaveCourseLibraryItem(ctx context.Context, tenantID ui
|
||||
|
||||
// DeleteCourseLibraryItem 软删课程管理条目(月培训计划已创建的历史计划不受影响)。
|
||||
// 000157 收紧:仅「待核验」状态可删(已确认课程须走核验流程,不可绕过);
|
||||
// deptScope 非空(课长/经理)时仅可删除本部门课程。
|
||||
func (s *trainingService) DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id, deptScope string) error {
|
||||
// deptScope 非空(课长/经理)时仅可删除本部门课程。bySuperAdmin(超级管理员
|
||||
// 职称角色/空间 Owner 兜底)放开终态:已审核/已发布课程与跨部门均可删。
|
||||
func (s *trainingService) DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id, deptScope string, bySuperAdmin bool) error {
|
||||
item, err := s.repo.GetCourseLibraryItem(ctx, tenantID, id)
|
||||
if err != nil || item == nil {
|
||||
return werrors.NewNotFoundError("课程不存在")
|
||||
}
|
||||
if item.VerifyStatus != types.CourseLibraryVerifyPending {
|
||||
return werrors.NewBadRequestError("仅待核验状态的课程可删除,已确认课程不可删除")
|
||||
if item.VerifyStatus != types.CourseLibraryVerifyPending && !bySuperAdmin {
|
||||
return werrors.NewBadRequestError("仅待审核状态的课程可删除,已审核课程仅超级管理员可删除")
|
||||
}
|
||||
if deptScope != "" && item.OwnerDeptID != deptScope {
|
||||
return werrors.NewForbiddenError("仅可删除本部门的课程")
|
||||
|
||||
@@ -145,6 +145,23 @@ func (h *Handler) requireRoles(c *gin.Context, allowed ...string) (ok bool) {
|
||||
return false
|
||||
}
|
||||
|
||||
// callerIsSuperAdmin 超级管理员判定:持有「超级管理员」职称角色(super_admin,
|
||||
// 配置中心可配、组织架构「设置角色」可分配)或空间 Owner 兜底;空间 Admin 不放行。
|
||||
// 已确认需求/已审核课程/已发布计划这类终态数据的删除仅对超级管理员开放,其余
|
||||
// 角色仍按原状态规则拦截,前端删除按钮同口径仅超级管理员可见。
|
||||
func (h *Handler) callerIsSuperAdmin(c *gin.Context) bool {
|
||||
if callerRole := types.TenantRoleFromContext(c.Request.Context()); callerRole.IsValid() &&
|
||||
callerRole == types.TenantRoleOwner {
|
||||
return true
|
||||
}
|
||||
member, err := h.svc.CurrentMember(c.Request.Context(), callerTenantID(c), callerUserID(c))
|
||||
if err != nil || member == nil {
|
||||
return false
|
||||
}
|
||||
roles := h.svc.ExpandTrainingRoles(c.Request.Context(), callerTenantID(c), member.TrainingRoleList())
|
||||
return types.HasTrainingRole(roles, types.TrainingRoleSuperAdmin)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 数据范围:课程/计划类列表按调用方职称角色收窄(权限模型 §数据范围)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -584,7 +601,9 @@ func (h *Handler) SaveDemand(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": demand})
|
||||
}
|
||||
|
||||
// DeleteDemand DELETE /training/demands/:id — 删除未确认需求。
|
||||
// DeleteDemand DELETE /training/demands/:id — 删除未确认需求;已确认需求仅
|
||||
// 超级管理员(职称角色 super_admin/空间 Owner 兜底)可删(前端行内删除按钮
|
||||
// 同口径仅超级管理员可见)。超级管理员删除时不再要求提报人/管理角色身份。
|
||||
func (h *Handler) DeleteDemand(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
demand, err := h.svc.GetDemand(ctx, callerTenantID(c), c.Param("id"))
|
||||
@@ -592,15 +611,16 @@ func (h *Handler) DeleteDemand(c *gin.Context) {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
if demand.Status == types.TrainingDemandConfirmed {
|
||||
_ = c.Error(errors.NewBadRequestError("已确认的需求不可删除"))
|
||||
bySuperAdmin := h.callerIsSuperAdmin(c)
|
||||
if demand.Status == types.TrainingDemandConfirmed && !bySuperAdmin {
|
||||
_ = c.Error(errors.NewBadRequestError("已确认的需求不可删除,仅超级管理员可删除"))
|
||||
return
|
||||
}
|
||||
if !h.callerCanMutateDemand(c, demand.SubmitterID) {
|
||||
if !bySuperAdmin && !h.callerCanMutateDemand(c, demand.SubmitterID) {
|
||||
_ = c.Error(errors.NewForbiddenError("仅提报人或培训管理角色可删除该需求"))
|
||||
return
|
||||
}
|
||||
if err := h.svc.DeleteDemand(ctx, callerTenantID(c), c.Param("id")); err != nil {
|
||||
if err := h.svc.DeleteDemand(ctx, callerTenantID(c), c.Param("id"), bySuperAdmin); err != nil {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
@@ -1373,13 +1393,16 @@ func (h *Handler) PublishCourse(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": published})
|
||||
}
|
||||
|
||||
// DeleteCourse DELETE /training/courses/:id
|
||||
// DeleteCourse DELETE /training/courses/:id — 已发布计划仅超级管理员(职称角色
|
||||
// super_admin/空间 Owner 兜底)可删,其余状态仍为人事/课长(服务层同口径兜底
|
||||
// 校验);超级管理员删除时不要求人事/课长身份。
|
||||
func (h *Handler) DeleteCourse(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
if !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
|
||||
bySuperAdmin := h.callerIsSuperAdmin(c)
|
||||
if !bySuperAdmin && !h.requireRoles(c, types.TrainingRoleHR, types.TrainingRoleSupervisor) {
|
||||
return
|
||||
}
|
||||
if err := h.svc.DeleteCourse(ctx, callerTenantID(c), c.Param("id")); err != nil {
|
||||
if err := h.svc.DeleteCourse(ctx, callerTenantID(c), c.Param("id"), bySuperAdmin); err != nil {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -209,17 +209,23 @@ func (h *Handler) canEditRelatedLibraryCourse(c *gin.Context, id string) bool {
|
||||
}
|
||||
|
||||
// DeleteCourseLibraryItem DELETE /training/course-library/:id — 删除
|
||||
// (000157:仅本部门课长/经理,仅待核验状态;人事/学员/空间管理员无删除权限)。
|
||||
// (000157:仅本部门课长/经理,仅待审核状态;人事/学员/空间管理员无删除权限。
|
||||
// 超级管理员[职称角色 super_admin/空间 Owner 兜底]放开终态:已审核/已发布
|
||||
// 课程与跨部门均可删,且不要求课长/经理身份)。
|
||||
func (h *Handler) DeleteCourseLibraryItem(c *gin.Context) {
|
||||
if !h.requireRoles(c, types.TrainingRoleSupervisor, types.TrainingRoleManager) {
|
||||
return
|
||||
bySuperAdmin := h.callerIsSuperAdmin(c)
|
||||
deptID := ""
|
||||
if !bySuperAdmin {
|
||||
if !h.requireRoles(c, types.TrainingRoleSupervisor, types.TrainingRoleManager) {
|
||||
return
|
||||
}
|
||||
var ok bool
|
||||
if deptID, ok = h.callerVerifyDeptScope(c); !ok {
|
||||
_ = c.Error(errors.NewForbiddenError("仅本部门课长/经理可删除课程"))
|
||||
return
|
||||
}
|
||||
}
|
||||
deptID, ok := h.callerVerifyDeptScope(c)
|
||||
if !ok {
|
||||
_ = c.Error(errors.NewForbiddenError("仅本部门课长/经理可删除课程"))
|
||||
return
|
||||
}
|
||||
if err := h.svc.DeleteCourseLibraryItem(c.Request.Context(), callerTenantID(c), c.Param("id"), deptID); err != nil {
|
||||
if err := h.svc.DeleteCourseLibraryItem(c.Request.Context(), callerTenantID(c), c.Param("id"), deptID, bySuperAdmin); err != nil {
|
||||
_ = c.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -336,7 +336,9 @@ type TrainingService interface {
|
||||
// ImportDemands 批量导入需求;返回导入行与自动新增的待核验课程数(000158)。
|
||||
ImportDemands(ctx context.Context, tenantID uint64, demands []*types.TrainingDemand, updaterID string) ([]*types.TrainingDemand, int, error)
|
||||
ConfirmDemand(ctx context.Context, tenantID uint64, id string, updaterID string) (*types.TrainingDemand, error)
|
||||
DeleteDemand(ctx context.Context, tenantID uint64, id string) error
|
||||
// DeleteDemand 删除需求;bySuperAdmin(超级管理员职称角色/空间 Owner 兜底)
|
||||
// 时已确认需求同样可删,其余角色仅未确认需求。
|
||||
DeleteDemand(ctx context.Context, tenantID uint64, id string, bySuperAdmin bool) error
|
||||
// ListLecturers/ListPosts 需求提报表单下拉数据源(讲师/岗位)。
|
||||
ListLecturers(ctx context.Context, tenantID uint64) ([]*types.TrainingLecturerOption, error)
|
||||
ListPosts(ctx context.Context, tenantID uint64) ([]string, error)
|
||||
@@ -356,7 +358,9 @@ type TrainingService interface {
|
||||
ListCourses(ctx context.Context, tenantID uint64, q *TrainingListQuery) ([]*types.TrainingCourse, int64, error)
|
||||
GetCourse(ctx context.Context, tenantID uint64, id string) (*types.TrainingCourse, error)
|
||||
SaveCourse(ctx context.Context, tenantID uint64, course *types.TrainingCourse, updaterID string) (*types.TrainingCourse, error)
|
||||
DeleteCourse(ctx context.Context, tenantID uint64, id string) error
|
||||
// DeleteCourse 删除培训计划;bySuperAdmin(超级管理员职称角色/空间 Owner 兜底)
|
||||
// 时已发布计划同样可删,其余角色仅未发布计划。
|
||||
DeleteCourse(ctx context.Context, tenantID uint64, id string, bySuperAdmin bool) error
|
||||
PublishCourse(ctx context.Context, tenantID uint64, id, updaterID string) (*types.TrainingCourse, error)
|
||||
// ListCourseChangeLogs 课程信息修改版本记录(每次保存一条,变更明细可回溯)。
|
||||
ListCourseChangeLogs(ctx context.Context, tenantID uint64, courseID string) ([]*types.TrainingCourseChangeLog, error)
|
||||
@@ -374,9 +378,10 @@ type TrainingService interface {
|
||||
VerifyCourseLibraryItems(ctx context.Context, tenantID uint64, ids []string, verifierID, deptScope string) (*CourseLibraryVerifyResult, error)
|
||||
// GetCourseLibraryItem 取单条课程条目(发布/下线后回显)。
|
||||
GetCourseLibraryItem(ctx context.Context, tenantID uint64, id string) (*types.TrainingCourseLibrary, error)
|
||||
// DeleteCourseLibraryItem 软删课程条目(仅待核验状态可删;deptScope 非空时
|
||||
// 校验所属部门匹配,000157 仅课长/经理限本部门)。
|
||||
DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id, deptScope string) error
|
||||
// DeleteCourseLibraryItem 软删课程条目(仅待审核状态可删;deptScope 非空时
|
||||
// 校验所属部门匹配,000157 仅课长/经理限本部门;bySuperAdmin 超级管理员
|
||||
// 职称角色/空间 Owner 兜底时已审核/已发布课程与跨部门均放行)。
|
||||
DeleteCourseLibraryItem(ctx context.Context, tenantID uint64, id, deptScope string, bySuperAdmin bool) error
|
||||
// ImportCourseLibraryItems 批量导入(前端解析 Excel 后按行提交)。
|
||||
ImportCourseLibraryItems(ctx context.Context, tenantID uint64, items []*types.TrainingCourseLibrary, updaterID string) (int, error)
|
||||
// ExportCourseLibrary 导出 Excel(excelize;ids 空 = 全量)。
|
||||
|
||||
@@ -30,6 +30,10 @@ const (
|
||||
// TrainingRoleManager 经理(课长全部权限 + 审批决策 + 管理驾驶舱 + 讲师结算)。
|
||||
// 历史沿革:该角色前身是「高管(驾驶舱)」,key 保持 "exec" 不变以兼容存量数据。
|
||||
TrainingRoleManager TrainingRole = "exec"
|
||||
// TrainingRoleSuperAdmin 超级管理员(终态数据删除权):已确认需求/已审核课程/
|
||||
// 已发布计划这类终态数据仅该职称角色(及空间 Owner 兜底)可删,其余权限不做
|
||||
// 放宽——删除权单独收敛,不随人事/课长默认携带。
|
||||
TrainingRoleSuperAdmin TrainingRole = "super_admin"
|
||||
)
|
||||
|
||||
// legacyRoleClerk 部门文员(已移除的系统角色)。存量成员/自定义角色可能仍携带,
|
||||
@@ -66,12 +70,14 @@ func SystemTrainingRoles() []string {
|
||||
return []string{
|
||||
TrainingRoleHR, TrainingRoleSupervisor,
|
||||
TrainingRoleLecturer, TrainingRoleManager,
|
||||
TrainingRoleSuperAdmin,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultRoleDict 系统默认职称角色(与 defaultRuleSeed 的 role_dict 一致)。
|
||||
// 角色体系 v2:学员(隐式)/课长/经理/人事/讲师;经理继承课长全部权限并叠加
|
||||
// 审批决策、管理驾驶舱与讲师结算。
|
||||
// 审批决策、管理驾驶舱与讲师结算。超级管理员不继承任何权限组,仅承载终态
|
||||
// 数据(已确认需求/已审核课程/已发布计划)的删除权。
|
||||
func DefaultRoleDict() []TrainingRoleDef {
|
||||
return []TrainingRoleDef{
|
||||
{Key: TrainingRoleHR, Label: "人事", Short: "人事", System: true},
|
||||
@@ -79,6 +85,7 @@ func DefaultRoleDict() []TrainingRoleDef {
|
||||
{Key: TrainingRoleLecturer, Label: "讲师", Short: "讲师", System: true},
|
||||
{Key: TrainingRoleManager, Label: "经理", Short: "经理", System: true,
|
||||
Inherits: []string{TrainingRoleSupervisor}},
|
||||
{Key: TrainingRoleSuperAdmin, Label: "超级管理员", Short: "超管", System: true},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,15 +243,22 @@ func hasString(list []string, want string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// NeedsRoleDictUpgrade 判断存量字典是否为 v1 口径(角色体系调整前):
|
||||
// v2 的硬标记是经理(exec)必须继承课长;凡不满足即视为 v1 需升级。
|
||||
// NeedsRoleDictUpgrade 判断存量字典是否需要读时升级:
|
||||
// - v1 口径:经理(exec)未继承课长(角色体系调整前的字典);
|
||||
// - v2 口径但缺后续新增的系统角色(如超级管理员):同样需要补齐,
|
||||
// 使存量租户无需迁移即可在配置中心看到并分配新角色。
|
||||
func NeedsRoleDictUpgrade(dict []TrainingRoleDef) bool {
|
||||
mgrFound := false
|
||||
for _, r := range dict {
|
||||
if r.Key == TrainingRoleManager {
|
||||
return !hasString(r.Inherits, TrainingRoleSupervisor)
|
||||
mgrFound = true
|
||||
if !hasString(r.Inherits, TrainingRoleSupervisor) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return true // 字典缺经理角色(异常/极旧数据),同样需要补齐
|
||||
// 缺经理(异常/极旧数据)或缺超级管理员,均视为需要升级
|
||||
return !mgrFound || !hasString(RoleDictKeys(dict), TrainingRoleSuperAdmin)
|
||||
}
|
||||
|
||||
// UpgradeRoleDictV2 把 v1 存量字典升级为 v2(课长/经理/人事/讲师),幂等:
|
||||
|
||||
@@ -17,8 +17,8 @@ func marshalDict(t *testing.T, roles []TrainingRoleDef) []byte {
|
||||
|
||||
func TestDefaultRoleDict(t *testing.T) {
|
||||
dict := DefaultRoleDict()
|
||||
if len(dict) != 4 {
|
||||
t.Fatalf("default dict should have 4 system roles, got %d", len(dict))
|
||||
if len(dict) != 5 {
|
||||
t.Fatalf("default dict should have 5 system roles, got %d", len(dict))
|
||||
}
|
||||
sysKeys := SystemTrainingRoles()
|
||||
for i, r := range dict {
|
||||
@@ -33,10 +33,15 @@ func TestDefaultRoleDict(t *testing.T) {
|
||||
}
|
||||
}
|
||||
// 经理必须继承课长(经理权限 = 课长全部 + 审批决策)
|
||||
mgr := dict[len(dict)-1]
|
||||
mgr := dict[3]
|
||||
if mgr.Key != TrainingRoleManager || !hasString(mgr.Inherits, TrainingRoleSupervisor) {
|
||||
t.Fatalf("manager should inherit supervisor, got %+v", mgr)
|
||||
}
|
||||
// 超级管理员:纯删除权角色,不继承任何权限组
|
||||
super := dict[len(dict)-1]
|
||||
if super.Key != TrainingRoleSuperAdmin || len(super.Inherits) != 0 {
|
||||
t.Fatalf("super admin should have no inherits, got %+v", super)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRoleDictValid(t *testing.T) {
|
||||
@@ -45,22 +50,23 @@ func TestParseRoleDictValid(t *testing.T) {
|
||||
{Key: TrainingRoleSupervisor, Label: "课长", Short: "课长", System: true},
|
||||
{Key: TrainingRoleLecturer, Label: "讲师", Short: "讲师", System: true},
|
||||
{Key: TrainingRoleManager, Label: "经理", Short: "经理", System: true, Inherits: []string{"", TrainingRoleSupervisor}},
|
||||
{Key: TrainingRoleSuperAdmin, Label: "超级管理员", Short: "超管", System: true},
|
||||
{Key: "trainer_plus", Label: "资深讲师", Inherits: []string{TrainingRoleLecturer, TrainingRoleSupervisor}},
|
||||
})
|
||||
dict, err := ParseRoleDict(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("valid dict rejected: %v", err)
|
||||
}
|
||||
if len(dict) != 5 {
|
||||
t.Fatalf("expect 5 roles, got %d", len(dict))
|
||||
if len(dict) != 6 {
|
||||
t.Fatalf("expect 6 roles, got %d", len(dict))
|
||||
}
|
||||
last := dict[4]
|
||||
last := dict[5]
|
||||
if len(last.Inherits) != 2 || last.Inherits[0] != TrainingRoleLecturer {
|
||||
t.Fatalf("inherits not preserved/cleaned: %v", last.Inherits)
|
||||
}
|
||||
// short 缺省回退 label
|
||||
if dict[4].Short != "资深讲师" {
|
||||
t.Fatalf("short should fall back to label, got %q", dict[4].Short)
|
||||
if dict[5].Short != "资深讲师" {
|
||||
t.Fatalf("short should fall back to label, got %q", dict[5].Short)
|
||||
}
|
||||
// manager 的空 inherit 被清理,课长继承保留
|
||||
if len(dict[3].Inherits) != 1 || dict[3].Inherits[0] != TrainingRoleSupervisor {
|
||||
@@ -75,6 +81,7 @@ func TestParseRoleDictInvalid(t *testing.T) {
|
||||
{Key: TrainingRoleSupervisor, Label: "课长", Short: "课长", System: true},
|
||||
{Key: TrainingRoleLecturer, Label: "讲师", Short: "讲师", System: true},
|
||||
{Key: TrainingRoleManager, Label: "经理", Short: "经理", System: true, Inherits: []string{TrainingRoleSupervisor}},
|
||||
{Key: TrainingRoleSuperAdmin, Label: "超级管理员", Short: "超管", System: true},
|
||||
}
|
||||
}
|
||||
cases := []struct {
|
||||
@@ -194,6 +201,10 @@ func TestNeedsRoleDictUpgrade(t *testing.T) {
|
||||
if NeedsRoleDictUpgrade(DefaultRoleDict()) {
|
||||
t.Fatal("v2 default dict should not need upgrade")
|
||||
}
|
||||
// v2 口径但缺 v2.1 增补的超级管理员:同样需要读时升级补齐(存量租户免迁移)
|
||||
if !NeedsRoleDictUpgrade(DefaultRoleDict()[:4]) {
|
||||
t.Fatal("v2 dict missing super_admin should need upgrade")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpgradeRoleDictV2(t *testing.T) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// 校验课程权限 SQL 常量括号配平与占位符数量(2026-11-26 复测根因定位辅助)
|
||||
const fs = require('fs')
|
||||
const src = fs.readFileSync('internal/application/repository/training_library.go', 'utf8')
|
||||
const start = src.indexOf('const courseLibraryPermissionMatchSQL')
|
||||
const end = src.indexOf('// courseLibraryPermissionCond 组装')
|
||||
const block = src.slice(start, end)
|
||||
const parts = []
|
||||
let i = 0
|
||||
while (true) {
|
||||
const q1 = block.indexOf('"', i)
|
||||
if (q1 < 0) break
|
||||
let j = q1 + 1
|
||||
let out = ''
|
||||
while (j < block.length) {
|
||||
if (block[j] === '\\') {
|
||||
out += block[j + 1]
|
||||
j += 2
|
||||
continue
|
||||
}
|
||||
if (block[j] === '"') break
|
||||
out += block[j]
|
||||
j += 1
|
||||
}
|
||||
parts.push(out)
|
||||
i = j + 1
|
||||
}
|
||||
const sql = parts.join('')
|
||||
const opens = (sql.match(/\(/g) || []).length
|
||||
const closes = (sql.match(/\)/g) || []).length
|
||||
const qs = (sql.match(/\?/g) || []).length
|
||||
console.log('opens=', opens, 'closes=', closes, 'placeholders=', qs, 'BALANCED=', opens === closes)
|
||||
// 括号深度轨迹:定位未闭合位置(深度未回 0 即缺失右括号)
|
||||
let depth = 0
|
||||
for (let k = 0; k < sql.length; k++) {
|
||||
if (sql[k] === '(') depth += 1
|
||||
if (sql[k] === ')') depth -= 1
|
||||
}
|
||||
console.log('final depth =', depth, '(>0 表示缺少右括号)')
|
||||
// 输出最后 120 个字符,便于人工核对末尾闭合
|
||||
console.log('--- tail ---')
|
||||
console.log(sql.slice(-120))
|
||||
console.log('--- SQL ---')
|
||||
console.log(sql)
|
||||
Reference in new issue
Block a user