|
|
@@ -260,9 +260,35 @@ const parseToMs = (val) => {
|
|
|
if (typeof val === 'string') {
|
|
|
const trimmed = val.trim()
|
|
|
if (!trimmed) return null
|
|
|
- const normalized = trimmed.replace('T', ' ').replace(/\//g, '-')
|
|
|
- const ms = Date.parse(normalized)
|
|
|
+ // 处理各种时间格式
|
|
|
+ // 1. ISO格式: 2025-01-18T00:00:00
|
|
|
+ // 2. 标准格式: 2025-01-18 00:00:00
|
|
|
+ // 3. 带时区: 2025-01-18T00:00:00.000+08:00
|
|
|
+ let normalized = trimmed
|
|
|
+ .replace('T', ' ')
|
|
|
+ .replace(/\//g, '-')
|
|
|
+ .replace(/\.\d{3}/, '') // 移除毫秒
|
|
|
+ .replace(/[+-]\d{2}:\d{2}$/, '') // 移除时区
|
|
|
+
|
|
|
+ // 尝试解析
|
|
|
+ let ms = Date.parse(normalized)
|
|
|
if (!Number.isNaN(ms)) return ms
|
|
|
+
|
|
|
+ // 如果还是失败,尝试手动解析 YYYY-MM-DD HH:mm:ss 格式
|
|
|
+ const match = normalized.match(/^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})/)
|
|
|
+ if (match) {
|
|
|
+ const [, year, month, day, hour, minute, second] = match
|
|
|
+ const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day), parseInt(hour), parseInt(minute), parseInt(second))
|
|
|
+ return date.getTime()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尝试只有日期的格式 YYYY-MM-DD
|
|
|
+ const dateMatch = normalized.match(/^(\d{4})-(\d{2})-(\d{2})/)
|
|
|
+ if (dateMatch) {
|
|
|
+ const [, year, month, day] = dateMatch
|
|
|
+ const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day))
|
|
|
+ return date.getTime()
|
|
|
+ }
|
|
|
}
|
|
|
return null
|
|
|
}
|
|
|
@@ -272,13 +298,25 @@ const getComputedStatus = (row) => {
|
|
|
const endMs = parseToMs(row?.endTime)
|
|
|
const now = nowTs.value
|
|
|
|
|
|
- if (!startMs || !endMs) {
|
|
|
+ // 如果没有开始时间,返回数据库状态
|
|
|
+ if (!startMs) {
|
|
|
return row?.status
|
|
|
}
|
|
|
|
|
|
+ // 当前时间小于开始时间,未开始
|
|
|
if (now < startMs) return 1
|
|
|
- if (now >= endMs) return 3
|
|
|
- if (now >= startMs && now < endMs) return 2
|
|
|
+
|
|
|
+ // 如果有结束时间
|
|
|
+ if (endMs) {
|
|
|
+ // 当前时间大于等于结束时间,已结束
|
|
|
+ if (now >= endMs) return 3
|
|
|
+ // 当前时间在开始和结束之间,进行中
|
|
|
+ if (now >= startMs && now < endMs) return 2
|
|
|
+ } else {
|
|
|
+ // 没有结束时间,只要已开始就是进行中
|
|
|
+ if (now >= startMs) return 2
|
|
|
+ }
|
|
|
+
|
|
|
return row?.status
|
|
|
}
|
|
|
|
|
|
@@ -321,27 +359,33 @@ const loadActivityList = async () => {
|
|
|
if (response.code === 200) {
|
|
|
const list = response.data.list || response.data || []
|
|
|
// 字段兼容与转换:确保 isHot 为布尔,并兼容不同时间字段命名
|
|
|
- activityList.value = list.map(item => ({
|
|
|
- ...item,
|
|
|
- isHot:
|
|
|
- item.isHot === true ||
|
|
|
- item.isHot === 1 ||
|
|
|
- item.isHot === '1' ||
|
|
|
- item.is_hot === true ||
|
|
|
- item.is_hot === 1,
|
|
|
- isDeleted: Number(item.isDeleted ?? item.is_deleted ?? 0),
|
|
|
- // 兼容下划线命名与不同字段名
|
|
|
- startTime: item.startTime || item.start_time || item.start_at || '',
|
|
|
- endTime: item.endTime || item.end_time || item.end_at || '',
|
|
|
- registrationEndTime:
|
|
|
- item.registrationEndTime ||
|
|
|
- item.registration_end_time ||
|
|
|
- item.signup_end_time ||
|
|
|
- '',
|
|
|
- // 兼容报名人数字段
|
|
|
- actualParticipants: item.actualParticipants ?? item.actual_participants ?? 0,
|
|
|
- maxParticipants: item.maxParticipants ?? item.max_participants
|
|
|
- }))
|
|
|
+ activityList.value = list.map(item => {
|
|
|
+ // 优先使用下划线命名(后端SQL返回的格式)
|
|
|
+ const startTime = item.start_time || item.startTime || item.start_at || ''
|
|
|
+ const endTime = item.end_time || item.endTime || item.end_at || ''
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ isHot:
|
|
|
+ item.isHot === true ||
|
|
|
+ item.isHot === 1 ||
|
|
|
+ item.isHot === '1' ||
|
|
|
+ item.is_hot === true ||
|
|
|
+ item.is_hot === 1,
|
|
|
+ isDeleted: Number(item.isDeleted ?? item.is_deleted ?? 0),
|
|
|
+ // 兼容下划线命名与不同字段名
|
|
|
+ startTime: startTime,
|
|
|
+ endTime: endTime,
|
|
|
+ registrationEndTime:
|
|
|
+ item.registration_end_time ||
|
|
|
+ item.registrationEndTime ||
|
|
|
+ item.signup_end_time ||
|
|
|
+ '',
|
|
|
+ // 兼容报名人数字段
|
|
|
+ actualParticipants: item.actualParticipants ?? item.actual_participants ?? 0,
|
|
|
+ maxParticipants: item.maxParticipants ?? item.max_participants
|
|
|
+ }
|
|
|
+ })
|
|
|
total.value = response.data.total || activityList.value.length
|
|
|
}
|
|
|
} catch (error) {
|