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

@@ -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;