- 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.
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
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" });
|
|
}
|
|
},
|
|
});
|
|
|