diff --git a/pets-fe/pages/home/home.js b/pets-fe/pages/home/home.js index cb9c9f0..c7491b6 100644 --- a/pets-fe/pages/home/home.js +++ b/pets-fe/pages/home/home.js @@ -23,7 +23,8 @@ function fmtWhen(iso) { return d.getMonth() + 1 + '月' + d.getDate() + '日'; } -const TL_PAGE = 10; +// 首页最近记录只是速览,固定最新几条,翻全量去「全部记录」页,避免首页无限滚 +const TL_LIMIT = 6; Page({ data: { @@ -38,7 +39,6 @@ Page({ needNextPlan: false, monthCost: 0, timeline: [], - tlPage: 1, hasMore: false, }, onLoad() { @@ -127,11 +127,11 @@ Page({ .then((b) => this.setData({ monthCost: (b && b.total) || 0 })) .catch(() => this.setData({ monthCost: 0 })); }, - loadTimeline(page) { + loadTimeline() { const id = store.currentPetId(); if (!id) return; api - .getRecords(id, { page, pageSize: TL_PAGE }) + .getRecords(id, { page: 1, pageSize: TL_LIMIT }) .then((res) => { const list = (res.list || []).map((r) => ({ id: r.id, @@ -142,13 +142,13 @@ Page({ image: r.image_url || '', timeText: fmtWhen(r.occurred_at), })); - const merged = page === 1 ? list : this.data.timeline.concat(list); - this.setData({ timeline: merged, tlPage: page, hasMore: merged.length < (res.total || 0) }); + // 有更多就露出「查看全部」入口,跳到能分页筛选的全部记录页 + this.setData({ timeline: list, hasMore: (res.total || 0) > list.length }); }) .catch(() => {}); }, - loadMore() { - if (this.data.hasMore) this.loadTimeline(this.data.tlPage + 1); + goHistory() { + wx.navigateTo({ url: '/pages/history/history' }); }, previewImage(e) { const url = e.currentTarget.dataset.url; diff --git a/pets-fe/pages/home/home.wxml b/pets-fe/pages/home/home.wxml index 87e37a2..7ac843e 100644 --- a/pets-fe/pages/home/home.wxml +++ b/pets-fe/pages/home/home.wxml @@ -2,8 +2,7 @@ - + @@ -110,7 +109,7 @@ 还没有记录。点上面的「记一笔」开始, 体重趋势和健康洞察都会从这些记录里长出来。 - 加载更多 + 查看全部记录 ›