diff --git a/change/@acedatacloud-nexior-7e8fdcc6-8b7a-4599-81a2-a1185adeac9c.json b/change/@acedatacloud-nexior-7e8fdcc6-8b7a-4599-81a2-a1185adeac9c.json new file mode 100644 index 00000000..2c0e128c --- /dev/null +++ b/change/@acedatacloud-nexior-7e8fdcc6-8b7a-4599-81a2-a1185adeac9c.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix bad pagniation", + "packageName": "@acedatacloud/nexior", + "email": "cqc@cuiqingcai.com", + "dependentChangeType": "patch" +} diff --git a/src/components/common/ScrollList.vue b/src/components/common/ScrollList.vue index e42df76b..8bb7cb43 100644 --- a/src/components/common/ScrollList.vue +++ b/src/components/common/ScrollList.vue @@ -29,7 +29,7 @@ export default defineComponent({ }, reachThreshold: { type: Number, - default: 10 + default: 40 } }, emits: ['reach-top', 'scroll'], diff --git a/src/utils/pagination.ts b/src/utils/pagination.ts index de19b55f..f36deb20 100644 --- a/src/utils/pagination.ts +++ b/src/utils/pagination.ts @@ -9,15 +9,26 @@ export async function loadPreviousPage(options: { tasks?: TasksLike; getTasks?: () => TasksLike | undefined; loading: boolean; + ignoreLoadingGuard?: boolean; setLoading: (value: boolean) => void; isBlocked?: () => boolean; fetch: (createdAtMax: number) => Promise; getScrollElement?: () => HTMLElement | undefined; reachThreshold?: number; }) { - const { tasks, getTasks, loading, setLoading, isBlocked, fetch, getScrollElement, reachThreshold = 10 } = options; + const { + tasks, + getTasks, + loading, + ignoreLoadingGuard, + setLoading, + isBlocked, + fetch, + getScrollElement, + reachThreshold = 40 + } = options; const currentTasks = getTasks ? getTasks() : tasks; - if (loading || isBlocked?.()) { + if ((loading && !ignoreLoadingGuard) || isBlocked?.()) { return; } @@ -43,18 +54,18 @@ export async function loadPreviousPage(options: { await nextTick(); const latest = getTasks ? getTasks() : tasks; const newLength = latest?.items?.length || 0; - const hasMore = latest?.total !== undefined ? newLength < (latest.total || 0) : false; + const hasMore = latest?.total !== undefined ? newLength < (latest.total || 0) : newLength > previousLength; const scrollEl = getScrollElement?.(); if (scrollEl) { const newHeight = scrollEl.scrollHeight; scrollEl.scrollTop = newHeight - previousHeight + previousScrollTop; } - // If仍在顶部附近且还有更多数据,自动继续拉取,避免需要人为下滑再上滑。 if (hasMore && newLength > previousLength && scrollEl && scrollEl.scrollTop <= reachThreshold && !isBlocked?.()) { await loadPreviousPage({ ...options, tasks: latest, - loading: false + loading: false, + ignoreLoadingGuard: true }); } } finally {