feat: 赛事管理页面状态根据时间自动计算
- 添加 calculateStatus 方法根据报名时间和比赛时间计算状态 - 状态显示不再依赖数据库字段,而是实时计算 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@@ -60,8 +60,8 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="status" label="状态" width="90" align="center">
|
<el-table-column prop="status" label="状态" width="90" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-tag :type="getStatusType(scope.row.status)" size="small">
|
<el-tag :type="getStatusType(calculateStatus(scope.row))" size="small">
|
||||||
{{ getStatusText(scope.row.status) }}
|
{{ getStatusText(calculateStatus(scope.row)) }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@@ -252,6 +252,19 @@ export default {
|
|||||||
return `${start} ~ ${end}`
|
return `${start} ~ ${end}`
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 根据时间计算赛事状态
|
||||||
|
calculateStatus(row) {
|
||||||
|
const now = new Date()
|
||||||
|
const regStart = row.registrationStartTime ? new Date(row.registrationStartTime) : null
|
||||||
|
const regEnd = row.registrationEndTime ? new Date(row.registrationEndTime) : null
|
||||||
|
const compStart = row.competitionStartTime ? new Date(row.competitionStartTime) : null
|
||||||
|
const compEnd = row.competitionEndTime ? new Date(row.competitionEndTime) : null
|
||||||
|
if (compEnd && now > compEnd) return 4
|
||||||
|
if (compStart && now >= compStart) return 3
|
||||||
|
if (regStart && regEnd && now >= regStart && now <= regEnd) return 2
|
||||||
|
return 1
|
||||||
|
},
|
||||||
|
|
||||||
getStatusType(status) {
|
getStatusType(status) {
|
||||||
const statusMap = {
|
const statusMap = {
|
||||||
1: 'info', // 未开始
|
1: 'info', // 未开始
|
||||||
|
|||||||
Reference in New Issue
Block a user