Files
ai_academy/frontend/src/views/training/Training.vue
T
runny 043e0485e2
deploy-hxtesting / build-and-deploy (push) Successful in 1m20s
feat(权限优化)1.AI对话中点击快捷标签问题时,明明已经配置了默认默写为什么还会提示配置?必须点击一下保存并关闭才可以这个不对,只要配置了就可以问答不需要再让用户过来点击一次!如图一、二所示
2.知识库中的企业培训(课件)、企业培训(试题)、配置中心、组织架构、共享空间如图三所示可查看权限归属到超级管理员权限中!如何对
2026-11-27 14:49:06 +08:00

287 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="training-page">
<!-- 页头与知识库/工具箱同构:资源图标 + 当前页签名称 + 角色标签 + 副标题 -->
<header class="training-header">
<div class="training-title-row">
<div class="training-title-group">
<h2>
<ResourceIcon type="training" :size="24" />
{{ activeTabMeta.title }}
</h2>
<t-tag v-if="myRoleLabel" theme="primary" variant="light">{{ myRoleLabel }}</t-tag>
</div>
<!-- 工作台视图切换:课程 / 个人成长(数据驾驶舱已迁侧栏,000158) -->
<nav v-if="isWorkbench" class="workbench-switch" aria-label="工作台视图切换">
<button
v-for="t in workbenchSwitchTabs"
:key="t.key"
type="button"
class="workbench-switch__tab"
:class="{ 'is-active': workbenchTab === t.key }"
:aria-pressed="workbenchTab === t.key"
@click="workbenchTab = t.key"
>{{ t.label }}</button>
</nav>
</div>
<p class="training-subtitle">{{ activeTabMeta.desc }}</p>
</header>
<!-- 子页(培训中心/年培训计划/…/配置中心)由侧栏「企业培训」分组导航,此处按路由 tab 参数渲染 -->
<t-alert
v-if="sessionExpired"
class="training-session-alert"
theme="warning"
message="登录态已失效"
description="培训数据未丢失。请重新登录后刷新本页即可查看。"
/>
<div class="training-body">
<!-- 工作台:课程(默认)/个人成长 两视图切换;数据驾驶舱已迁侧栏(000158) -->
<WorkbenchPanel v-if="activeTab === 'dashboard'" :roles="myRoles" :admin="isAdmin" :tab="workbenchTab" />
<!-- 数据驾驶舱独立子页(000158):与工作台驾驶舱视图同源,非管理角色回落课程目录 -->
<template v-else-if="activeTab === 'data-dashboard'">
<WorkbenchPanel v-if="canSeeWorkbenchDashboard" :roles="myRoles" :admin="isAdmin" tab="dashboard" />
<t-empty v-else class="training-empty" description="数据驾驶舱仅人事/课长/经理可见" />
</template>
<template v-else-if="activeTab === 'plan'">
<PlanPanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
<t-empty v-else class="training-empty" description="培训计划仅课长/经理/人事可见" />
</template>
<template v-else-if="activeTab === 'course'">
<CoursePanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
<t-empty v-else class="training-empty" description="月培训计划仅课长/经理/人事/讲师可见,学员请前往培训中心课程目录" />
</template>
<template v-else-if="activeTab === 'library'">
<!-- 课程管理全员可见(000157):数据范围与按钮权限按角色细分(人事全部/
课长经理本部门/讲师学员仅「与我相关」),细控在 LibraryPanel 与后端 -->
<LibraryPanel :roles="myRoles" :admin="isAdmin" />
</template>
<template v-else-if="activeTab === 'sign'">
<SignPanel v-if="canManageTabs" :roles="myRoles" :admin="isAdmin" />
<t-empty v-else class="training-empty" description="培训签到仅课长/经理/人事/讲师可见" />
</template>
<StudyPanel v-else-if="activeTab === 'study'" :roles="myRoles" :admin="isAdmin" />
<template v-else-if="activeTab === 'rules'">
<!-- 配置中心对经理开放(000158):经理与人事同权查看/维护培训规则 -->
<RulePanel v-if="canManageConfig" />
<t-empty v-else class="training-empty" description="配置中心仅人事/经理可见" />
</template>
<WorkbenchPanel v-else :roles="myRoles" :admin="isAdmin" :tab="workbenchTab" />
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { MessagePlugin } from 'tdesign-vue-next'
import { useAuthStore } from '@/stores/auth'
import ResourceIcon from '@/components/icons/ResourceIcon.vue'
import WorkbenchPanel from './components/WorkbenchPanel.vue'
import PlanPanel from './components/PlanPanel.vue'
import CoursePanel from './components/CoursePanel.vue'
import LibraryPanel from './components/LibraryPanel.vue'
import SignPanel from './components/SignPanel.vue'
import StudyPanel from './components/StudyPanel.vue'
import RulePanel from './components/RulePanel.vue'
import { expandRoles, fetchRoleDict, getMyProfile, roleLabelOf, type TrainingMember, type TrainingRoleDef } from '@/api/training'
// 与侧栏「企业培训」分组文案一致;title 同时用于页头显示当前页签名
// 「学习考试」已移出侧栏导航,路由保留(学习/考试状态列点击等场景仍可直达)
const TRAINING_TABS_META: Record<string, { title: string; desc: string }> = {
dashboard: { title: '培训中心', desc: '培训运营总览、待办与达成率一览' },
// 数据驾驶舱(000158):侧栏独立子页,内容与工作台驾驶舱视图同源
'data-dashboard': { title: '数据驾驶舱', desc: '部门培训达成率排名、讲师积分榜与月度盘点' },
plan: { title: '年培训计划', desc: '年度培训需求收集与汇总(可切换年度)' },
course: { title: '月培训计划', desc: '月度培训计划排期、场次安排与学员名单;课程从课程管理选择,计划编号自动生成' },
library: { title: '课程管理', desc: '课程资产库维护:编号/课程名称/说明/分类/类型/线上线下/讲师/时长/课件/试题' },
sign: { title: '培训签到', desc: '签到码生成、签到明细复核与佐证导出' },
study: { title: '学习考试', desc: '我的课程学习、课程学习情况、课程考试情况与 AI 课程分析' },
// members(职称角色)已并入「组织架构」页维护,路由 /platform/training/members 重定向过去
rules: { title: '配置中心', desc: '培训业务规则在线配置,改配置不改代码' },
}
const TRAINING_TAB_KEYS = Object.keys(TRAINING_TABS_META)
const route = useRoute()
const router = useRouter()
const rawRoles = ref<string[]>([])
const authStore = useAuthStore()
// 职称角色字典(配置中心可配);myRoles = 实际分配角色按「权限分配」传递展开后的
// 权限并集 —— 各子页既有 canXxx 判断因此对自定义角色自动生效,无需逐一修改。
const roleDict = ref<TrainingRoleDef[]>([])
const loadRoleDict = () =>
fetchRoleDict().then((d) => {
roleDict.value = d
})
const myRoles = computed(() => expandRoles(rawRoles.value, roleDict.value))
loadRoleDict()
// 空间 Admin/Owner 视同培训管理角色(与后端 requireRoles 的 bypass 一致),
// 保证冷启动时管理员即可进入职称角色/配置中心子页完成首批授权。
// 职称角色/配置中心为人事专属(角色体系 v2)。
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', 'super_admin'].includes(r)))
// 配置中心门槛(000163 权限收口):仅平台超级管理员可查看与维护
// (菜单入口/路由守卫同步收口,此处为页面内兜底)。
const canManageConfig = computed(() => authStore.isSystemAdmin)
// 页头角色标签:展示实际分配的角色(非权限展开),文案取自配置中心字典
const myRoleLabel = computed(() =>
rawRoles.value.map((r) => roleLabelOf(r, roleDict.value)).join(' / '))
// 当前子页:取路由 tab 参数;非法值回退工作台(不动路由,避免与侧栏高亮脱节)
const activeTab = computed(() => {
const tab = String(route.params.tab || 'dashboard')
// 旧页签合并兼容:exam/learning → study
if (tab === 'exam' || tab === 'learning') return 'study'
return TRAINING_TAB_KEYS.includes(tab) ? tab : 'dashboard'
})
const activeTabMeta = computed(() => {
// 工作台三视图:页头标题/副标题跟随当前视图(课程视图「培训中心」,000154)
if (activeTab.value === 'dashboard') {
if (workbenchTab.value === 'course') return { title: '培训中心', desc: '和信课程目录、我的培训与我的考试' }
if (workbenchTab.value === 'growth') return { title: '工作台', desc: '个人成长进阶 · 能力模型与成就任务总览' }
return TRAINING_TABS_META.dashboard
}
return TRAINING_TABS_META[activeTab.value]
})
// ---- 工作台三视图切换 ----
// 课程 / 个人成长全员可见;数据驾驶舱仅培训管理角色可见(普通员工隐藏入口)。
type WorkbenchView = 'course' | 'growth' | 'dashboard'
const workbenchTab = ref<WorkbenchView>('course')
const canSeeWorkbenchDashboard = computed(
() => isAdmin.value || myRoles.value.some((r) => r === 'hr' || r === 'supervisor' || r === 'exec'),
)
// 页头视图切换(000158):数据驾驶舱已迁侧栏独立子页,工作台仅保留课程/个人成长
const workbenchSwitchTabs = computed(() => {
const list: { key: WorkbenchView; label: string }[] = [
{ key: 'course', label: '课程' },
{ key: 'growth', label: '个人成长' },
]
return list
})
const isWorkbench = computed(() => activeTab.value === 'dashboard')
// 角色异步加载后若驾驶舱入口被收回,视图回落课程目录
watch(canSeeWorkbenchDashboard, (ok) => {
if (!ok && workbenchTab.value === 'dashboard') workbenchTab.value = 'course'
})
// 会话失效标记:401 时组件层不再静默降级为「学员」空态(会被误读成数据丢失),
// 而是明确提示重新登录;跳转由 request.ts 的 401 拦截器统一负责。
const sessionExpired = ref(false)
const loadProfile = async () => {
try {
const res = await getMyProfile() as any
sessionExpired.value = false
// 兼容两种封包:拦截器解包后 {success, data}(res.data 即 member)
const member: TrainingMember | undefined = res?.data?.data || res?.data
if (member) {
rawRoles.value = (member.roles as unknown as string[]) || ['trainee']
}
} catch (e: any) {
const status = e?.response?.status || e?.data?.status
if (status === 401) {
sessionExpired.value = true
rawRoles.value = []
MessagePlugin.warning('登录态已失效,请重新登录后查看培训数据')
} else {
rawRoles.value = ['trainee']
}
}
}
onMounted(() => {
loadProfile()
})
// 侧栏在企业培训各子页间切换时复用同一页面实例(不重挂载):本人职称角色可能刚在
// 「职称角色」子页被分配/回收,角色权限字典可能刚在「配置中心」子页被修改。切换
// 子页时重取这两项,否则各子页会沿用挂载时的旧 myRoles —— 例如刚给自己分配了
// 课长,课程管理的核验/删除按钮却不出现,须整页刷新才生效。
watch(activeTab, () => {
loadProfile()
loadRoleDict()
})
</script>
<style lang="less" scoped>
@import (reference) './training.less';
.training-page {
.training-page-frame();
}
.training-header {
.training-header();
}
// 工作台视图切换页签:右对齐文本页签,激活态品牌色加粗
.workbench-switch {
display: flex;
align-items: center;
gap: 28px;
flex-shrink: 0;
&__tab {
position: relative;
border: 0;
background: transparent;
padding: 4px 2px;
font: inherit;
font-size: var(--app-text-lg);
font-weight: 500;
color: var(--td-text-color-secondary);
cursor: pointer;
transition: color var(--app-motion-fast) ease;
&:hover {
color: var(--td-text-color-primary);
}
&.is-active {
color: var(--td-brand-color);
font-weight: 600;
}
&:focus-visible {
outline: 2px solid var(--td-brand-color);
outline-offset: 2px;
border-radius: var(--app-radius-sm);
}
}
}
.training-session-alert {
margin-bottom: 12px;
}
.training-body {
flex: 1;
min-height: 0;
min-width: 0;
overflow-y: auto;
overflow-x: hidden;
padding: var(--app-space-3) 0 var(--app-space-6);
}
.training-empty {
padding: 64px 0;
}
</style>