yingsa/miniprogram/pages/article/list/index.js
Ethanfly d07ebb735a fix(env): Update API URL and enhance HTML structure
- 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.
2026-02-06 19:04:16 +08:00

60 lines
1.4 KiB
JavaScript

const app = getApp();
const util = require("../../../utils/util");
Page({
data: {
articles: [],
loading: false,
},
onLoad() {
this.fetchArticles();
},
onPullDownRefresh() {
this.fetchArticles().finally(() => {
wx.stopPullDownRefresh();
});
},
async fetchArticles() {
this.setData({ loading: true });
try {
// 活动公告:按当前门店只拉取公告分类最近 10 条
const storeId = app.globalData.currentStore && app.globalData.currentStore.storeId;
const data = { category: "notice", limit: 10 };
if (storeId) {
data.store_id = storeId;
}
const res = await app.request("/api/article", {
method: "GET",
data,
});
const raw = res.data || [];
const articles = raw.map((a) => ({
id: a.id,
title: a.title,
category: a.category,
categoryName: a.category === "notice" ? "活动公告" : "",
summary: a.summary,
timeText: a.createdAt ? util.formatDate(a.createdAt) : "",
isTop: !!a.isTop,
}));
this.setData({ articles });
} catch (e) {
console.error("获取文章列表失败:", e);
} finally {
this.setData({ loading: false });
}
},
goDetail(e) {
const id = e.currentTarget.dataset.id;
if (!id) return;
wx.navigateTo({
url: `/pages/article/detail/index?id=${id}`,
});
},
});