fix(培训课程):优化培训课程

This commit is contained in:
runny committed 2026-11-17 08:21:59 +08:00
1 parent e378e8b7fd
commit aae041a0b4
19 files changed
+777 -188

No files matched your search

@@ -22,7 +22,7 @@
</div>
</div>
<p class="ai-hint">
汇总{{ scopeHint }}的课程学习、考试成绩、课堂签到与错题情况,由大模型生成本次分析报告与指导建议。
汇总{{ scopeHint }}的课程学习、考试成绩、培训签到与错题情况,由大模型生成本次分析报告与指导建议。
分析约需数十秒,请耐心等待。
</p>
@@ -24,11 +24,12 @@
</div>
<!-- 汇总行:与设计稿一致(共 N 门 · 线上 / 线下 / 本月新增或课件数)。
待维护 = 我任讲师且未发布(草稿/待审)、或已发布但未上传课件的课程数
(2026-11 需求:>0 时用与「草稿」一致的橙色提醒,不再用红色)。 -->
待维护 = 我主讲且「草稿」状态的课程数(2026-11 需求;>0 时用与「草稿」一致的橙色提醒)。
待开始 = 已排期且开课时间未到的课程数(按「我的课程」口径:我主讲/我参加,2026-11 需求)。 -->
<div class="catalog-stats">
{{ statsText }}
<span class="catalog-stats__maintain" :class="{ 'is-alert': maintainCount > 0 }">待维护 {{ maintainCount }} 门</span>
<span class="catalog-stats__pending" :class="{ 'is-info': pendingStartCount > 0 }">待开始 {{ pendingStartCount }} 门</span>
</div>
<!-- 课程卡片网格 -->
@@ -181,10 +182,19 @@ const myTeachingCourses = computed<TrainingCourse[]>(() => {
return [...map.values()]
})
// 待维护 = 我任讲师且未发布(草稿/待审)、或已发布但未上传课件的课程
// (线上课发布强制有课件,实际命中的多为线下课:学员通知在课件上传前不会推送)
// 「我的课程」数据源:我相关的已发布课 + 我任讲师的课(含未发布,按 id 去重);
// 页签列表与「待开始」统计共用同一口径。
const myCoursesSource = computed<TrainingCourse[]>(() => {
const minePublished = publishedCourses.value.filter(isMyCourse)
const mineIds = new Set(minePublished.map((c) => c.id))
return [...minePublished, ...myTeachingCourses.value.filter((c) => !mineIds.has(c.id))]
})
// 待维护 = 我主讲且「草稿」状态的课程(2026-11 需求:待审/已发布缺课件不再计入统计)
const maintainCount = computed(() => myTeachingCourses.value.filter((c) => c.status === 'draft').length)
// 置顶排序/维护按钮仍关注未发布(草稿/待审)或已发布但未上传课件的课程
const needsMaintain = (c: TrainingCourse) => c.status !== 'published' || !c.material_ids?.length
const maintainCount = computed(() => myTeachingCourses.value.filter(needsMaintain).length)
// 线下课排期索引:取最近一场排期/已完成场次汇总
const sessionByCourse = computed(() => {
@@ -197,6 +207,13 @@ const sessionByCourse = computed(() => {
return map
})
// [2026-11 需求] 待开始 = 已排期且开课时间还没到的课程(按「我的课程」口径统计)
const hasUpcomingSession = (c: TrainingCourse) =>
(sessionByCourse.value.get(c.id) || []).some(
(s) => s.status === 'scheduled' && !!s.start_at && new Date(s.start_at).getTime() > Date.now(),
)
const pendingStartCount = computed(() => myCoursesSource.value.filter(hasUpcomingSession).length)
const typeText = (c: TrainingCourse) => (c.type === 'elective' ? '选修' : '必修')
const fmtMonthDay = (raw: string | null) => {
if (!raw) return ''
@@ -247,11 +264,7 @@ const visibleCards = computed<CatalogCard[]>(() => {
const kw = keyword.value.trim().toLowerCase()
// 数据源:全部/线上/线下 = 已发布目录;我的课程 = 我相关的已发布课 + 我任讲师的课(含未发布,已发布的按 id 去重)
let source = publishedCourses.value
if (filter.value === 'mine') {
const minePublished = publishedCourses.value.filter(isMyCourse)
const mineIds = new Set(minePublished.map((c) => c.id))
source = [...minePublished, ...myTeachingCourses.value.filter((c) => !mineIds.has(c.id))]
}
if (filter.value === 'mine') source = myCoursesSource.value
let list = source.filter((c) => {
if (filter.value === 'online' && c.mode !== 'online') return false
if (filter.value === 'offline' && c.mode !== 'offline') return false
@@ -259,7 +272,7 @@ const visibleCards = computed<CatalogCard[]>(() => {
if (kw && !(c.name.toLowerCase().includes(kw) || (c.tags || []).some((t) => String(t).toLowerCase().includes(kw)))) return false
return true
})
// [2026-11 需求] 「我的课程」排序:待维护(我主讲未发布/缺课件)置顶,
// [2026-11 需求] 「我的课程」排序:需关注的课程(我主讲未发布/缺课件)置顶,
// 其余按与当前时间的邻近度升序(临近开课/结课的在前,无时间锚点的排最后)
if (filter.value === 'mine') {
const now = Date.now()
@@ -440,6 +453,16 @@ onMounted(loadAll)
font-weight: 600;
}
}
// 待开始统计:与「已排期」状态同色(品牌色)
&__pending {
margin-left: 6px;
&.is-info {
color: var(--td-brand-color);
font-weight: 600;
}
}
}
.catalog-grid-wrap {
@@ -32,7 +32,9 @@
</div>
<t-table :data="filteredCourses" :columns="courseColumns" row-key="id" size="small" :loading="loading">
<template #name="{ row }"><span class="clamp-2">{{ row.name }}</span></template>
<template #name="{ row }">
<span class="course-name-link clamp-2" title="点击前往培训签到" @click="goSignTab(row)">{{ row.name }}</span>
</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' ? '线上' : '线下' }}
@@ -536,6 +538,11 @@ const goStudyStatus = (row: TrainingCourse, section: 'learning' | 'exam') => {
router.push({ path: '/platform/training/study', query: { section, courseId: row.id } })
}
// 课程名称点击 → 培训签到页,携带 courseId 自动选中该课程的场次
const goSignTab = (row: TrainingCourse) => {
router.push({ path: '/platform/training/sign', query: { courseId: row.id } })
}
const loading = ref(false)
const saving = ref(false)
const courses = ref<TrainingCourse[]>([])
@@ -1766,15 +1773,17 @@ watch(() => route.query.courseId, openDetailFromRoute)
overflow-wrap: anywhere;
}
// 列表单元格内容垂直居中:用行内级 -webkit-inline-box 承接两行截断,
// 配合下方 .t-table__cell 的 vertical-align: middle,单行/双行内容均随行居中
.clamp-2 {
display: -webkit-box;
display: -webkit-inline-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-all;
line-height: 1.5;
min-height: 3em;
vertical-align: middle;
}
// 学习/考试状态 tag 可点击跳转学习考试页
@@ -1786,6 +1795,16 @@ watch(() => route.query.courseId, openDetailFromRoute)
}
}
// 课程名称可点击 → 培训签到页(与状态 tag 同款可点击观感,品牌色区分)
.course-name-link {
cursor: pointer;
color: var(--td-brand-color);
&:hover {
text-decoration: underline;
}
}
.course-panel :deep(.t-table .t-table__cell) {
vertical-align: middle;
}
@@ -88,67 +88,6 @@
</t-table>
</div>
<!-- 月度培训计划与审批:经理/人事审批决策(通过/调整/驳回),课长可见本部门计划 -->
<div class="panel-box">
<div class="panel-box__header">
<span class="panel-box__title plan-title-row">
月度培训计划与审批({{ monthPlansYear }})
<t-select
v-model="monthPlansYear"
class="year-select"
:options="yearOptions"
@change="loadMonthPlans"
/>
</span>
<div class="panel-box__actions">
<t-button v-if="isHr" variant="outline" :loading="rolling" @click="onRollMonthPlans">月底滚动未完成计划</t-button>
<t-button variant="outline" @click="loadMonthPlans">刷新</t-button>
</div>
</div>
<t-table
:data="monthPlans"
:columns="monthPlanColumns"
row-key="id"
size="small"
:loading="monthPlansLoading"
>
<template #dept_id="{ row }">{{ deptMap[row.dept_id] || row.dept_id || '-' }}</template>
<template #start_at="{ row }">{{ fmtStartAt(row.start_at) }}</template>
<template #status="{ row }">
<t-tag v-if="row.status === 'approved'" theme="success" variant="light" size="small">已通过</t-tag>
<t-tag v-else-if="row.status === 'rejected'" theme="danger" variant="light" size="small">已驳回</t-tag>
<t-tag v-else-if="row.status === 'submitted'" theme="warning" variant="light" size="small">待审批</t-tag>
<t-tag v-else-if="row.status === 'rolled'" theme="primary" variant="light" size="small">已滚动</t-tag>
<t-tag v-else theme="default" variant="light" size="small">草稿</t-tag>
</template>
<template #reject_reason="{ row }">{{ row.reject_reason || '-' }}</template>
<template #op="{ row }">
<template v-if="canApprove && (row.status === 'submitted' || row.status === 'draft')">
<t-button variant="text" theme="success" size="small" @click="onApprove(row, 'pass')">通过</t-button>
<t-button variant="text" theme="warning" size="small" @click="onApprove(row, 'adjust')">调整</t-button>
<t-button variant="text" theme="danger" size="small" @click="onApprove(row, 'reject')">驳回</t-button>
</template>
</template>
</t-table>
</div>
<!-- 审批意见弹窗(调整/驳回需填审批意见) -->
<t-dialog v-model:visible="approveVisible" :header="approveTitle" width="420">
<t-textarea
v-model="approveReason"
:autosize="{ minRows: 3 }"
placeholder="请输入审批意见(调整/驳回建议注明原因)"
/>
<template #footer>
<t-button variant="outline" @click="approveVisible = false">取消</t-button>
<t-button
:theme="approveAction === 'reject' ? 'danger' : 'primary'"
:loading="approving"
@click="onConfirmApprove"
>确认</t-button>
</template>
</t-dialog>
<!-- 提报需求弹窗(编辑态复用:部门按提报人自动获取) -->
<t-dialog v-model:visible="demandFormVisible" :header="demandDialogTitle" width="560">
<t-form :data="demandForm" label-width="90" @submit="onSaveDemand">
@@ -264,7 +203,6 @@ import * as XLSX from 'xlsx'
import { DEMAND_TEMPLATE_KEY, downloadTrainingTemplate } from '../trainingTemplates'
import { apiErrorMessage } from '@/utils/request'
import {
approveMonthPlan,
broadcastTrainingNotification,
confirmDemand,
deleteDemand,
@@ -274,12 +212,9 @@ import {
listDepts,
listLecturers,
listMembers,
listMonthPlans,
rollMonthPlans,
saveDemand,
type TrainingDept,
type TrainingDemand,
type TrainingMonthPlan,
type TrainingLecturerOption,
type TrainingMember,
unwrap,
@@ -289,10 +224,6 @@ const props = defineProps<{ roles: string[]; admin?: boolean }>()
// 计划管理(录入/推送/排课):人事/课长(roles 已按权限组展开,经理自动命中课长)
const canManage = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor'))
// 审批决策:经理(exec)/人事 — 与后端 ApproveMonthPlan 的 requireRoles 口径一致
const canApprove = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'exec'))
// 月底滚动等运营动作仅人事
const isHr = computed(() => props.admin || props.roles.includes('hr'))
const now = new Date()
const currentYear = now.getFullYear()
@@ -468,98 +399,12 @@ const loadFormOptions = async () => {
const loadAll = async () => {
loading.value = true
try {
await Promise.all([loadDemands(), loadMonthPlans()])
await loadDemands()
} finally {
loading.value = false
}
}
// ---- 月度培训计划与审批 ----
const monthPlans = ref<TrainingMonthPlan[]>([])
const monthPlansLoading = ref(false)
const monthPlansYear = ref(currentYear)
const monthPlanColumns = [
{ colKey: 'title', title: '计划主题' },
{ colKey: 'month', title: '月份', width: 64 },
{ colKey: 'dept_id', title: '部门', width: 110 },
{ colKey: 'start_at', title: '开始时间', width: 130 },
{ colKey: 'location', title: '地点', width: 100 },
{ colKey: 'status', title: '状态', width: 84 },
{ colKey: 'reject_reason', title: '审批意见', width: 150 },
{ colKey: 'op', title: '操作', width: 170 },
]
const fmtStartAt = (v: string | null) => (v ? String(v).slice(0, 16).replace('T', ' ') : '-')
const loadMonthPlans = async () => {
monthPlansLoading.value = true
try {
const res = await listMonthPlans({ year: monthPlansYear.value, page_size: 200 })
monthPlans.value = unwrap(res) || []
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '月度计划加载失败'))
} finally {
monthPlansLoading.value = false
}
}
// 审批决策:通过直达;调整/驳回弹窗填审批意见
const approveVisible = ref(false)
const approving = ref(false)
const approveAction = ref<'pass' | 'adjust' | 'reject'>('pass')
const approveRow = ref<TrainingMonthPlan | null>(null)
const approveReason = ref('')
const approveTitle = computed(() => {
const name = approveRow.value?.title || ''
if (approveAction.value === 'reject') return `驳回计划:${name}`
if (approveAction.value === 'adjust') return `调整意见:${name}`
return `通过计划:${name}`
})
const onConfirmApprove = async () => {
const row = approveRow.value
if (!row) return
approving.value = true
try {
await approveMonthPlan(row.id, approveAction.value, approveReason.value.trim())
MessagePlugin.success(approveAction.value === 'pass' ? '已通过该月度计划' : '审批意见已提交')
approveVisible.value = false
loadMonthPlans()
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '审批失败,请稍后重试'))
} finally {
approving.value = false
}
}
const onApprove = (row: TrainingMonthPlan, action: 'pass' | 'adjust' | 'reject') => {
approveRow.value = row
approveAction.value = action
approveReason.value = ''
if (action === 'pass') {
onConfirmApprove()
return
}
approveVisible.value = true
}
// 月底滚动(人事):未完成计划滚动生成下月计划
const rolling = ref(false)
const onRollMonthPlans = async () => {
rolling.value = true
try {
const res = await rollMonthPlans(monthPlansYear.value, new Date().getMonth() + 1)
MessagePlugin.success(`已滚动 ${unwrap(res)?.rolled ?? 0} 条未完成计划到下月`)
loadMonthPlans()
} catch (e: any) {
MessagePlugin.error(apiErrorMessage(e, '滚动失败,请稍后重试'))
} finally {
rolling.value = false
}
}
const onOpenDemandForm = () => {
demandForm.value = {
id: '',
@@ -404,7 +404,7 @@ const RULE_SCHEMAS: RuleSchemaDesc[] = [
{
key: 'sign_policy',
title: '签到策略',
desc: '课堂签到的迟到判定与定位校验',
desc: '培训签到的迟到判定与定位校验',
fields: [
{ key: 'late_after_min', label: '迟到阈值', type: 'number', min: 1, max: 120, unit: '分钟后算迟到' },
{ key: 'geo_radius_m', label: '定位有效半径', type: 'number', min: 50, max: 5000, unit: '米' },
@@ -2,7 +2,7 @@
<div class="sign-panel">
<div class="panel-box">
<div class="panel-box__header">
<span class="panel-box__title">课堂签到与佐证</span>
<span class="panel-box__title">培训签到与佐证</span>
<t-select
v-model="selectedSessionId"
filterable
@@ -23,7 +23,9 @@
<!-- 签到码 + 统计卡片 -->
<div class="sign-top">
<div class="sign-code-box">
<div class="sign-code-box__title">课堂签到码</div>
<div class="sign-code-box__title">培训签到码</div>
<!-- 签到二维码:学员企微扫码直达签到页;本地生成,不依赖外网二维码服务 -->
<img v-if="signQrUrl" :src="signQrUrl" class="sign-code-box__qr" alt="培训签到二维码" />
<div class="sign-code-box__token">{{ signCode?.token || '尚未生成' }}</div>
<div class="sign-code-box__meta" v-if="signCode">
有效期至 {{ fmtTime(signCode.expire_at) }}
@@ -148,8 +150,10 @@
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { computed, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { MessagePlugin } from 'tdesign-vue-next'
import QRCode from 'qrcode'
import {
checkin,
createSignCode,
@@ -177,6 +181,7 @@ import {
import { fmtBeijingTime } from '@/utils/datetime'
const props = defineProps<{ roles: string[]; admin?: boolean }>()
const route = useRoute()
// 签到复核/代签:人事/课长(roles 已按权限组展开,经理自动命中)
const canReview = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor'))
// 佐证上传/删除:人事/课长/讲师(与课件上传同口径)
@@ -213,6 +218,24 @@ const statusTheme = (s: string) => ({
normal: 'success', late: 'warning', abnormal: 'danger', outside: 'danger', duplicate: 'danger', missing: 'default',
}[s] || 'default')
// 签到二维码:内容为学员扫码签到页链接(携带 token),本地生成不依赖外网服务;
// 签到码刷新/切换场次后自动重绘。
const signQrUrl = ref('')
const buildSignQr = async () => {
const token = signCode.value?.token
if (!token) {
signQrUrl.value = ''
return
}
const url = `${window.location.origin}/platform/training/checkin/${token}`
try {
signQrUrl.value = await QRCode.toDataURL(url, { width: 320, margin: 1 })
} catch {
signQrUrl.value = ''
}
}
watch(signCode, buildSignQr, { immediate: true })
const flagText = (f: string) => ({ late: '迟到', outside: '定位异常', not_in_roster: '名单外' }[f] || f)
const courseName = (courseId: string) => courses.value.find((c) => c.id === courseId)?.name || '课程'
@@ -416,7 +439,32 @@ const onExport = async () => {
}
}
onMounted(loadAll)
// 培训课程页课程名称跳转:携带 courseId 查询参数直达本页,并自动选中该课程的
// 最相关场次(进行中 > 最近待开课 > 最近一场),完成「按课程筛选」的直接打开。
const applyRouteCourse = () => {
const courseId = String(route.query.courseId || '')
if (!courseId) return
const now = Date.now()
const ts = (s: TrainingCourseSession) => (s.start_at ? new Date(s.start_at).getTime() : 0)
const ofCourse = sessions.value.filter((s) => s.course_id === courseId && s.status !== 'cancelled')
if (!ofCourse.length) {
MessagePlugin.warning('该课程暂无课程场次')
return
}
const ongoing = ofCourse.find((s) => s.status === 'ongoing')
const upcoming = ofCourse
.filter((s) => s.status === 'scheduled' && ts(s) >= now)
.sort((a, b) => ts(a) - ts(b))[0]
const latest = [...ofCourse].sort((a, b) => ts(b) - ts(a))[0]
selectedSessionId.value = (ongoing || upcoming || latest).id
loadSessionData()
}
watch(() => route.query.courseId, applyRouteCourse)
onMounted(async () => {
await loadAll()
applyRouteCourse()
})
</script>
<style lang="less" scoped>
@@ -449,6 +497,17 @@ onMounted(loadAll)
text-align: center;
&__title { font-weight: 600; }
// 二维码白底留边,保证企微/相机扫码识别率
&__qr {
display: block;
width: 150px;
height: 150px;
margin: 10px auto 4px;
padding: 6px;
background: #fff;
border: 1px solid var(--td-component-stroke);
border-radius: var(--app-radius-sm);
}
&__token {
margin: 10px 0;
font-family: monospace;