yingsa/miniprogram/pages/match/ranking/index.js

54 lines
1.2 KiB
JavaScript

const app = getApp()
Page({
data: {
matchCode: '',
match: {
players: []
},
myPlayer: null,
currentGame: null
},
onLoad(options) {
this.setData({ matchCode: options.code })
this.fetchMatchDetail()
},
onPullDownRefresh() {
this.fetchMatchDetail().then(() => {
wx.stopPullDownRefresh()
})
},
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)
}
}
})