- 新增选手资料页面,支持查看选手信息及比赛记录 - 添加多个SVG图标替换原有emoji,提升视觉一致性 - 扩展CSS变量系统,增加信息、成功、警告、危险等状态颜色 - 优化多个页面的样式,统一使用CSS变量和现代设计语言 - 修复可选链操作符兼容性问题,改用传统条件判断 - 改进数据加载逻辑,使用Object.assign替代展开运算符 - 调整开发环境配置,使用本地服务器地址
137 lines
3.1 KiB
JavaScript
137 lines
3.1 KiB
JavaScript
const app = getApp();
|
||
const util = require("../../utils/util");
|
||
|
||
Page({
|
||
data: {
|
||
currentStore: null,
|
||
gender: "",
|
||
list: [],
|
||
loading: false,
|
||
page: 1,
|
||
pageSize: 20,
|
||
hasMore: true,
|
||
},
|
||
|
||
onLoad() {
|
||
this.initData();
|
||
},
|
||
|
||
onShow() {
|
||
const newStore = app.globalData.currentStore;
|
||
const oldStoreId = this.data.currentStore
|
||
? this.data.currentStore.storeId
|
||
: null;
|
||
|
||
// 检查门店是否切换
|
||
if (newStore && newStore.storeId !== oldStoreId) {
|
||
this.setData({
|
||
currentStore: newStore,
|
||
page: 1,
|
||
hasMore: true,
|
||
list: [],
|
||
});
|
||
this.fetchData();
|
||
} else if (app.globalData.storeChanged) {
|
||
// 全局标记门店已切换
|
||
app.globalData.storeChanged = false;
|
||
this.setData({
|
||
currentStore: newStore,
|
||
page: 1,
|
||
hasMore: true,
|
||
list: [],
|
||
});
|
||
this.fetchData();
|
||
}
|
||
},
|
||
|
||
onPullDownRefresh() {
|
||
this.setData({ page: 1, hasMore: true });
|
||
this.fetchData().then(() => {
|
||
wx.stopPullDownRefresh();
|
||
});
|
||
},
|
||
|
||
onReachBottom() {
|
||
if (this.data.hasMore && !this.data.loading) {
|
||
this.loadMore();
|
||
}
|
||
},
|
||
|
||
async initData() {
|
||
// 检查是否已登录(有 token)
|
||
if (!app.globalData.token) {
|
||
// 未登录,跳转到用户页面进行登录
|
||
wx.switchTab({ url: "/pages/user/index" });
|
||
return;
|
||
}
|
||
|
||
// 获取当前门店
|
||
try {
|
||
const store = await app.getCurrentStore();
|
||
this.setData({ currentStore: store });
|
||
this.fetchData();
|
||
} catch (e) {
|
||
console.error("获取门店失败:", e);
|
||
// 如果是认证失败,跳转到登录页
|
||
if (e.code === 401) {
|
||
wx.switchTab({ url: "/pages/user/index" });
|
||
}
|
||
}
|
||
},
|
||
|
||
async fetchData() {
|
||
if (!this.data.currentStore || !this.data.currentStore.storeId) return;
|
||
|
||
this.setData({ loading: true });
|
||
|
||
try {
|
||
const res = await app.request("/api/ladder/ranking", {
|
||
store_id: this.data.currentStore.storeId,
|
||
gender: this.data.gender,
|
||
page: this.data.page,
|
||
pageSize: this.data.pageSize,
|
||
});
|
||
|
||
const list = res.data.list || [];
|
||
this.setData({
|
||
list: this.data.page === 1 ? list : this.data.list.concat(list),
|
||
hasMore: list.length >= this.data.pageSize,
|
||
});
|
||
} catch (e) {
|
||
console.error("获取排名失败:", e);
|
||
} finally {
|
||
this.setData({ loading: false });
|
||
}
|
||
},
|
||
|
||
loadMore() {
|
||
this.setData({ page: this.data.page + 1 });
|
||
this.fetchData();
|
||
},
|
||
|
||
setGender(e) {
|
||
const gender = e.currentTarget.dataset.gender;
|
||
this.setData({ gender, page: 1, hasMore: true });
|
||
this.fetchData();
|
||
},
|
||
|
||
selectStore() {
|
||
wx.navigateTo({ url: "/pages/store/index" });
|
||
},
|
||
|
||
viewPlayer(e) {
|
||
const player = e.currentTarget.dataset.player;
|
||
const id = player && player.id ? player.id : e.currentTarget.dataset.id;
|
||
if (!id) return;
|
||
|
||
wx.navigateTo({
|
||
url: `/pages/player/index?id=${id}`,
|
||
success: (res) => {
|
||
if (res && res.eventChannel && player) {
|
||
res.eventChannel.emit("player", player);
|
||
}
|
||
},
|
||
});
|
||
},
|
||
});
|