fix bugs
This commit is contained in:
@@ -76,30 +76,98 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import competitionAPI from '@/api/competition.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
eventId: '',
|
||||
eventInfo: {
|
||||
id: 1,
|
||||
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
|
||||
location: '天津市-天津市体育中心',
|
||||
registerTime: '2025.02.01-2025.02.10',
|
||||
matchTime: '2025.02.01-2025.02.10',
|
||||
registerCount: '25212',
|
||||
status: 'open' // open, finished
|
||||
id: '',
|
||||
title: '',
|
||||
location: '',
|
||||
registerTime: '',
|
||||
matchTime: '',
|
||||
registerCount: '0',
|
||||
status: 'open'
|
||||
}
|
||||
};
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.id) {
|
||||
this.loadEventDetail(options.id);
|
||||
this.eventId = options.id
|
||||
this.loadEventDetail(options.id)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loadEventDetail(id) {
|
||||
// 加载赛事详情
|
||||
// 实际应该从后端获取
|
||||
/**
|
||||
* 加载赛事详情
|
||||
* @param {String|Number} id 赛事ID
|
||||
*/
|
||||
async loadEventDetail(id) {
|
||||
try {
|
||||
const res = await competitionAPI.getCompetitionDetail(id)
|
||||
|
||||
console.log('赛事详情API返回:', res)
|
||||
|
||||
// 尝试多个可能的时间字段
|
||||
const regStartTime = res.registrationStartTime || res.registerStartTime || res.signUpStartTime
|
||||
const regEndTime = res.registrationEndTime || res.registerEndTime || res.signUpEndTime
|
||||
const startTime = res.startTime || res.competitionStartTime || res.beginTime || res.startDate
|
||||
const endTime = res.endTime || res.competitionEndTime || res.finishTime || res.endDate
|
||||
|
||||
// 数据映射
|
||||
this.eventInfo = {
|
||||
id: res.id,
|
||||
title: res.name || res.title || res.competitionName || '未命名赛事',
|
||||
location: res.location || res.address || res.venue || '待定',
|
||||
registerTime: this.formatTimeRange(regStartTime, regEndTime) ||
|
||||
res.registerTime || res.registrationPeriod || '待定',
|
||||
matchTime: this.formatTimeRange(startTime, endTime) ||
|
||||
res.matchTime || res.competitionTime || '待定',
|
||||
registerCount: res.registrationCount || res.registerCount || res.signUpCount || '0',
|
||||
status: this.getStatus(res.status)
|
||||
}
|
||||
|
||||
console.log('格式化后的赛事信息:', this.eventInfo)
|
||||
} catch (err) {
|
||||
console.error('加载赛事详情失败:', err)
|
||||
uni.showToast({
|
||||
title: '加载失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 格式化时间范围
|
||||
*/
|
||||
formatTimeRange(startTime, endTime) {
|
||||
if (!startTime || !endTime) return ''
|
||||
|
||||
const formatDate = (dateStr) => {
|
||||
if (!dateStr) return ''
|
||||
const date = new Date(dateStr)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}.${month}.${day}`
|
||||
}
|
||||
|
||||
return `${formatDate(startTime)}-${formatDate(endTime)}`
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取赛事状态
|
||||
*/
|
||||
getStatus(status) {
|
||||
// 1: 报名中, 2: 进行中, 3: 已结束
|
||||
if (status === 3 || status === '3' || status === 'finished') {
|
||||
return 'finished'
|
||||
}
|
||||
return 'open'
|
||||
},
|
||||
|
||||
handleFunction(type) {
|
||||
const routeMap = {
|
||||
'info': '/pages/event-info/event-info',
|
||||
@@ -115,7 +183,10 @@ export default {
|
||||
|
||||
const url = routeMap[type];
|
||||
if (url) {
|
||||
uni.navigateTo({ url });
|
||||
// 跳转时传递赛事ID
|
||||
uni.navigateTo({
|
||||
url: `${url}?eventId=${this.eventId}`
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '功能开发中',
|
||||
@@ -202,8 +273,8 @@ export default {
|
||||
}
|
||||
|
||||
.function-icon-img {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
width: 90rpx;
|
||||
height: 90rpx;
|
||||
}
|
||||
|
||||
.function-text {
|
||||
@@ -226,9 +297,9 @@ export default {
|
||||
background-color: #C93639;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
padding: 30rpx;
|
||||
padding: 20rpx;
|
||||
border-radius: 12rpx;
|
||||
font-size: 32rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user