2026-03-30 18:08:27 +08:00
|
|
|
|
function formatDateTime(iso) {
|
|
|
|
|
|
if (!iso || typeof iso !== 'string') return '-';
|
|
|
|
|
|
// expected format: 2026-03-30T12:34:56
|
|
|
|
|
|
const s = iso.replace('T', ' ').replace('Z', '');
|
|
|
|
|
|
if (s.length > 19) return s.slice(0, 19);
|
|
|
|
|
|
return s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 23:27:35 +08:00
|
|
|
|
function formatTime(iso) {
|
|
|
|
|
|
if (!iso || typeof iso !== 'string') return '-';
|
|
|
|
|
|
const s = iso.replace('T', ' ').replace('Z', '');
|
|
|
|
|
|
// 返回 yyyy-MM-dd HH:mm 格式
|
|
|
|
|
|
if (s.length >= 16) return s.slice(0, 16);
|
|
|
|
|
|
return s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-30 18:08:27 +08:00
|
|
|
|
function eventStatusText(status) {
|
2026-04-07 16:47:13 +08:00
|
|
|
|
// 与后端 EventStatus 枚举一致
|
|
|
|
|
|
const strMap = {
|
|
|
|
|
|
NotStarted: '未开始',
|
|
|
|
|
|
Enrolling: '报名中',
|
|
|
|
|
|
RegistrationEnded: '报名结束',
|
|
|
|
|
|
Ongoing: '比赛中',
|
|
|
|
|
|
Ended: '已结束'
|
2026-03-30 18:08:27 +08:00
|
|
|
|
};
|
2026-04-07 16:47:13 +08:00
|
|
|
|
if (strMap[status] != null) return strMap[status];
|
|
|
|
|
|
|
|
|
|
|
|
const n = status === undefined || status === null || status === '' ? NaN : Number(status);
|
|
|
|
|
|
const numMap = {
|
|
|
|
|
|
0: '未开始',
|
|
|
|
|
|
1: '报名中',
|
|
|
|
|
|
2: '报名结束',
|
|
|
|
|
|
3: '比赛中',
|
|
|
|
|
|
4: '已结束'
|
|
|
|
|
|
};
|
|
|
|
|
|
if (!Number.isNaN(n) && numMap[n] !== undefined) return numMap[n];
|
|
|
|
|
|
return status !== undefined && status !== null && status !== '' ? `状态${status}` : '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 列表角标样式用:0~4,未知时回退 0 */
|
|
|
|
|
|
function eventStatusForPill(status) {
|
|
|
|
|
|
const strToNum = {
|
|
|
|
|
|
NotStarted: 0,
|
|
|
|
|
|
Enrolling: 1,
|
|
|
|
|
|
RegistrationEnded: 2,
|
|
|
|
|
|
Ongoing: 3,
|
|
|
|
|
|
Ended: 4
|
|
|
|
|
|
};
|
|
|
|
|
|
if (strToNum[status] !== undefined) return strToNum[status];
|
|
|
|
|
|
const n = Number(status);
|
|
|
|
|
|
if (!Number.isNaN(n) && n >= 0 && n <= 4) return n;
|
|
|
|
|
|
return 0;
|
2026-03-31 18:09:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function eventFormatText(v) {
|
|
|
|
|
|
if (v === 'Offline') return '线下';
|
|
|
|
|
|
if (v === 'Online') return '线上';
|
|
|
|
|
|
return '';
|
2026-03-30 18:08:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
formatDateTime,
|
2026-03-31 23:27:35 +08:00
|
|
|
|
formatTime,
|
2026-03-31 18:09:37 +08:00
|
|
|
|
eventStatusText,
|
2026-04-07 16:47:13 +08:00
|
|
|
|
eventStatusForPill,
|
2026-03-31 18:09:37 +08:00
|
|
|
|
eventFormatText
|
2026-03-30 18:08:27 +08:00
|
|
|
|
};
|
|
|
|
|
|
|