const app = getApp(); const util = require("../../../utils/util"); Page({ data: { id: null, article: { title: "", contentHtml: "", timeText: "", categoryName: "", }, }, onLoad(options) { const id = options.id; if (!id) { wx.showToast({ title: "参数错误", icon: "none" }); return; } this.setData({ id }); this.fetchDetail(); }, async fetchDetail() { try { const res = await app.request(`/api/article/${this.data.id}`); const data = res.data || {}; const categoryName = data.category === "rules" ? "比赛规则" : data.category === "notice" ? "公告" : ""; this.setData({ article: { title: data.title || "", contentHtml: data.contentHtml || "", timeText: data.createdAt ? util.formatDate(data.createdAt) : "", categoryName, }, }); if (data.title) { wx.setNavigationBarTitle({ title: data.title }); } } catch (e) { console.error("获取文章详情失败:", e); wx.showToast({ title: "内容加载失败", icon: "none" }); } }, });