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 -12
View File
@@ -1,3 +1,4 @@
const { itemsOf, startList, applyList, failList, finishList, withListPagination } = require('../../utils/list-pagination');
const { withDataCache } = require('../../utils/page-cache');
const { getLayout } = require('../../utils/layout');
// pages/timeline/timeline.js
@@ -56,7 +57,7 @@ function calcNearestRepeatDate(eventDate, today, interval, unit) {
return new Date(eventDate);
}
Page(withDataCache({
Page(withDataCache(withListPagination({
onResize: function() { this.setData(getLayout()); },
data: { loading: true, loadError: false,
list: []
@@ -82,12 +83,11 @@ Page(withDataCache({
return { title: '让所有的爱有迹可循', imageUrl: '/images/share.png' };
},
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 list = await api.timelineList();
const list = await api.timelineList({page:ticket.page,page_size:20});
const myUid = wx.getStorageSync('userId');
var nameMap = {};
var avatarMap = {};
@@ -100,12 +100,12 @@ Page(withDataCache({
} catch (e) {}
var today = new Date(); today.setHours(0,0,0,0);
var items = (list || []).map(function(item, idx) {
var items = itemsOf(list).map(function(item, idx) {
var cid = parseInt(item.created_by) || 0;
item.creator_name = nameMap[cid] || (cid == myUid ? '我' : 'TA');
item.creator_avatar = avatarMap[cid] || '';
item.creator_initial = (item.creator_name || '?')[0].toUpperCase();
item.side = idx % 2 === 0 ? 'left' : 'right';
item.side = ((ticket.page-1)*20+idx) % 2 === 0 ? 'left' : 'right';
item.bg_image_url = item.bg_image ? getImageUrl(item.bg_image) : '';
// 计算纪念日/倒数日(支持重复事件)
@@ -150,13 +150,13 @@ Page(withDataCache({
}
return item;
});
this.setData({ list: items });
applyList(this, ticket, list, items, 'list');
} catch (e) {
this.setData({loadError:true});
failList(this,ticket);
console.error(e);
wx.showToast({ title: (e && (e.error || e.errMsg || e.message)) || '加载失败', icon: 'none' });
}
finally { this._pageLoading = false; this.setData({loading:false}); }
finally { finishList(this,ticket); }
},
@@ -192,4 +192,4 @@ Page(withDataCache({
goHome: function() { wx.switchTab({ url: '/pages/index/index' }); },
goBack: function() { wx.navigateBack(); },
goProfile: function() { wx.switchTab({ url: '/pages/profile/profile' }); }
}, {"loadData": ["timelineList", "coupleInfo"]}));
}, 'loadData'), {"loadData": ["timelineList", "coupleInfo"]}));