834 lines
32 KiB
Vue
834 lines
32 KiB
Vue
<template>
|
|
<div class="sign-panel">
|
|
<div class="panel-box">
|
|
<div class="panel-box__header">
|
|
<span class="panel-box__title">培训签到与佐证</span>
|
|
<t-select
|
|
v-model="selectedSessionId"
|
|
filterable
|
|
placeholder="选择课程场次"
|
|
style="width: 360px"
|
|
@change="loadSessionData"
|
|
>
|
|
<t-option
|
|
v-for="s in sessions"
|
|
:key="s.id"
|
|
:value="s.id"
|
|
:label="`${courseName(s.course_id)} · ${fmtTime(s.start_at)}`"
|
|
/>
|
|
</t-select>
|
|
</div>
|
|
|
|
<template v-if="selectedSessionId">
|
|
<!-- 签到码 + 统计卡片 -->
|
|
<div class="sign-top">
|
|
<div class="sign-code-box">
|
|
<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">
|
|
<!-- 文案口径(测试反馈 2026-11-26):「二维码有效期至 HH:mm」,不展示年月日 -->
|
|
二维码有效期至 {{ fmtClock(signCode.expire_at) }}
|
|
<template v-if="signCode.geo_radius"> · 定位半径 {{ signCode.geo_radius }}m</template>
|
|
</div>
|
|
<!-- 二维码地址预检:非对外域名生成时当场提醒,避免学员扫码后企微报
|
|
"redirect_uri需使用应用可信域名"(2026-11 联调反馈) -->
|
|
<div class="sign-code-box__countdown is-stale" v-if="signCode && qrOriginWarn">
|
|
当前页面地址({{ qrOriginHost }})不是对外域名,学员扫码无法签到 —— 请从 kbt/kb.well-trust.com 打开本页重新生成
|
|
</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>
|
|
</div>
|
|
<div class="stat-cards">
|
|
<div class="stat-card"><div class="stat-card__label">应到(人)</div><div class="stat-card__value">{{ summary?.expected ?? '—' }}</div></div>
|
|
<div class="stat-card"><div class="stat-card__label">已签到</div><div class="stat-card__value tone-good">{{ summary?.signed ?? '—' }}</div></div>
|
|
<div class="stat-card"><div class="stat-card__label">迟到</div><div class="stat-card__value tone-warn">{{ summary?.late ?? '—' }}</div></div>
|
|
<div class="stat-card"><div class="stat-card__label">异常待复核</div><div class="stat-card__value tone-bad">{{ summary?.abnormal ?? '—' }}</div></div>
|
|
<!-- 培训佐证上传:签到照(可多选)/培训视频,点击卡片选择文件 -->
|
|
<template v-if="canUpload">
|
|
<div class="stat-card upload-card" :class="{ 'is-uploading': uploading }" role="button" tabindex="0" @click="!uploading && photoInput?.click()" @keydown.enter="!uploading && photoInput?.click()">
|
|
<div class="stat-card__label">上传签到照</div>
|
|
<div class="upload-card__main">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><circle cx="9" cy="10" r="1.6"/><path d="m5 19 5.2-5.2a1.4 1.4 0 0 1 2 0L17 18.5"/><path d="M14.5 15.5 16 14a1.4 1.4 0 0 1 2 0l3 3"/><path d="M12 2v4M10 4h4"/></svg>
|
|
<span>已归档 {{ evidenceCount('sign_photo') }} 张</span>
|
|
</div>
|
|
<div class="upload-card__hint">{{ uploading ? '上传中…' : '现场拍照上传 · 每张 ≤ ' + PHOTO_MAX_MB + 'MB' }}</div>
|
|
</div>
|
|
<div class="stat-card upload-card" :class="{ 'is-uploading': uploading }" role="button" tabindex="0" @click="!uploading && videoInput?.click()" @keydown.enter="!uploading && videoInput?.click()">
|
|
<div class="stat-card__label">上传培训视频</div>
|
|
<div class="upload-card__main">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="12" rx="2"/><path d="m10 8.6 4 2.4-4 2.4z"/><path d="M8 21h8M12 17v4"/><path d="M12 1v2"/></svg>
|
|
<span>已归档 {{ evidenceCount('training_video') }} 个</span>
|
|
</div>
|
|
<div class="upload-card__hint">{{ uploading ? '上传中…' : '课程实录留证 · 每个 ≤ ' + VIDEO_MAX_MB + 'MB' }}</div>
|
|
</div>
|
|
</template>
|
|
<!-- 培训详情:回跳课程学习详情页(与课程详情页「培训签到」按钮互为出入口) -->
|
|
<div v-if="selectedCourseId" class="stat-card upload-card" role="button" tabindex="0" @click="goCourseDetail" @keydown.enter="goCourseDetail">
|
|
<div class="stat-card__label">培训详情</div>
|
|
<div class="upload-card__main">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19V5a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v14"/><path d="M2 19h20"/><path d="M8 7h8M8 11h6"/></svg>
|
|
<span :title="courseName(selectedCourseId)">{{ courseName(selectedCourseId) }}</span>
|
|
</div>
|
|
<div class="upload-card__hint">查看课程课件 / 随堂考试详情</div>
|
|
</div>
|
|
</div>
|
|
<input ref="photoInput" type="file" accept="image/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'sign_photo')" />
|
|
<input ref="videoInput" type="file" accept="video/*" multiple class="visually-hidden-input" @change="onEvidenceFiles($event, 'training_video')" />
|
|
</div>
|
|
|
|
<!-- 佐证文件列表:在线预览(照片/视频)与删除 -->
|
|
<div v-if="evidences.length" class="evidence-files">
|
|
<div class="records-header">
|
|
<span class="records-header__title">培训佐证文件</span>
|
|
</div>
|
|
<div class="evidence-files__list">
|
|
<div v-for="ev in evidences" :key="ev.id" class="evidence-file">
|
|
<span class="evidence-file__icon" :class="`is-${ev.kind}`">
|
|
<svg v-if="ev.kind === 'sign_photo'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><circle cx="9" cy="10" r="1.6"/><path d="m5 19 5.2-5.2a1.4 1.4 0 0 1 2 0L17 18.5"/><path d="M14.5 15.5 16 14a1.4 1.4 0 0 1 2 0l3 3"/></svg>
|
|
<svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="12" rx="2"/><path d="m10 8.6 4 2.4-4 2.4z"/><path d="M8 21h8M12 17v4"/></svg>
|
|
</span>
|
|
<div class="evidence-file__meta">
|
|
<span class="evidence-file__name" :title="ev.name">{{ ev.name }}</span>
|
|
<span class="evidence-file__sub">{{ ev.kind === 'sign_photo' ? '签到照' : '培训视频' }} · {{ fmtSize(ev.size) }} · {{ fmtTime(ev.created_at) }}</span>
|
|
</div>
|
|
<t-button variant="text" theme="primary" size="small" @click="onPreviewEvidence(ev)">预览</t-button>
|
|
<t-popconfirm v-if="canUpload" content="确定删除该佐证文件?" theme="danger" @confirm="onDeleteEvidence(ev)">
|
|
<t-button variant="text" theme="danger" size="small">删除</t-button>
|
|
</t-popconfirm>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 签到明细 -->
|
|
<div class="records-header">
|
|
<span class="records-header__title">签到明细</span>
|
|
<t-button v-if="canReview && signCode" variant="outline" size="small" @click="proxyVisible = true">补录</t-button>
|
|
</div>
|
|
<t-table :data="pagedRecords" :columns="recordColumns" row-key="id" size="small" :loading="loading">
|
|
<template #member="{ row }">{{ memberLabel(row.member_id) }}</template>
|
|
<template #signed_at="{ row }">{{ fmtRecordTime(row.signed_at) }}</template>
|
|
<template #channel="{ row }">{{ channelText(row.channel) }}</template>
|
|
<template #status="{ row }">
|
|
<t-tag :theme="statusTheme(row.status)" variant="light" size="small">{{ statusText(row.status) }}</t-tag>
|
|
<t-tag v-for="f in row.abnormal_flags || []" :key="f" theme="danger" variant="outline" size="small" class="flag-tag">{{ flagText(f) }}</t-tag>
|
|
</template>
|
|
<template #op="{ row }">
|
|
<template v-if="canReview && row.status !== 'normal'">
|
|
<t-button variant="text" theme="primary" size="small" @click="onReview(row, 'confirm')">确认</t-button>
|
|
<t-button variant="text" theme="danger" size="small" @click="onReview(row, 'reject')">驳回</t-button>
|
|
</template>
|
|
</template>
|
|
</t-table>
|
|
<!-- 共用分页(000163):默认每页 15 条 -->
|
|
<TrainingPagination v-model:current="recordPage" v-model:page-size="recordPageSize" :total="recordTotal" />
|
|
|
|
<!-- 补录:走同一防伪规则引擎,proxy 标记留痕 -->
|
|
<t-dialog v-model:visible="proxyVisible" header="现场补录" width="460">
|
|
<t-form label-width="90">
|
|
<t-form-item label="学员" required>
|
|
<t-select v-model="proxyMemberId" filterable placeholder="选择要补录的学员" style="width: 100%">
|
|
<t-option v-for="m in members" :key="m.id" :value="m.id" :label="memberLabelText(m)" />
|
|
</t-select>
|
|
</t-form-item>
|
|
</t-form>
|
|
<div class="form-hint">代录与本人扫码走同一校验(有效期/名单/定位/迟到),记录带 proxy 标记可追溯。</div>
|
|
<template #footer>
|
|
<t-button theme="primary" :loading="proxyLoading" :disabled="!proxyMemberId" @click="onProxyCheckin">完成签到</t-button>
|
|
</template>
|
|
</t-dialog>
|
|
|
|
<!-- 佐证预览:照片直接展示,视频 blob 播放 -->
|
|
<t-dialog v-model:visible="previewVisible" :header="previewEvidence?.name || '佐证预览'" width="720">
|
|
<div class="preview-box">
|
|
<t-loading :loading="previewLoading" class="preview-box__wrap">
|
|
<img v-if="previewEvidence?.kind === 'sign_photo' && previewUrl" :src="previewUrl" class="preview-box__img" alt="签到照" />
|
|
<video v-else-if="previewEvidence?.kind === 'training_video' && previewUrl" :src="previewUrl" class="preview-box__video" controls playsinline />
|
|
<t-empty v-else-if="!previewLoading" description="文件加载失败" />
|
|
</t-loading>
|
|
</div>
|
|
<template #footer>
|
|
<t-button variant="outline" @click="previewVisible = false">关闭</t-button>
|
|
</template>
|
|
</t-dialog>
|
|
|
|
<!-- 佐证导出 -->
|
|
<div class="evidence-bar">
|
|
<div>
|
|
<div class="evidence-bar__title">一键导出 · 请款佐证包</div>
|
|
<div class="muted">导出字段:部门 · 工号 · 姓名 · 签到时间 · 讲师姓名 · 课程名称 · 上课时间 · 学员考试成绩</div>
|
|
</div>
|
|
<t-button theme="primary" :loading="exportLoading" @click="onExport">导出佐证包(Excel)</t-button>
|
|
</div>
|
|
</template>
|
|
<t-empty v-else description="请选择课程场次查看签到情况" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
import { MessagePlugin } from 'tdesign-vue-next'
|
|
import QRCode from 'qrcode'
|
|
import {
|
|
checkin,
|
|
createSignCode,
|
|
deleteSessionEvidence,
|
|
downloadSessionEvidenceFile,
|
|
exportEvidence,
|
|
getSignCode,
|
|
getSignSummary,
|
|
listCourses,
|
|
listMembers,
|
|
listSessions,
|
|
listSessionEvidence,
|
|
listSignRecords,
|
|
reviewSignRecord,
|
|
uploadSessionEvidence,
|
|
type SignSummary,
|
|
type TrainingCourse,
|
|
type TrainingCourseSession,
|
|
type TrainingMember,
|
|
type TrainingSessionEvidence,
|
|
type TrainingSignCode,
|
|
type TrainingSignRecord,
|
|
unwrap,
|
|
} from '@/api/training'
|
|
import { fmtBeijingClock, fmtBeijingTime, fmtBeijingTimeSec } from '@/utils/datetime'
|
|
import TrainingPagination from './TrainingPagination.vue'
|
|
import { useTrainingPager } from './useTrainingPager'
|
|
|
|
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
// 签到复核/代签:人事/课长(roles 已按权限组展开,经理自动命中)
|
|
const canReview = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor'))
|
|
// 佐证上传/删除:人事/课长/讲师(与课件上传同口径)
|
|
const canUpload = computed(() => props.admin || props.roles.some((r) => r === 'hr' || r === 'supervisor' || r === 'lecturer'))
|
|
|
|
// 客户端预检上限提示(服务端同口径硬限制:文档 50MB/视频 200MB)
|
|
const PHOTO_MAX_MB = 50
|
|
const VIDEO_MAX_MB = 200
|
|
|
|
const loading = ref(false)
|
|
const genLoading = ref(false)
|
|
const exportLoading = ref(false)
|
|
const sessions = ref<TrainingCourseSession[]>([])
|
|
const courses = ref<TrainingCourse[]>([])
|
|
const selectedSessionId = ref('')
|
|
// 当前选中场次的课程 id:「培训详情」卡片回跳课程学习详情页用(2026-11 需求)
|
|
const selectedCourseId = computed(
|
|
() => sessions.value.find((s) => s.id === selectedSessionId.value)?.course_id || '',
|
|
)
|
|
// 培训详情:携课程 id 跳「培训签到」页的同源落地页(课程学习详情)。
|
|
const goCourseDetail = () => {
|
|
if (!selectedCourseId.value) return
|
|
router.push({ path: `/platform/training/course/${selectedCourseId.value}` })
|
|
}
|
|
const signCode = ref<TrainingSignCode | null>(null)
|
|
const summary = ref<SignSummary | null>(null)
|
|
const records = ref<TrainingSignRecord[]>([])
|
|
|
|
// 签到明细分页(000163):默认每页 15 条;切换场次后回到第 1 页
|
|
const {
|
|
page: recordPage,
|
|
pageSize: recordPageSize,
|
|
total: recordTotal,
|
|
paged: pagedRecords,
|
|
reset: resetRecordPage,
|
|
} = useTrainingPager(records)
|
|
|
|
const recordColumns = [
|
|
{ colKey: 'member', title: '学员', width: 220 },
|
|
{ colKey: 'signed_at', title: '签到时间', width: 170 },
|
|
{ colKey: 'channel', title: '方式', width: 110 },
|
|
{ colKey: 'distance_m', title: '定位距离(m)', width: 110 },
|
|
{ colKey: 'status', title: '状态' },
|
|
{ colKey: 'op', title: '操作', width: 140 },
|
|
]
|
|
|
|
const statusText = (s: string) => ({
|
|
normal: '已签到', late: '迟到', abnormal: '待复核', outside: '定位异常', duplicate: '重复扫码', missing: '未签到',
|
|
}[s] || s)
|
|
|
|
const statusTheme = (s: string) => ({
|
|
normal: 'success', late: 'warning', abnormal: 'danger', outside: 'danger', duplicate: 'danger', missing: 'default',
|
|
}[s] || 'default')
|
|
|
|
// 签到明细列展示口径(000165):
|
|
// 签到时间 → 北京时间「YYYY/MM/DD HH:mm:ss」(带秒)
|
|
// 方式 → 中文(企微扫码/代扫码补录),未知值回退原文
|
|
const fmtRecordTime = (raw: string | null) => fmtBeijingTimeSec(raw) || '—'
|
|
const channelText = (c: string) => ({ wecom_scan: '企微扫码', proxy: '代扫码/补录' }[c] || c)
|
|
|
|
// 签到二维码:内容为学员扫码签到页链接(携带 token),本地生成不依赖外网服务;
|
|
// 签到码刷新/切换场次后自动重绘。
|
|
const signQrUrl = ref('')
|
|
const buildSignQr = async () => {
|
|
const token = signCode.value?.token
|
|
if (!token) {
|
|
signQrUrl.value = ''
|
|
return
|
|
}
|
|
const url = `${window.location.origin}/m/training/checkin/${token}`
|
|
try {
|
|
signQrUrl.value = await QRCode.toDataURL(url, { width: 320, margin: 1 })
|
|
} catch {
|
|
signQrUrl.value = ''
|
|
}
|
|
}
|
|
watch(signCode, buildSignQr, { immediate: true })
|
|
|
|
// 二维码地址预检:企微 OAuth 要求 redirect_uri 使用应用可信域名,二维码内容
|
|
// 取本页 origin —— 若讲师在本机/内网地址打开培训签到页,学员扫码必然失败。
|
|
// 启发式与后端 checkin-auth 预检同口径(localhost/内网 IP/单标签/伪域名)。
|
|
const qrOriginHost = window.location.hostname.toLowerCase()
|
|
const qrOriginWarn = (() => {
|
|
const h = qrOriginHost
|
|
if (h === 'localhost' || h === '127.0.0.1' || h === '::1' || !h.includes('.')) return true
|
|
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(h)) {
|
|
const [a, b] = h.split('.').map(Number)
|
|
if (a === 127 || a === 10 || a === 192) return true
|
|
if (a === 172 && b >= 16 && b <= 31) return true
|
|
if (a === 169 && b === 254) return true
|
|
}
|
|
return /\.(local|lan|internal|localhost)$/.test(h)
|
|
})()
|
|
|
|
// ---- 签到码自动轮换(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 || '课程'
|
|
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '—'
|
|
// 签到码有效期只展示时分(测试反馈 2026-11-26:去掉年月日)
|
|
const fmtClock = (raw: string | null) => fmtBeijingClock(raw) || '—'
|
|
|
|
const memberLabels = ref<Record<string, string>>({})
|
|
const members = ref<TrainingMember[]>([])
|
|
const proxyVisible = ref(false)
|
|
const proxyMemberId = ref('')
|
|
const proxyLoading = ref(false)
|
|
|
|
// 学员展示口径(000165):「姓名 工号」;未入名册时回退 member_id 前缀
|
|
const memberLabel = (memberId: string) => memberLabels.value[memberId] || memberId
|
|
const memberLabelText = (m: TrainingMember) =>
|
|
[m.user_name || m.employee_no || '-', m.employee_no && m.user_name ? m.employee_no : '']
|
|
.filter(Boolean)
|
|
.join(' ')
|
|
|
|
const loadAll = async () => {
|
|
loading.value = true
|
|
try {
|
|
const [s, c, m] = await Promise.all([
|
|
listSessions({ page_size: 200 }),
|
|
listCourses({ page_size: 200 }),
|
|
listMembers({ page_size: 500 }).catch(() => null),
|
|
])
|
|
sessions.value = unwrap(s) || []
|
|
courses.value = unwrap(c)?.items || []
|
|
const memberItems = (m && unwrap(m)?.items) || []
|
|
if (memberItems.length) {
|
|
members.value = memberItems
|
|
const labels: Record<string, string> = {}
|
|
for (const mem of members.value) {
|
|
// 签到明细学员列(000165):「姓名 工号」,无姓名时回退工号
|
|
labels[mem.id] = [mem.user_name || '', mem.employee_no || ''].filter(Boolean).join(' ') || mem.id.slice(0, 8)
|
|
}
|
|
memberLabels.value = labels
|
|
}
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const loadSessionData = async () => {
|
|
if (!selectedSessionId.value) return
|
|
const sid = selectedSessionId.value
|
|
resetRecordPage()
|
|
try {
|
|
const [code, sum, recs, evs] = await Promise.all([
|
|
getSignCode(sid).catch(() => null),
|
|
getSignSummary(sid).catch(() => null),
|
|
listSignRecords(sid),
|
|
listSessionEvidence(sid).catch(() => null),
|
|
])
|
|
signCode.value = unwrap(code) || null
|
|
summary.value = unwrap(sum) || null
|
|
records.value = unwrap(recs) || []
|
|
evidences.value = (evs && unwrap(evs)) || []
|
|
} catch {
|
|
records.value = []
|
|
}
|
|
}
|
|
|
|
// ---- 培训佐证文件(签到照/培训视频) ----
|
|
const evidences = ref<TrainingSessionEvidence[]>([])
|
|
const photoInput = ref<HTMLInputElement | null>(null)
|
|
const videoInput = ref<HTMLInputElement | null>(null)
|
|
const uploading = ref(false)
|
|
|
|
const evidenceCount = (kind: TrainingSessionEvidence['kind']) =>
|
|
evidences.value.filter((e) => e.kind === kind).length
|
|
|
|
const fmtSize = (size: number) => {
|
|
if (!size) return '-'
|
|
return size >= 1024 * 1024 ? `${(size / 1024 / 1024).toFixed(1)}MB` : `${Math.ceil(size / 1024)}KB`
|
|
}
|
|
|
|
const onEvidenceFiles = async (e: Event, kind: TrainingSessionEvidence['kind']) => {
|
|
const input = e.target as HTMLInputElement
|
|
const files = Array.from(input.files || [])
|
|
input.value = ''
|
|
if (!files.length || !selectedSessionId.value) return
|
|
const limitMB = kind === 'sign_photo' ? PHOTO_MAX_MB : VIDEO_MAX_MB
|
|
const oversize = files.filter((f) => f.size > limitMB * 1024 * 1024)
|
|
if (oversize.length) {
|
|
MessagePlugin.warning(`文件大小不能超过${limitMB}MB:${oversize.map((f) => f.name).join('、')}`)
|
|
return
|
|
}
|
|
uploading.value = true
|
|
let ok = 0
|
|
let fail = 0
|
|
try {
|
|
for (const file of files) {
|
|
try {
|
|
const fd = new FormData()
|
|
fd.append('file', file)
|
|
fd.append('kind', kind)
|
|
fd.append('name', file.name)
|
|
await uploadSessionEvidence(selectedSessionId.value, fd)
|
|
ok += 1
|
|
} catch {
|
|
fail += 1
|
|
}
|
|
}
|
|
if (ok) MessagePlugin.success(`已上传 ${ok} 个${kind === 'sign_photo' ? '签到照' : '培训视频'}并归档到场次佐证`)
|
|
if (fail) MessagePlugin.error(`${fail} 个文件上传失败,请稍后重试`)
|
|
await loadSessionData()
|
|
} finally {
|
|
uploading.value = false
|
|
}
|
|
}
|
|
|
|
const previewVisible = ref(false)
|
|
const previewLoading = ref(false)
|
|
const previewEvidence = ref<TrainingSessionEvidence | null>(null)
|
|
const previewUrl = ref('')
|
|
let previewObjectUrl = ''
|
|
|
|
const onPreviewEvidence = async (ev: TrainingSessionEvidence) => {
|
|
previewEvidence.value = ev
|
|
previewUrl.value = ''
|
|
previewVisible.value = true
|
|
previewLoading.value = true
|
|
try {
|
|
const blob = await downloadSessionEvidenceFile(ev.id)
|
|
previewObjectUrl = URL.createObjectURL(blob)
|
|
previewUrl.value = previewObjectUrl
|
|
} catch {
|
|
previewUrl.value = ''
|
|
} finally {
|
|
previewLoading.value = false
|
|
}
|
|
}
|
|
|
|
const onDeleteEvidence = async (ev: TrainingSessionEvidence) => {
|
|
try {
|
|
await deleteSessionEvidence(ev.id)
|
|
MessagePlugin.success('佐证文件已删除')
|
|
loadSessionData()
|
|
} catch {
|
|
MessagePlugin.error('删除失败')
|
|
}
|
|
}
|
|
|
|
const onGenCode = async () => {
|
|
genLoading.value = true
|
|
try {
|
|
const res = await createSignCode(selectedSessionId.value)
|
|
signCode.value = unwrap(res) || null
|
|
MessagePlugin.success('签到码已生成,学员企微扫码/点击链接即可签到')
|
|
} catch {
|
|
MessagePlugin.error('生成失败')
|
|
} finally {
|
|
genLoading.value = false
|
|
}
|
|
}
|
|
|
|
const onReview = async (row: TrainingSignRecord, decision: 'confirm' | 'reject') => {
|
|
try {
|
|
await reviewSignRecord(row.id, decision)
|
|
MessagePlugin.success(decision === 'confirm' ? '已确认签到有效' : '已维持异常标记')
|
|
loadSessionData()
|
|
} catch {
|
|
MessagePlugin.error('操作失败')
|
|
}
|
|
}
|
|
|
|
const onProxyCheckin = async () => {
|
|
if (!signCode.value || !proxyMemberId.value) return
|
|
proxyLoading.value = true
|
|
try {
|
|
await checkin(signCode.value.token, 0, 0, 'proxy', proxyMemberId.value)
|
|
MessagePlugin.success('代录签到完成')
|
|
proxyVisible.value = false
|
|
proxyMemberId.value = ''
|
|
loadSessionData()
|
|
} catch (e: any) {
|
|
MessagePlugin.error(e?.response?.data?.message || '代录失败')
|
|
} finally {
|
|
proxyLoading.value = false
|
|
}
|
|
}
|
|
|
|
const onExport = async () => {
|
|
exportLoading.value = true
|
|
try {
|
|
const res = await exportEvidence([selectedSessionId.value])
|
|
const blob = new Blob([res.data as unknown as BlobPart], {
|
|
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
})
|
|
const url = URL.createObjectURL(blob)
|
|
const a = document.createElement('a')
|
|
a.href = url
|
|
a.download = `training_evidence_${new Date().toISOString().slice(0, 10)}.xlsx`
|
|
a.click()
|
|
URL.revokeObjectURL(url)
|
|
MessagePlugin.success('佐证包已导出')
|
|
} catch {
|
|
MessagePlugin.error('导出失败')
|
|
} finally {
|
|
exportLoading.value = false
|
|
}
|
|
}
|
|
|
|
// 培训课程页课程名称跳转:携带 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()
|
|
// 签到码轮换:进页即启动(选中场次后 watch 也会重启,双保险覆盖异步加载)。
|
|
startCodeRotation()
|
|
})
|
|
|
|
onUnmounted(stopCodeRotation)
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
@import (reference) '../training.less';
|
|
|
|
.panel-box {
|
|
.training-panel-box();
|
|
|
|
&__header {
|
|
margin-bottom: 14px;
|
|
}
|
|
}
|
|
|
|
.sign-top {
|
|
display: grid;
|
|
grid-template-columns: 280px 1fr;
|
|
gap: 12px;
|
|
margin-bottom: 14px;
|
|
|
|
@media (max-width: 900px) {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
|
|
.sign-code-box {
|
|
background: var(--td-bg-color-secondarycontainer);
|
|
border: 1px dashed var(--td-component-border);
|
|
border-radius: var(--app-radius-md);
|
|
padding: 14px;
|
|
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;
|
|
font-size: var(--app-text-md);
|
|
word-break: break-all;
|
|
background: var(--td-bg-color-container);
|
|
border-radius: var(--app-radius-sm);
|
|
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 {
|
|
.training-stat-cards();
|
|
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.stat-card {
|
|
.training-stat-card();
|
|
}
|
|
|
|
// 佐证上传卡片:点击选择文件,与统计卡片同区栅格
|
|
.upload-card {
|
|
cursor: pointer;
|
|
transition: box-shadow var(--app-motion-fast) ease, transform var(--app-motion-fast) ease;
|
|
|
|
&:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: var(--app-shadow-1, 0 6px 16px rgba(0, 0, 0, 0.08));
|
|
}
|
|
|
|
&:focus-visible {
|
|
outline: 2px solid var(--td-brand-color);
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
&.is-uploading {
|
|
opacity: 0.6;
|
|
pointer-events: none;
|
|
}
|
|
|
|
&__main {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
margin: 10px 0 6px;
|
|
color: var(--td-brand-color);
|
|
font-weight: 600;
|
|
|
|
svg {
|
|
width: 26px;
|
|
height: 26px;
|
|
}
|
|
}
|
|
|
|
&__hint {
|
|
color: var(--td-text-color-placeholder);
|
|
font-size: var(--app-text-sm);
|
|
}
|
|
}
|
|
|
|
// 隐藏的文件选择 input(卡片点击触发)
|
|
.visually-hidden-input {
|
|
position: absolute;
|
|
width: 1px;
|
|
height: 1px;
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
}
|
|
|
|
// 佐证文件列表
|
|
.evidence-files {
|
|
margin-bottom: 14px;
|
|
|
|
&__list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
}
|
|
}
|
|
|
|
.evidence-file {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
padding: 8px 12px;
|
|
border: 1px solid var(--td-component-stroke);
|
|
border-radius: var(--app-radius-md);
|
|
background: var(--td-bg-color-secondarycontainer);
|
|
|
|
&__icon {
|
|
display: inline-flex;
|
|
color: var(--td-brand-color);
|
|
|
|
svg {
|
|
width: 20px;
|
|
height: 20px;
|
|
}
|
|
|
|
&.is-training_video {
|
|
color: var(--td-success-color);
|
|
}
|
|
}
|
|
|
|
&__meta {
|
|
flex: 1;
|
|
min-width: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
&__name {
|
|
color: var(--td-text-color-primary);
|
|
font-size: var(--app-text-md);
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
&__sub {
|
|
color: var(--td-text-color-placeholder);
|
|
font-size: var(--app-text-sm);
|
|
}
|
|
}
|
|
|
|
// 佐证预览弹窗
|
|
.preview-box {
|
|
&__wrap {
|
|
display: block;
|
|
min-height: 160px;
|
|
}
|
|
|
|
&__img {
|
|
display: block;
|
|
max-width: 100%;
|
|
max-height: 60vh;
|
|
margin: 0 auto;
|
|
border-radius: var(--app-radius-md);
|
|
}
|
|
|
|
&__video {
|
|
display: block;
|
|
width: 100%;
|
|
max-height: 60vh;
|
|
border-radius: var(--app-radius-md);
|
|
background: #000;
|
|
}
|
|
}
|
|
|
|
.tone-good { color: var(--td-success-color); }
|
|
.tone-warn { color: var(--td-warning-color); }
|
|
.tone-bad { color: var(--td-error-color); }
|
|
|
|
.flag-tag { margin-left: 4px; }
|
|
|
|
.evidence-bar {
|
|
margin-top: 14px;
|
|
background: var(--td-brand-color-1, rgba(0, 82, 217, 0.06));
|
|
border-radius: var(--app-radius-md);
|
|
padding: 14px 16px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
|
|
&__title { font-weight: 600; margin-bottom: 2px; }
|
|
}
|
|
|
|
.muted { color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); }
|
|
|
|
.records-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 8px;
|
|
|
|
&__title { font-weight: 600; }
|
|
}
|
|
|
|
.form-hint {
|
|
margin-top: 8px;
|
|
color: var(--td-text-color-placeholder);
|
|
font-size: var(--app-text-sm);
|
|
}
|
|
</style>
|