feat(duty): add web-admin calendar page and public H5 grab UI
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
36fc7f286c
commit
35e09fa09b
9 files changed
+3152
No files matched your search
@@ -0,0 +1,454 @@
|
||||
<template>
|
||||
<div class="duty-h5">
|
||||
<div v-if="loading" class="state">加载中…</div>
|
||||
<div v-else-if="errorType === 'invalid'" class="state">
|
||||
<div class="icon">?</div>
|
||||
<h2>链接无效或已失效</h2>
|
||||
<p>请确认是否复制完整,或向管理员重新索取当日值班链接。</p>
|
||||
</div>
|
||||
<div v-else-if="errorType === 'closed' || page?.linkStatus === 'closed' || page?.closed" class="state">
|
||||
<div class="icon off">⊘</div>
|
||||
<h2>报名已关闭</h2>
|
||||
<p>管理员已关闭本链接,暂时无法继续抢班。</p>
|
||||
<div v-if="page?.dutyDate" class="card">
|
||||
<div class="kv"><span>日期</span><span>{{ page.dutyDate }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="success" class="page">
|
||||
<header class="header">
|
||||
<div class="eyebrow">山峡化工 · 值班抢班</div>
|
||||
<h1>报名成功</h1>
|
||||
<p class="sub">请按时到岗。如需调整请联系管理员。</p>
|
||||
</header>
|
||||
<div class="body state-ok">
|
||||
<div class="icon ok">✓</div>
|
||||
<h2>已抢到{{ success.shiftLabel }}</h2>
|
||||
<p>{{ success.dutyDate }}</p>
|
||||
<div class="card">
|
||||
<div class="kv"><span>日期</span><span>{{ success.dutyDate }}</span></div>
|
||||
<div class="kv"><span>班次</span><span>{{ success.shiftLabel }}</span></div>
|
||||
<div class="kv"><span>姓名</span><span>{{ success.personName }}</span></div>
|
||||
</div>
|
||||
<button type="button" class="btn secondary" @click="backToList">返回查看当日班次</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="page" class="page">
|
||||
<header class="header">
|
||||
<div class="eyebrow">山峡化工 · 值班抢班</div>
|
||||
<h1>{{ formatTitle(page.dutyDate) }}</h1>
|
||||
<p class="sub">无需登录,填写姓名后选择班次提交。名额满了就不能再抢。</p>
|
||||
<div class="meta">
|
||||
<span class="pill">{{ weekdayLabel(page.dutyDate) }}</span>
|
||||
<span class="pill">链接有效</span>
|
||||
<span class="pill">剩余 {{ remainTotal }} 个名额</span>
|
||||
</div>
|
||||
</header>
|
||||
<div class="body">
|
||||
<div class="tip">提示:同名可能重复,请填写真实姓名;提交后如需改动请联系管理员。</div>
|
||||
<section v-for="slot in page.slots" :key="slot.shiftType" class="slot">
|
||||
<div class="slot-hd">
|
||||
<div class="title">
|
||||
<i class="dot" :class="slot.shiftType" />
|
||||
{{ slot.shiftLabel || slot.shiftType }}
|
||||
</div>
|
||||
<span class="badge" :class="isFull(slot) ? 'full' : 'open'">
|
||||
{{ isFull(slot) ? '已满' : '可抢' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="cap">
|
||||
<span>名额</span>
|
||||
<strong>{{ slot.taken }} / {{ slot.capacity }}</span>
|
||||
</div>
|
||||
<div class="bar"><i :style="{ width: barWidth(slot) }" :class="slot.shiftType" /></div>
|
||||
<div class="people">
|
||||
<span v-for="(a, i) in slot.assignments" :key="i" class="person">{{ a.personName }}</span>
|
||||
<span v-if="!slot.assignments?.length" class="person empty">暂无人报名</span>
|
||||
<span v-else-if="slot.capacity - slot.taken > 0" class="person empty"
|
||||
>空缺 {{ slot.capacity - slot.taken }}</span
|
||||
>
|
||||
</div>
|
||||
<template v-if="!isFull(slot)">
|
||||
<label class="field">
|
||||
<span>您的姓名</span>
|
||||
<input v-model="names[slot.shiftType]" maxlength="20" placeholder="请输入真实姓名" />
|
||||
</label>
|
||||
<button type="button" class="btn" :disabled="submitting" @click="grab(slot)">
|
||||
提交抢班
|
||||
</button>
|
||||
</template>
|
||||
<button v-else type="button" class="btn" disabled>名额已满</button>
|
||||
</section>
|
||||
</div>
|
||||
<footer class="note">提交即表示确认当日可到岗值班<br />链接由管理员分享 · 请勿转发无关人员</footer>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import {
|
||||
publicDutyApi,
|
||||
type PublicDutyGrabResult,
|
||||
type PublicDutyPage,
|
||||
type PublicDutySlot
|
||||
} from '@/api/public-duty'
|
||||
|
||||
defineOptions({ name: 'PublicDutyGrab' })
|
||||
|
||||
const route = useRoute()
|
||||
const loading = ref(true)
|
||||
const submitting = ref(false)
|
||||
const errorType = ref<'invalid' | 'closed' | ''>('')
|
||||
const page = ref<PublicDutyPage | null>(null)
|
||||
const success = ref<PublicDutyGrabResult | null>(null)
|
||||
const names = reactive<Record<string, string>>({})
|
||||
|
||||
const token = computed(() => String(route.params.token || ''))
|
||||
|
||||
const remainTotal = computed(() => {
|
||||
if (!page.value?.slots) return 0
|
||||
return page.value.slots.reduce((sum, s) => sum + Math.max(0, s.capacity - s.taken), 0)
|
||||
})
|
||||
|
||||
function isFull(slot: PublicDutySlot) {
|
||||
return (slot.taken || 0) >= (slot.capacity || 0)
|
||||
}
|
||||
|
||||
function barWidth(slot: PublicDutySlot) {
|
||||
if (!slot.capacity) return '0%'
|
||||
return `${Math.min(100, Math.round((slot.taken / slot.capacity) * 100))}%`
|
||||
}
|
||||
|
||||
function formatTitle(dutyDate: string) {
|
||||
const d = dutyDate?.split('-')
|
||||
if (!d || d.length < 3) return '值班'
|
||||
return `${Number(d[1])}月${Number(d[2])}日 值班`
|
||||
}
|
||||
|
||||
function weekdayLabel(dutyDate: string) {
|
||||
const map = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
||||
const dt = new Date(dutyDate.replace(/-/g, '/'))
|
||||
if (Number.isNaN(dt.getTime())) return ''
|
||||
return map[dt.getDay()]
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
errorType.value = ''
|
||||
success.value = null
|
||||
try {
|
||||
const data = await publicDutyApi.getPage(token.value)
|
||||
page.value = data
|
||||
if (data.linkStatus === 'closed' || data.closed) {
|
||||
errorType.value = 'closed'
|
||||
}
|
||||
for (const s of data.slots || []) {
|
||||
if (names[s.shiftType] === undefined) names[s.shiftType] = ''
|
||||
}
|
||||
} catch (e: any) {
|
||||
const msg = String(e?.message || e || '')
|
||||
if (msg.includes('关闭')) errorType.value = 'closed'
|
||||
else errorType.value = 'invalid'
|
||||
page.value = null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function grab(slot: PublicDutySlot) {
|
||||
const name = (names[slot.shiftType] || '').trim()
|
||||
if (!name) {
|
||||
window.alert('请先填写姓名')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const res = await publicDutyApi.grab(token.value, {
|
||||
shiftType: slot.shiftType,
|
||||
personName: name
|
||||
})
|
||||
success.value = res
|
||||
names[slot.shiftType] = ''
|
||||
} catch (e: any) {
|
||||
window.alert(e?.message || '提交失败')
|
||||
await load()
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function backToList() {
|
||||
success.value = null
|
||||
void load()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.duty-h5 {
|
||||
min-height: 100vh;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
|
||||
color: #1f2a26;
|
||||
background: #f5f8f7;
|
||||
}
|
||||
.page {
|
||||
max-width: 480px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.header {
|
||||
padding: 28px 18px 22px;
|
||||
color: #fff;
|
||||
background: linear-gradient(160deg, #0a9f6d 0%, #087f57 100%);
|
||||
border-radius: 0 0 22px 22px;
|
||||
}
|
||||
.eyebrow {
|
||||
margin-bottom: 6px;
|
||||
font-size: 12px;
|
||||
opacity: 0.88;
|
||||
}
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.sub {
|
||||
margin: 8px 0 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
opacity: 0.92;
|
||||
}
|
||||
.meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
.pill {
|
||||
padding: 4px 10px;
|
||||
font-size: 11px;
|
||||
background: rgba(255, 255, 255, 0.18);
|
||||
border: 1px solid rgba(255, 255, 255, 0.22);
|
||||
border-radius: 999px;
|
||||
}
|
||||
.body {
|
||||
padding: 14px 14px 28px;
|
||||
}
|
||||
.tip {
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 12px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: #8a6418;
|
||||
background: #fff7e8;
|
||||
border: 1px solid #f0dfb5;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.slot {
|
||||
margin-bottom: 12px;
|
||||
padding: 14px;
|
||||
background: #fff;
|
||||
border: 1px solid #dcebe4;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 1px 2px rgba(31, 42, 38, 0.04);
|
||||
}
|
||||
.slot-hd {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.title {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.dot.morning {
|
||||
background: #cf8a19;
|
||||
}
|
||||
.dot.evening {
|
||||
background: #3b82f6;
|
||||
}
|
||||
.dot.duty {
|
||||
background: #d14343;
|
||||
}
|
||||
.badge {
|
||||
padding: 3px 8px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
border-radius: 999px;
|
||||
}
|
||||
.badge.open {
|
||||
color: #087f57;
|
||||
background: #e9f9f2;
|
||||
}
|
||||
.badge.full {
|
||||
color: #6b7b74;
|
||||
background: #eef2f0;
|
||||
}
|
||||
.cap {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
font-size: 12px;
|
||||
color: #6b7b74;
|
||||
}
|
||||
.cap strong {
|
||||
font-size: 15px;
|
||||
color: #1f2a26;
|
||||
}
|
||||
.bar {
|
||||
height: 7px;
|
||||
margin-top: 8px;
|
||||
overflow: hidden;
|
||||
background: #e8f0ec;
|
||||
border-radius: 999px;
|
||||
}
|
||||
.bar > i {
|
||||
display: block;
|
||||
height: 100%;
|
||||
background: #0a9f6d;
|
||||
border-radius: 999px;
|
||||
}
|
||||
.bar > i.morning {
|
||||
background: #cf8a19;
|
||||
}
|
||||
.bar > i.evening {
|
||||
background: #3b82f6;
|
||||
}
|
||||
.bar > i.duty {
|
||||
background: #d14343;
|
||||
}
|
||||
.people {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.person {
|
||||
padding: 4px 9px;
|
||||
font-size: 12px;
|
||||
color: #6b7b74;
|
||||
background: #f3f7f5;
|
||||
border: 1px solid #dcebe4;
|
||||
border-radius: 999px;
|
||||
}
|
||||
.person.empty {
|
||||
color: #8a9a93;
|
||||
background: transparent;
|
||||
border-style: dashed;
|
||||
}
|
||||
.field {
|
||||
display: block;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.field span {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-size: 12px;
|
||||
color: #6b7b74;
|
||||
}
|
||||
.field input {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
padding: 0 12px;
|
||||
font-size: 15px;
|
||||
background: #fff;
|
||||
border: 1px solid #dcebe4;
|
||||
border-radius: 12px;
|
||||
outline: none;
|
||||
}
|
||||
.btn {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
margin-top: 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
background: #0a9f6d;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
background: #b7c5bf;
|
||||
}
|
||||
.btn.secondary {
|
||||
max-width: 280px;
|
||||
color: #087f57;
|
||||
background: #fff;
|
||||
border: 1px solid #0a9f6d;
|
||||
}
|
||||
.note {
|
||||
padding: 4px 16px 24px;
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
color: #8a9a93;
|
||||
text-align: center;
|
||||
}
|
||||
.state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 70vh;
|
||||
padding: 40px 28px;
|
||||
text-align: center;
|
||||
}
|
||||
.state-ok {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding-top: 28px;
|
||||
text-align: center;
|
||||
}
|
||||
.icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 34px;
|
||||
color: #0a9f6d;
|
||||
background: #e9f9f2;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.icon.off {
|
||||
color: #6b7b74;
|
||||
background: #eef2f0;
|
||||
}
|
||||
.card {
|
||||
width: 100%;
|
||||
max-width: 320px;
|
||||
margin-top: 22px;
|
||||
padding: 14px;
|
||||
text-align: left;
|
||||
background: #fff;
|
||||
border: 1px solid #dcebe4;
|
||||
border-radius: 14px;
|
||||
}
|
||||
.kv {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 6px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.kv span:first-child {
|
||||
color: #6b7b74;
|
||||
}
|
||||
.kv span:last-child {
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user