yingsa/miniprogram/pages/article/list/index.js
ethanfly 98f9e64d91 refactor: Enhance store and user management features
- Updated user information retrieval to support store-specific points and ladder user data.
- Refactored store initialization logic to prioritize last selected store.
- Improved API endpoints for fetching matches and user data, ensuring compatibility with store context.
- Adjusted UI components to display store-related information consistently across various pages.
- Enhanced error handling and data fetching logic for better user experience.
2026-02-07 11:09:37 +08:00

57 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", 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}`,
});
},
});