- 新增选手资料页面,支持查看选手信息及比赛记录 - 添加多个SVG图标替换原有emoji,提升视觉一致性 - 扩展CSS变量系统,增加信息、成功、警告、危险等状态颜色 - 优化多个页面的样式,统一使用CSS变量和现代设计语言 - 修复可选链操作符兼容性问题,改用传统条件判断 - 改进数据加载逻辑,使用Object.assign替代展开运算符 - 调整开发环境配置,使用本地服务器地址
70 lines
1.4 KiB
JavaScript
70 lines
1.4 KiB
JavaScript
const app = getApp()
|
|
const util = require('../../../utils/util')
|
|
|
|
Page({
|
|
data: {
|
|
records: [],
|
|
loading: false,
|
|
page: 1,
|
|
pageSize: 20,
|
|
hasMore: true
|
|
},
|
|
|
|
onLoad() {
|
|
this.fetchRecords()
|
|
},
|
|
|
|
onShow() {
|
|
// 门店切换后刷新数据
|
|
if (app.globalData.storeChanged) {
|
|
app.globalData.storeChanged = false
|
|
this.setData({ page: 1, hasMore: true, records: [] })
|
|
this.fetchRecords()
|
|
}
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.setData({ page: 1, hasMore: true })
|
|
this.fetchRecords().then(() => {
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
|
|
onReachBottom() {
|
|
if (this.data.hasMore && !this.data.loading) {
|
|
this.loadMore()
|
|
}
|
|
},
|
|
|
|
async fetchRecords() {
|
|
this.setData({ loading: true })
|
|
|
|
try {
|
|
const res = await app.request('/api/points/records', {
|
|
page: this.data.page,
|
|
pageSize: this.data.pageSize
|
|
})
|
|
|
|
const records = (res.data.list || []).map(record =>
|
|
Object.assign({}, record, {
|
|
createdAt: util.formatDate(record.createdAt)
|
|
})
|
|
)
|
|
|
|
this.setData({
|
|
records: this.data.page === 1 ? records : this.data.records.concat(records),
|
|
hasMore: records.length >= this.data.pageSize
|
|
})
|
|
} catch (e) {
|
|
console.error('获取积分记录失败:', e)
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
loadMore() {
|
|
this.setData({ page: this.data.page + 1 })
|
|
this.fetchRecords()
|
|
}
|
|
})
|