From ec0eb9841169cd718e9d4f6e77e9260a3eb23415 Mon Sep 17 00:00:00 2001 From: wm <2747639460@qq.com> Date: Thu, 23 Jul 2026 20:13:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(category):=20=E5=AE=9E=E7=8E=B0=E8=A7=A6?= =?UTF-8?q?=E5=BA=95=E5=88=86=E9=A1=B5=E5=8A=A0=E8=BD=BD=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=BE=80=E4=B8=8B=E7=BF=BB=E6=97=A0?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 根因:category.js 的 loadExercises 永远只取第 1 页(page=1, pageSize=20), 且用 exercises = res.items 整体替换、从不追加,也没有 onReachBottom/触底加载。 动作数远超 20(全部 1324、胸 163)时,往下翻只能看到前 20 条,其余永远加载不出来。 - 修复: * loadExercises 首次加载重置 page=1 并按 items.length { + const items = (res && res.items) || []; + const total = (res && res.total) || 0; this.setData({ - exercises: (res && res.items) || [], - total: (res && res.total) || 0, - loading: false + exercises: items, + total, + loading: false, + hasMore: items.length < total }); }).catch(() => { this.setData({ loading: false }); }); }, + onReachBottom() { + if (this.data.loading || this.data.loadingMore || !this.data.hasMore) return; + this.loadMore(); + }, + + loadMore() { + const next = this.data.page + 1; + this.setData({ loadingMore: true }); + const params = { page: next, pageSize: this.data.pageSize }; + params[this.data.dimension] = this.data.activeValue; + svc.listExercises(params).then((res) => { + const items = (res && res.items) || []; + const total = (res && res.total) || 0; + const merged = this.data.exercises.concat(items); + this.setData({ + exercises: merged, + total, + page: next, + loadingMore: false, + hasMore: merged.length < total + }); + }).catch(() => { + this.setData({ loadingMore: false }); + }); + }, + onValue(e) { const value = e.detail.value; if (value === this.data.activeValue) return; diff --git a/miniprogram/pages/category/category.wxml b/miniprogram/pages/category/category.wxml index 10143c3..a9441d5 100644 --- a/miniprogram/pages/category/category.wxml +++ b/miniprogram/pages/category/category.wxml @@ -21,6 +21,16 @@ + + + + + 加载中… + + 已经到底啦 + 上拉加载更多 + + 暂无数据 加载中… diff --git a/miniprogram/pages/category/category.wxss b/miniprogram/pages/category/category.wxss index 11fde5c..7d95a75 100644 --- a/miniprogram/pages/category/category.wxss +++ b/miniprogram/pages/category/category.wxss @@ -19,3 +19,15 @@ .grid { display: flex; flex-wrap: wrap; gap: 18rpx; margin-top: 12rpx; } .grid__item { width: calc((100% - 18rpx) / 2); } .empty { color: var(--text-3); font-size: 26rpx; text-align: center; padding: 80rpx 0; } + +/* 触底加载更多状态条 */ +.loadmore { display: flex; justify-content: center; padding: 36rpx 0 12rpx; } +.loadmore__loading { display: flex; align-items: center; gap: 12rpx; color: var(--text-3); font-size: 26rpx; } +.spinner { + width: 32rpx; height: 32rpx; border-radius: 50%; + border: 4rpx solid var(--line); + border-top-color: var(--accent); + animation: spin 0.8s linear infinite; +} +.loadmore__end, .loadmore__hint { font-size: 26rpx; } +@keyframes spin { to { transform: rotate(360deg); } }