- 新增选手资料页面,支持查看选手信息及比赛记录 - 添加多个SVG图标替换原有emoji,提升视觉一致性 - 扩展CSS变量系统,增加信息、成功、警告、危险等状态颜色 - 优化多个页面的样式,统一使用CSS变量和现代设计语言 - 修复可选链操作符兼容性问题,改用传统条件判断 - 改进数据加载逻辑,使用Object.assign替代展开运算符 - 调整开发环境配置,使用本地服务器地址
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
playerId: null,
|
|
player: null,
|
|
matches: [],
|
|
loadingMatches: false
|
|
},
|
|
|
|
onLoad(options) {
|
|
const playerId = options && options.id ? String(options.id) : null
|
|
this.setData({ playerId })
|
|
|
|
const eventChannel = this.getOpenerEventChannel ? this.getOpenerEventChannel() : null
|
|
if (eventChannel) {
|
|
eventChannel.on('player', (player) => {
|
|
if (player) this.setData({ player })
|
|
})
|
|
}
|
|
|
|
this.refresh()
|
|
},
|
|
|
|
async onPullDownRefresh() {
|
|
try {
|
|
await this.refresh()
|
|
} finally {
|
|
wx.stopPullDownRefresh()
|
|
}
|
|
},
|
|
|
|
async refresh() {
|
|
await Promise.all([this.fetchPlayer(), this.fetchMatches()])
|
|
},
|
|
|
|
async fetchPlayer() {
|
|
if (!this.data.playerId) return
|
|
try {
|
|
const res = await app.request('/api/ladder/player', { id: this.data.playerId })
|
|
if (res && res.data) this.setData({ player: res.data })
|
|
} catch (e) {
|
|
}
|
|
},
|
|
|
|
async fetchMatches() {
|
|
if (!this.data.playerId) return
|
|
this.setData({ loadingMatches: true })
|
|
try {
|
|
const res = await app.request('/api/match/history', { player_id: this.data.playerId })
|
|
const list = Array.isArray(res && res.data) ? res.data : (res && res.data && res.data.list) || []
|
|
const matches = list.map((item) => {
|
|
return Object.assign({}, item, {
|
|
timeText: item.timeText || item.createTime || item.matchTime || '',
|
|
resultClass: item.resultClass || (item.result === 'win' ? 'win' : item.result === 'lose' ? 'lose' : ''),
|
|
resultText:
|
|
item.resultText ||
|
|
(item.result === 'win' ? '胜' : item.result === 'lose' ? '负' : item.resultName || '')
|
|
})
|
|
})
|
|
this.setData({ matches })
|
|
} catch (e) {
|
|
this.setData({ matches: [] })
|
|
} finally {
|
|
this.setData({ loadingMatches: false })
|
|
}
|
|
}
|
|
})
|