fix(培训课程):优化培训课程
This commit is contained in:
1 parent
e378e8b7fd
commit
aae041a0b4
19 files changed
+777
-188
No files matched your search
@@ -0,0 +1,187 @@
|
||||
<template>
|
||||
<!-- 学员扫码签到落地页:培训签到页二维码 → 企微/相机扫码直达,自动定位并提交签到 -->
|
||||
<div class="checkin-page">
|
||||
<div class="checkin-card">
|
||||
<div class="checkin-card__icon" :class="`is-${state}`">
|
||||
<!-- 定位中/提交中 -->
|
||||
<svg v-if="state === 'pending'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="3.2" />
|
||||
<path d="M12 2v3M12 19v3M2 12h3M19 12h3" />
|
||||
</svg>
|
||||
<!-- 成功 -->
|
||||
<svg v-else-if="state === 'success'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="m8.5 12.2 2.4 2.4 4.8-4.9" />
|
||||
</svg>
|
||||
<!-- 失败 -->
|
||||
<svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="M12 7.5V13" />
|
||||
<path d="M12 16.4h.01" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<h2 class="checkin-card__title">{{ title }}</h2>
|
||||
<p class="checkin-card__hint">{{ hint }}</p>
|
||||
|
||||
<t-tag v-if="record" :theme="record.status === 'normal' ? 'success' : 'warning'" variant="light" size="medium">
|
||||
{{ record.status === 'normal' ? '签到成功' : record.status === 'late' ? '迟到签到' : '已提交,待复核' }}
|
||||
</t-tag>
|
||||
|
||||
<div class="checkin-card__actions">
|
||||
<t-button v-if="state === 'error'" theme="primary" @click="submit">重新签到</t-button>
|
||||
<t-button variant="outline" @click="goTraining">前往企业培训</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { checkin, unwrap, type TrainingSignRecord } from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
type CheckinState = 'pending' | 'success' | 'error'
|
||||
const state = ref<CheckinState>('pending')
|
||||
const record = ref<TrainingSignRecord | null>(null)
|
||||
const errorMsg = ref('')
|
||||
// 定位坐标:拒绝授权/不可用时以 0,0 提交,由后端 sign_policy(强制定位)决定是否放行
|
||||
const geo = ref({ lat: 0, lng: 0 })
|
||||
|
||||
const title = computed(() => {
|
||||
if (state.value === 'pending') return '正在签到…'
|
||||
if (state.value === 'success') return '签到完成'
|
||||
return '签到失败'
|
||||
})
|
||||
const hint = computed(() => {
|
||||
if (state.value === 'pending') return '正在获取定位并提交签到,请保持页面打开'
|
||||
if (state.value === 'success') return `签到时间:${fmtBeijingTime(record.value?.signed_at || null) || '—'}`
|
||||
return errorMsg.value || '签到码无效或已过期,请联系讲师刷新签到码'
|
||||
})
|
||||
|
||||
// 取定位:最多等 6 秒,失败不阻塞签到(是否强制定位由后端规则决定)
|
||||
const locate = () =>
|
||||
new Promise<void>((resolve) => {
|
||||
if (!navigator.geolocation) return resolve()
|
||||
const timer = window.setTimeout(resolve, 6000)
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(pos) => {
|
||||
window.clearTimeout(timer)
|
||||
geo.value = { lat: pos.coords.latitude, lng: pos.coords.longitude }
|
||||
resolve()
|
||||
},
|
||||
() => {
|
||||
window.clearTimeout(timer)
|
||||
MessagePlugin.warning('未获取到定位,如课程开启定位校验将无法签到')
|
||||
resolve()
|
||||
},
|
||||
{ timeout: 5500, maximumAge: 30000 },
|
||||
)
|
||||
})
|
||||
|
||||
const submit = async () => {
|
||||
state.value = 'pending'
|
||||
const token = String(route.params.token || '')
|
||||
if (!token) {
|
||||
state.value = 'error'
|
||||
errorMsg.value = '签到链接不完整'
|
||||
return
|
||||
}
|
||||
await locate()
|
||||
try {
|
||||
const res = await checkin(token, geo.value.lat, geo.value.lng, 'wecom_scan')
|
||||
record.value = (unwrap(res) as TrainingSignRecord | undefined) || null
|
||||
state.value = 'success'
|
||||
} catch (e: any) {
|
||||
state.value = 'error'
|
||||
errorMsg.value = e?.response?.data?.message || '签到码无效或已过期,请联系讲师刷新签到码'
|
||||
}
|
||||
}
|
||||
|
||||
const goTraining = () => {
|
||||
router.push('/platform/training/dashboard')
|
||||
}
|
||||
|
||||
onMounted(submit)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.checkin-page {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 60vh;
|
||||
padding: var(--app-space-4);
|
||||
}
|
||||
|
||||
.checkin-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: min(420px, 100%);
|
||||
padding: 40px 32px;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-lg, 12px);
|
||||
text-align: center;
|
||||
|
||||
&__icon {
|
||||
display: inline-flex;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
|
||||
svg {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
&.is-pending {
|
||||
color: var(--td-brand-color);
|
||||
background: var(--td-brand-color-1, rgba(0, 82, 217, 0.08));
|
||||
animation: checkin-breath 1.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
&.is-success {
|
||||
color: var(--td-success-color);
|
||||
background: var(--td-success-color-1, rgba(0, 168, 112, 0.08));
|
||||
}
|
||||
|
||||
&.is-error {
|
||||
color: var(--td-error-color);
|
||||
background: var(--td-error-color-1, rgba(227, 77, 89, 0.08));
|
||||
}
|
||||
}
|
||||
|
||||
&__title {
|
||||
margin: 4px 0 0;
|
||||
font-size: var(--app-text-xl, 20px);
|
||||
}
|
||||
|
||||
&__hint {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-md);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes checkin-breath {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.55; }
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user