feat(企微签到):逻辑:员工使用企微扫码后直接跳出签到页面,在签到页面对该课程进行点击签到!
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s

规则:1.签到要校验是否为培训当天签到,如果不是当天扫码签到则进行友好提示;2. 签到需提供员工工号及随机时间戳(超过签到二维码有效期后需重新扫码签到);3.签到二维码每5分钟自动更新一次(更新后之前扫码签到自动作废需重新扫码);
补充说明:1.签到页面需展示该签到课程相关信息;2.展示签到倒计时还有多久过期,过期后需重新扫码进行优化提示;3.签到后提示签到成功!自动登录进入平台系统并进入该课程详情页面
This commit is contained in:
runny committed 2026-11-25 11:02:48 +08:00
1 parent 9950a28346
commit f43fbef5db
24 files changed
+1336 -67

No files matched your search

@@ -31,6 +31,12 @@
有效期至 {{ fmtTime(signCode.expire_at) }}
<template v-if="signCode.geo_radius"> · 定位半径 {{ signCode.geo_radius }}m</template>
</div>
<!-- 自动轮换倒计时(2026-11 需求:二维码每 5 分钟自动更新,旧码即时作废;
轮换由后端在轮询读取时惰性触发,本页每 10s 轻量轮询驱动) -->
<div class="sign-code-box__countdown" v-if="signCode && rotateRemainSec > 0">
{{ rotateRemainText }}后自动更新,旧码作废需重扫
</div>
<div class="sign-code-box__countdown is-stale" v-else-if="signCode">即将自动更新签到码…</div>
<t-button v-if="canReview" theme="primary" variant="outline" :loading="genLoading" @click="onGenCode">
{{ signCode ? '刷新签到码' : '生成签到码' }}
</t-button>
@@ -159,7 +165,7 @@
</template>
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { MessagePlugin } from 'tdesign-vue-next'
import QRCode from 'qrcode'
@@ -255,6 +261,60 @@ const buildSignQr = async () => {
}
watch(signCode, buildSignQr, { immediate: true })
// ---- 签到码自动轮换(2026-11 企微扫码需求) ----
// 后端在 GET sign-code 超过轮换窗口(rotation_sec,默认 5 分钟)时惰性轮换:
// 旧 token 挪入 prev(30s 宽限后彻底作废),新码即时生效。本页每 10s 轻量轮询
// sign-code(不带明细/佐证),token 变化经上方 watch 自动重绘二维码并提示重扫;
// 页面隐藏时暂停轮询(投屏不在展示态时不做无谓轮换)。
const rotateRemainSec = ref(0)
let rotateDisplayTimer: number | undefined
let rotatePollTimer: number | undefined
const fmtRemainText = (sec: number) => {
const m = Math.floor(sec / 60)
const s = sec % 60
return m > 0 ? `${m}分${String(s).padStart(2, '0')}秒` : `${s}秒`
}
const rotateRemainText = computed(() => fmtRemainText(rotateRemainSec.value))
const tickRotateRemain = () => {
const exp = signCode.value?.expire_at
rotateRemainSec.value = exp ? Math.max(0, Math.floor((new Date(exp).getTime() - Date.now()) / 1000)) : 0
}
const pollSignCode = async () => {
if (!selectedSessionId.value || document.hidden) return
try {
const next = unwrap<TrainingSignCode | null>(await getSignCode(selectedSessionId.value))
if (!next) return
if (next.token !== signCode.value?.token) {
// 仅在 token 变化时回写:watch(signCode) 会重绘二维码并提示重扫;
// token 未变时跳过赋值,避免每 10s 触发一次无谓重绘。
signCode.value = next
MessagePlugin.info('签到码已自动更新,旧码已作废,请提醒学员重新扫码')
}
} catch {
// 场次尚未生成签到码/网络抖动:静默,不打断投屏。
}
}
const startCodeRotation = () => {
stopCodeRotation()
tickRotateRemain()
rotateDisplayTimer = window.setInterval(tickRotateRemain, 1000)
rotatePollTimer = window.setInterval(pollSignCode, 10000)
}
const stopCodeRotation = () => {
if (rotateDisplayTimer) {
window.clearInterval(rotateDisplayTimer)
rotateDisplayTimer = undefined
}
if (rotatePollTimer) {
window.clearInterval(rotatePollTimer)
rotatePollTimer = undefined
}
}
watch(selectedSessionId, (sid) => {
if (sid) startCodeRotation()
else stopCodeRotation()
})
const flagText = (f: string) => ({ late: '迟到', outside: '定位异常', not_in_roster: '名单外' }[f] || f)
const courseName = (courseId: string) => courses.value.find((c) => c.id === courseId)?.name || '课程'
@@ -483,7 +543,11 @@ watch(() => route.query.courseId, applyRouteCourse)
onMounted(async () => {
await loadAll()
applyRouteCourse()
// 签到码轮换:进页即启动(选中场次后 watch 也会重启,双保险覆盖异步加载)。
startCodeRotation()
})
onUnmounted(stopCodeRotation)
</script>
<style lang="less" scoped>
@@ -537,6 +601,15 @@ onMounted(async () => {
padding: 8px;
}
&__meta { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); margin-bottom: 10px; }
// 自动轮换倒计时(2026-11 需求):临期转警示色,提醒讲师学员需重扫。
&__countdown {
color: var(--td-brand-color);
font-size: var(--app-text-sm);
margin-bottom: 10px;
&.is-stale { color: var(--td-warning-color, #e37318); }
}
}
.stat-cards {