Add server and mini-program pagination for shared lists

This commit is contained in:
2026-10-11 10:10:49 +08:00
parent c0a3db5c8e
commit 7854d94e7b
37 changed files with 395 additions and 175 deletions
+12 -11
View File
@@ -1,8 +1,9 @@
const { itemsOf, startList, applyList, failList, finishList, withListPagination } = require('../../utils/list-pagination');
const { withDataCache } = require('../../utils/page-cache');
const { getLayout } = require('../../utils/layout');
// pages/punch/punch.js - 情侣打卡
const { api, getImageUrl } = require('../../utils/request');
Page(withDataCache({
Page(withDataCache(withListPagination({
onResize: function() { this.setData(getLayout()); },
data: { loadError: false,
checkins: [],
@@ -54,16 +55,15 @@ Page(withDataCache({
});
},
loadData: async function() {
if (this._pageLoading) return;
this._pageLoading = true;
this.setData({loading: !this._hasCachedData, loadError:false});
loadData: async function(page) {
const ticket = startList(this, page);
if (!ticket) return;
try {
const [res, stats] = await Promise.all([
api.checkinList(),
api.checkinList({page:ticket.page,page_size:20}),
api.checkinStats().catch(() => ({}))
]);
const list = (res.items || res || []).map(function(item) {
const list = itemsOf(res).map(function(item) {
item.type = item.type || 'both';
var typeLabels = { both: '双方', first: '第一视角', her: '她打卡' };
item.type_label = typeLabels[item.type] || '双方';
@@ -89,10 +89,11 @@ Page(withDataCache({
todayPartner: stats.today_partner_count || 0,
loading: false
};
this.setData(data);
delete data.checkins;
applyList(this, ticket, res, list, 'checkins', data);
} catch(e) {
this.setData({loadError:true}); console.error(e); this.setData({ loading: false }); }
finally { this._pageLoading = false; this.setData({loading:false}); }
failList(this,ticket); console.error(e); this.setData({ loading: false }); }
finally { finishList(this,ticket); }
},
// ===== 点击卡片 → 详情弹窗 =====
@@ -119,4 +120,4 @@ Page(withDataCache({
goBack: function() { wx.navigateBack(); },
goHome: function() { wx.switchTab({ url: '/pages/index/index' }); },
goProfile: function() { wx.switchTab({ url: '/pages/profile/profile' }); }
}, {"loadData": ["checkinList", "checkinStats", "coupleInfo"]}));
}, 'loadData'), {"loadData": ["checkinList", "checkinStats", "coupleInfo"]}));