Files
ai_academy/frontend/src/views/training/components/StudyPanel.vue
T
runny 102d94e6c8
deploy-hxtesting / build-and-deploy (push) Successful in 1m8s
fix(培训页面优化):1.请检查所有企业培训相关页面带有列表展示都要进行分页,使用分页共用组件默认每页15条!
2.课程管理页面右侧固定太宽如图二所示收缩够用就可以,可参考培训计划页面
3.月培训计划数据默认显示计划培训和授课培训是当月数据,可筛选其他月份支持多选或全部数据
4.月培训计划只需要保留一个【创建月度计划】按钮,无法创建月度计划请核实根因!
2026-11-25 13:45:36 +08:00

333 lines
12 KiB
Vue

<template>
<div class="study-panel">
<!-- 顶部页签:我的课程学习 / 课程学习情况 / 课程考试情况 / AI课程分析 -->
<div class="study-tabbar">
<div class="study-tabs" role="tablist" aria-label="学习考试分区">
<button
v-for="tab in visibleTabs"
:key="tab.key"
type="button"
role="tab"
class="study-tab"
:aria-selected="activeSection === tab.key"
@click="activeSection = tab.key"
>{{ tab.title }}</button>
</div>
</div>
<!-- A. 我的课程学习:我的学习/考试/错题/画像 四宫格(所有人可见) -->
<div v-if="isVisited('mine')" v-show="activeSection === 'mine'" class="panel-grid">
<div class="panel-box">
<div class="panel-box__header">
<span class="panel-box__title">我的学习任务</span>
<span class="panel-box__sub">点击课程名进入学习,进度 ≥95% 自动完成</span>
</div>
<t-table :data="pagedTasks" :columns="taskColumns" row-key="id" size="small">
<template #course_name="{ row }">
<a class="task-course-link" @click="goCourse(row.course_id)">{{ row.course_name }}</a>
</template>
<template #deadline="{ row }">{{ fmtTime(row.deadline) }}</template>
<template #status="{ row }">
<t-tag :theme="taskTheme(row.status)" variant="light" size="small">{{ taskText(row.status) }}</t-tag>
</template>
</t-table>
<TrainingPagination v-model:current="taskPage" v-model:page-size="taskPageSize" :total="taskTotal" />
<t-empty v-if="!tasks.length" description="暂无学习任务,课程发布后将自动生成" />
</div>
<div class="panel-box">
<div class="panel-box__header">
<span class="panel-box__title">我的考试成绩</span>
</div>
<t-table :data="pagedMyRecords" :columns="myRecordColumns" row-key="id" size="small" :loading="loading">
<template #course_name="{ row }">{{ row.course_name || row.paper_name || '-' }}</template>
<template #score="{ row }">
<span :class="passClass(row)">{{ row.score ?? '—' }}</span>
</template>
<template #pass_line="{ row }">{{ row.pass_score || '-' }} / {{ row.total_score || '-' }}</template>
<template #submitted_at="{ row }">{{ fmtTime(row.submitted_at) }}</template>
</t-table>
<TrainingPagination v-model:current="myRecordPage" v-model:page-size="myRecordPageSize" :total="myRecordTotal" />
<t-empty v-if="!myRecords.length" description="暂无考试记录,参加随堂考试后此处展示成绩" />
</div>
<div class="panel-box">
<div class="panel-box__header">
<span class="panel-box__title">我的错题本</span>
</div>
<t-table :data="pagedWrongBook" :columns="wrongColumns" row-key="id" size="small">
<template #knowledge_point="{ row }">
<t-tag v-if="row.knowledge_point" variant="light" size="small">{{ row.knowledge_point }}</t-tag>
<span v-else>—</span>
</template>
<template #mastered="{ row }">
<t-tag :theme="row.mastered ? 'success' : 'warning'" variant="light" size="small">
{{ row.mastered ? '已掌握' : '待巩固' }}
</t-tag>
</template>
</t-table>
<TrainingPagination v-model:current="wrongPage" v-model:page-size="wrongPageSize" :total="wrongTotal" />
<t-empty v-if="!wrongBook.length" description="错题本为空,继续保持" />
</div>
<div class="panel-box">
<div class="panel-box__header">
<span class="panel-box__title">我的能力画像</span>
</div>
<div v-if="profile" class="profile-grid">
<div class="profile-item">
<div class="profile-item__label">岗位胜任度</div>
<div class="profile-item__value" :class="profile.competency >= profile.pass_line ? 'tone-good' : 'tone-bad'">
{{ profile.competency }} 分
</div>
<div class="profile-item__sub">达标线 {{ profile.pass_line }} 分</div>
</div>
<div class="profile-item">
<div class="profile-item__label">累计积分</div>
<div class="profile-item__value">{{ profile.points }}</div>
</div>
<div class="profile-item">
<div class="profile-item__label">平均成绩</div>
<div class="profile-item__value">{{ profile.avg_score }}</div>
</div>
<div class="profile-item">
<div class="profile-item__label">学习时长</div>
<div class="profile-item__value">{{ profile.study_hours }} h</div>
</div>
<div class="profile-item">
<div class="profile-item__label">课程数</div>
<div class="profile-item__value">{{ profile.course_count }}</div>
</div>
</div>
<t-empty v-else description="暂无画像数据" />
</div>
</div>
<!-- B. 课程学习情况(人事/文员/讲师):课程选择 + 状态汇总 + 条件查询 -->
<CourseLearningStatus
v-if="canManage && isVisited('learning')"
v-show="activeSection === 'learning'"
:initial-course-id="initialCourseId"
/>
<!-- C. 课程考试情况(人事/文员/讲师):成绩汇总查询 + 班级薄弱点 -->
<ExamPanel
v-if="canManage && isVisited('exam')"
v-show="activeSection === 'exam'"
:roles="roles"
:admin="admin"
:initial-course-id="initialCourseId"
/>
<!-- D. AI课程分析:学习/考试/签到/错题汇总分析(全员可见,维度随角色) -->
<CourseAIAnalysis
v-if="isVisited('ai')"
v-show="activeSection === 'ai'"
:roles="roles"
:admin="admin"
/>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import {
getMyAbilityProfile,
listMyExamRecords,
listMyLearningTasks,
listWrongBook,
type LearningTask,
type MyExamRecord,
type TrainingProfile,
type WrongBookItem,
unwrap,
} from '@/api/training'
import { fmtBeijingTime } from '@/utils/datetime'
import CourseLearningStatus from './CourseLearningStatus.vue'
import ExamPanel from './ExamPanel.vue'
import CourseAIAnalysis from './CourseAIAnalysis.vue'
import TrainingPagination from './TrainingPagination.vue'
import { useTrainingPager } from './useTrainingPager'
const props = defineProps<{ roles: string[]; admin?: boolean }>()
// 课程学习/考试情况管理端:人事/课长/讲师(roles 已按权限组展开,经理自动命中)
const canManage = computed(() => props.admin || props.roles.some((r) => ['hr', 'supervisor', 'lecturer'].includes(r)))
const router = useRouter()
// ---- 顶部页签(管理页签对纯学员隐藏,与工作台按角色显隐口径一致) ----
type StudySection = 'mine' | 'learning' | 'exam' | 'ai'
const STUDY_TABS: { key: StudySection; title: string; manageOnly?: boolean }[] = [
{ key: 'mine', title: '我的课程学习' },
{ key: 'learning', title: '课程学习情况', manageOnly: true },
{ key: 'exam', title: '课程考试情况', manageOnly: true },
{ key: 'ai', title: 'AI课程分析' },
]
const activeSection = ref<StudySection>('mine')
// 首访才挂载页签组件(懒加载),挂载后保活切换不丢状态
const visitedSections = ref(new Set<StudySection>(['mine']))
const isVisited = (key: StudySection) => visitedSections.value.has(key)
const visibleTabs = computed(() => STUDY_TABS.filter((t) => !t.manageOnly || canManage.value))
// 培训课程页状态列跳转:携带 section(learning/exam)与 courseId 查询参数,
// 用于直达「课程学习情况/课程考试情况」页签并预选对应课程。
const route = useRoute()
const initialCourseId = computed(() => String(route.query.courseId || ''))
const applyRouteSection = () => {
const section = String(route.query.section || '')
if (!canManage.value || (section !== 'learning' && section !== 'exam')) return
activeSection.value = section
visitedSections.value.add(section)
}
watch(activeSection, (key) => {
visitedSections.value.add(key)
})
// 角色异步加载后若管理页签被收回,视图回落「我的课程学习」;
// 角色就绪时再按路由参数重放一次页签定位(培训课程页跳转场景)。
watch(canManage, (ok) => {
if (!ok) {
if (activeSection.value === 'learning' || activeSection.value === 'exam') {
activeSection.value = 'mine'
}
return
}
applyRouteSection()
})
// 已挂载状态下再次携参跳转(如从培训课程页二次点击)同步页签
watch(() => route.query.section, applyRouteSection)
// ---- A. 我的课程学习数据 ----
const loading = ref(false)
const tasks = ref<LearningTask[]>([])
const myRecords = ref<MyExamRecord[]>([])
const wrongBook = ref<WrongBookItem[]>([])
const profile = ref<TrainingProfile | null>(null)
const taskColumns = [
{ colKey: 'course_name', title: '课程' },
{ colKey: 'deadline', title: '完成期限', width: 160 },
{ colKey: 'status', title: '状态', width: 90 },
]
const myRecordColumns = [
{ colKey: 'course_name', title: '课程/试卷' },
{ colKey: 'score', title: '成绩', width: 70 },
{ colKey: 'pass_line', title: '及格/总分', width: 90 },
{ colKey: 'submitted_at', title: '交卷时间', width: 160 },
]
const wrongColumns = [
{ colKey: 'stem', title: '题干' },
{ colKey: 'knowledge_point', title: '知识点', width: 130 },
{ colKey: 'wrong_count', title: '错误次数', width: 90 },
{ colKey: 'mastered', title: '掌握状态', width: 90 },
]
const taskText = (s: string) => ({ pending: '待学习', doing: '学习中', done: '已完成', overdue: '已逾期' }[s] || s)
const taskTheme = (s: string) => ({ pending: 'default', doing: 'primary', done: 'success', overdue: 'danger' }[s] || 'default')
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '—'
// 四宫格列表分页(000163):学习任务/考试成绩/错题本默认每页 15 条
const { page: taskPage, pageSize: taskPageSize, total: taskTotal, paged: pagedTasks } = useTrainingPager(tasks)
const { page: myRecordPage, pageSize: myRecordPageSize, total: myRecordTotal, paged: pagedMyRecords } = useTrainingPager(myRecords)
const { page: wrongPage, pageSize: wrongPageSize, total: wrongTotal, paged: pagedWrongBook } = useTrainingPager(wrongBook)
const passClass = (row: MyExamRecord) => {
if (row.score == null) return ''
return row.pass_score ? (row.score >= row.pass_score ? 'tone-good' : 'tone-bad') : ''
}
const goCourse = (courseId: string) => {
if (courseId) router.push(`/platform/training/course/${courseId}`)
}
const loadAll = async () => {
loading.value = true
try {
const [t, r, w, p] = await Promise.all([
listMyLearningTasks().catch(() => null),
listMyExamRecords().catch(() => null),
listWrongBook().catch(() => null),
getMyAbilityProfile().catch(() => null),
])
tasks.value = (t && unwrap(t)) || []
myRecords.value = (r && unwrap(r)) || []
wrongBook.value = (w && unwrap(w)) || []
profile.value = (p && unwrap(p)) || null
} finally {
loading.value = false
}
}
onMounted(() => {
applyRouteSection()
loadAll()
})
</script>
<style lang="less" scoped>
@import (reference) '../training.less';
// 顶部页签条(与培训计划页同款交互:底部描边 + 品牌色下划线)
.study-tabbar {
.training-tabbar();
}
.study-tabs {
.training-tabs();
}
.study-tab {
.training-tab();
}
.panel-grid {
.training-panel-grid();
}
.panel-box {
.training-panel-box();
&__sub {
color: var(--td-text-color-placeholder);
font-size: var(--app-text-sm);
}
}
.task-course-link {
color: var(--td-brand-color);
cursor: pointer;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
.profile-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 12px;
}
.profile-item {
background: var(--td-bg-color-secondarycontainer);
border-radius: var(--app-radius-md);
padding: 12px 14px;
text-align: center;
&__label { color: var(--td-text-color-secondary); font-size: var(--app-text-md); }
&__value { font-size: 22px; font-weight: 700; margin-top: 4px; }
&__sub { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); margin-top: 2px; }
}
.tone-good { color: var(--td-success-color); }
.tone-bad { color: var(--td-error-color); }
</style>