yingsa/miniprogram/pages/match/history/index.js
ethanfly 74ed19eee1 feat: 新增选手资料页面并优化界面设计
- 新增选手资料页面,支持查看选手信息及比赛记录
- 添加多个SVG图标替换原有emoji,提升视觉一致性
- 扩展CSS变量系统,增加信息、成功、警告、危险等状态颜色
- 优化多个页面的样式,统一使用CSS变量和现代设计语言
- 修复可选链操作符兼容性问题,改用传统条件判断
- 改进数据加载逻辑,使用Object.assign替代展开运算符
- 调整开发环境配置,使用本地服务器地址
2026-01-30 02:24:03 +08:00

96 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const app = getApp();
const util = require("../../../utils/util");
Page({
data: {
matches: [],
loading: false,
page: 1,
pageSize: 20,
hasMore: true,
},
onLoad() {
this.fetchMatches();
},
onShow() {
// 门店切换后刷新数据
if (app.globalData.storeChanged) {
app.globalData.storeChanged = false;
this.setData({ page: 1, hasMore: true, matches: [] });
this.fetchMatches();
}
},
onPullDownRefresh() {
this.setData({ page: 1, hasMore: true });
this.fetchMatches().then(() => {
wx.stopPullDownRefresh();
});
},
onReachBottom() {
if (this.data.hasMore && !this.data.loading) {
this.loadMore();
}
},
async fetchMatches() {
const currentStore = app.globalData.currentStore;
if (!currentStore || !currentStore.storeId) {
return;
}
this.setData({ loading: true });
try {
const res = await app.request("/api/match/my-matches", {
store_id: currentStore.storeId,
page: this.data.page,
pageSize: this.data.pageSize,
});
const matches = (res.data.list || []).map((match) => {
// 确保 powerChange 是数字类型,移除可能存在的加号和其他非数字字符
let powerChange = match.powerChange;
if (powerChange != null && powerChange !== undefined) {
// 如果是字符串,移除所有加号、空格等非数字字符(保留负号)
if (typeof powerChange === "string") {
// 保留负号,移除所有加号和其他字符
const cleaned = powerChange.replace(/\+/g, "").trim();
powerChange = parseFloat(cleaned) || 0;
}
// 确保是数字类型
powerChange = Number(powerChange);
// 如果是 NaN设为 0
if (isNaN(powerChange)) {
powerChange = 0;
}
} else {
powerChange = 0;
}
return Object.assign({}, match, {
powerChange: powerChange,
confirmedAt: util.formatDate(match.confirmedAt),
});
});
this.setData({
matches:
this.data.page === 1 ? matches : this.data.matches.concat(matches),
hasMore: matches.length >= this.data.pageSize,
});
} catch (e) {
console.error("获取比赛记录失败:", e);
} finally {
this.setData({ loading: false });
}
},
loadMore() {
this.setData({ page: this.data.page + 1 });
this.fetchMatches();
},
});