62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
const app = getApp()
|
|
const util = require('../../../utils/util')
|
|
|
|
Page({
|
|
data: {
|
|
matchCode: '',
|
|
match: {},
|
|
myPlayer: null,
|
|
currentGame: null
|
|
},
|
|
|
|
onLoad(options) {
|
|
this.setData({ matchCode: options.code })
|
|
this.fetchMatchDetail()
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.fetchMatchDetail().then(() => {
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
|
|
getStatusText(status) {
|
|
return util.getMatchStatusText(status)
|
|
},
|
|
|
|
getStageText(stage) {
|
|
const texts = { 0: '报名中', 1: '循环赛', 2: '淘汰赛', 3: '已结束' }
|
|
return texts[stage] || '未知'
|
|
},
|
|
|
|
async fetchMatchDetail() {
|
|
try {
|
|
const res = await app.request(`/api/match/ranking/${this.data.matchCode}`)
|
|
this.setData({ match: res.data })
|
|
|
|
// 找到我的参赛信息
|
|
const ladderUser = app.globalData.ladderUser
|
|
if (ladderUser) {
|
|
const myPlayer = res.data.players.find(p => p.ladderUserId === ladderUser.id)
|
|
this.setData({ myPlayer })
|
|
|
|
// 获取当前对局
|
|
if (myPlayer && myPlayer.status === 'playing') {
|
|
this.fetchCurrentGame()
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('获取排位赛详情失败:', e)
|
|
}
|
|
},
|
|
|
|
async fetchCurrentGame() {
|
|
try {
|
|
const res = await app.request(`/api/match/ranking/${this.data.matchCode}/my-game`)
|
|
this.setData({ currentGame: res.data.currentGame })
|
|
} catch (e) {
|
|
console.error('获取当前对局失败:', e)
|
|
}
|
|
}
|
|
})
|