fix bugs
This commit is contained in:
@@ -29,47 +29,108 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import infoAPI from '@/api/info.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
liveList: [
|
||||
{
|
||||
time: '16:45',
|
||||
type: 'highlight',
|
||||
typeText: '精彩瞬间',
|
||||
content: '张三选手以一记精彩的侧踢得分,现场观众掌声雷动!',
|
||||
images: []
|
||||
},
|
||||
{
|
||||
time: '16:30',
|
||||
type: 'score',
|
||||
typeText: '比分',
|
||||
content: '男子散打决赛:张三 3:2 李四,比赛进入白热化阶段',
|
||||
images: []
|
||||
},
|
||||
{
|
||||
time: '16:15',
|
||||
type: 'news',
|
||||
typeText: '赛况',
|
||||
content: '男子散打决赛正式开始,双方选手入场,裁判宣读比赛规则',
|
||||
images: []
|
||||
},
|
||||
{
|
||||
time: '16:00',
|
||||
type: 'news',
|
||||
typeText: '赛况',
|
||||
content: '上一场比赛结束,场地准备中...',
|
||||
images: []
|
||||
},
|
||||
{
|
||||
time: '15:45',
|
||||
type: 'highlight',
|
||||
typeText: '精彩瞬间',
|
||||
content: '半决赛第二场,王五选手表现出色,成功晋级决赛',
|
||||
images: []
|
||||
}
|
||||
]
|
||||
eventId: '',
|
||||
liveList: []
|
||||
};
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.eventId) {
|
||||
this.eventId = options.eventId
|
||||
this.loadLiveList(options.eventId)
|
||||
}
|
||||
},
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
this.loadLiveList(this.eventId, true)
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 加载比赛实况列表
|
||||
*/
|
||||
async loadLiveList(eventId, refresh = false) {
|
||||
try {
|
||||
const res = await infoAPI.getLiveUpdateList({ competitionId: eventId })
|
||||
|
||||
let list = []
|
||||
if (res.records) {
|
||||
list = res.records
|
||||
} else if (Array.isArray(res)) {
|
||||
list = res
|
||||
}
|
||||
|
||||
// 数据映射
|
||||
this.liveList = list.map(item => ({
|
||||
time: this.formatTime(item.updateTime || item.time || item.createTime),
|
||||
type: this.getLiveType(item.type || item.updateType),
|
||||
typeText: this.getLiveTypeText(item.type || item.updateType),
|
||||
content: item.content || item.updateContent || '',
|
||||
images: item.images || item.imageList || []
|
||||
}))
|
||||
|
||||
// 停止下拉刷新
|
||||
if (refresh) {
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('加载实况列表失败:', err)
|
||||
if (refresh) {
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取实况类型样式类名
|
||||
*/
|
||||
getLiveType(type) {
|
||||
const typeMap = {
|
||||
1: 'highlight',
|
||||
2: 'score',
|
||||
3: 'news',
|
||||
'highlight': 'highlight',
|
||||
'score': 'score',
|
||||
'news': 'news'
|
||||
}
|
||||
return typeMap[type] || 'news'
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取实况类型文本
|
||||
*/
|
||||
getLiveTypeText(type) {
|
||||
const typeMap = {
|
||||
1: '精彩瞬间',
|
||||
2: '比分',
|
||||
3: '赛况',
|
||||
'highlight': '精彩瞬间',
|
||||
'score': '比分',
|
||||
'news': '赛况'
|
||||
}
|
||||
return typeMap[type] || '赛况'
|
||||
},
|
||||
|
||||
/**
|
||||
* 格式化时间(只取时分)
|
||||
*/
|
||||
formatTime(timeStr) {
|
||||
if (!timeStr) return ''
|
||||
|
||||
// 如果已经是 HH:MM 格式
|
||||
if (/^\d{2}:\d{2}$/.test(timeStr)) {
|
||||
return timeStr
|
||||
}
|
||||
|
||||
const date = new Date(timeStr)
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
|
||||
return `${hours}:${minutes}`
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user