- Change VITE_API_URL in .env from localhost:3000 to localhost:3001 for backend access. - Update index.html to replace favicon with logo.png and ensure proper HTML structure. - Add new dependencies for WangEditor in package.json and package-lock.json to support rich text editing features.
91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
const app = getApp();
|
|
const util = require("../../../utils/util");
|
|
|
|
Page({
|
|
data: {
|
|
list: [],
|
|
loading: false,
|
|
},
|
|
|
|
onLoad() {
|
|
this.fetchList();
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.fetchList().finally(() => {
|
|
wx.stopPullDownRefresh();
|
|
});
|
|
},
|
|
|
|
async fetchList() {
|
|
const currentStore = app.globalData.currentStore;
|
|
const storeId = currentStore ? currentStore.storeId : null;
|
|
|
|
this.setData({ loading: true });
|
|
try {
|
|
const res = await app.request("/api/match/display-list", {
|
|
store_id: storeId,
|
|
days: 7,
|
|
limit: 100,
|
|
});
|
|
|
|
const raw = res.data || [];
|
|
const list = raw.map((item) => {
|
|
const time = item.startTime || item.createdAt || item.endTime || null;
|
|
const stageName = item.stageName || "";
|
|
const statusName = item.statusName || "";
|
|
|
|
// 如果阶段名和状态名一样(例如都是“已结束”),只显示一次状态
|
|
const showStage = !!stageName && stageName !== statusName;
|
|
|
|
// 根据状态生成样式类型
|
|
let statusType = "pending";
|
|
switch (item.status) {
|
|
case 1:
|
|
statusType = "ongoing";
|
|
break;
|
|
case 2:
|
|
statusType = "finished";
|
|
break;
|
|
case 3:
|
|
statusType = "cancelled";
|
|
break;
|
|
default:
|
|
statusType = "pending";
|
|
}
|
|
|
|
return {
|
|
...item,
|
|
timeText: time ? util.formatDate(time) : "",
|
|
stageName,
|
|
statusName,
|
|
showStage,
|
|
statusType,
|
|
};
|
|
});
|
|
|
|
this.setData({ list });
|
|
} catch (e) {
|
|
console.error("获取最近比赛列表失败:", e);
|
|
} finally {
|
|
this.setData({ loading: false });
|
|
}
|
|
},
|
|
|
|
goDetail(e) {
|
|
const match = e.currentTarget.dataset.match;
|
|
if (!match) return;
|
|
|
|
if (match.type === 1) {
|
|
wx.navigateTo({
|
|
url: `/pages/match/challenge-detail/index?id=${match.id}`,
|
|
});
|
|
} else {
|
|
wx.navigateTo({
|
|
url: `/pages/match/ranking/index?code=${match.matchCode}`,
|
|
});
|
|
}
|
|
},
|
|
});
|
|
|