Optimize pagnation exp (#297)
This commit is contained in:
1 parent
3f8941312d
commit
b103bee710
3 files changed
+24
-6
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"comment": "fix bad pagniation",
|
||||||
|
"packageName": "@acedatacloud/nexior",
|
||||||
|
"email": "cqc@cuiqingcai.com",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
reachThreshold: {
|
reachThreshold: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 10
|
default: 40
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['reach-top', 'scroll'],
|
emits: ['reach-top', 'scroll'],
|
||||||
|
|||||||
+16
-5
@@ -9,15 +9,26 @@ export async function loadPreviousPage(options: {
|
|||||||
tasks?: TasksLike;
|
tasks?: TasksLike;
|
||||||
getTasks?: () => TasksLike | undefined;
|
getTasks?: () => TasksLike | undefined;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
ignoreLoadingGuard?: boolean;
|
||||||
setLoading: (value: boolean) => void;
|
setLoading: (value: boolean) => void;
|
||||||
isBlocked?: () => boolean;
|
isBlocked?: () => boolean;
|
||||||
fetch: (createdAtMax: number) => Promise<any>;
|
fetch: (createdAtMax: number) => Promise<any>;
|
||||||
getScrollElement?: () => HTMLElement | undefined;
|
getScrollElement?: () => HTMLElement | undefined;
|
||||||
reachThreshold?: number;
|
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;
|
const currentTasks = getTasks ? getTasks() : tasks;
|
||||||
if (loading || isBlocked?.()) {
|
if ((loading && !ignoreLoadingGuard) || isBlocked?.()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,18 +54,18 @@ export async function loadPreviousPage(options: {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
const latest = getTasks ? getTasks() : tasks;
|
const latest = getTasks ? getTasks() : tasks;
|
||||||
const newLength = latest?.items?.length || 0;
|
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?.();
|
const scrollEl = getScrollElement?.();
|
||||||
if (scrollEl) {
|
if (scrollEl) {
|
||||||
const newHeight = scrollEl.scrollHeight;
|
const newHeight = scrollEl.scrollHeight;
|
||||||
scrollEl.scrollTop = newHeight - previousHeight + previousScrollTop;
|
scrollEl.scrollTop = newHeight - previousHeight + previousScrollTop;
|
||||||
}
|
}
|
||||||
// If仍在顶部附近且还有更多数据,自动继续拉取,避免需要人为下滑再上滑。
|
|
||||||
if (hasMore && newLength > previousLength && scrollEl && scrollEl.scrollTop <= reachThreshold && !isBlocked?.()) {
|
if (hasMore && newLength > previousLength && scrollEl && scrollEl.scrollTop <= reachThreshold && !isBlocked?.()) {
|
||||||
await loadPreviousPage({
|
await loadPreviousPage({
|
||||||
...options,
|
...options,
|
||||||
tasks: latest,
|
tasks: latest,
|
||||||
loading: false
|
loading: false,
|
||||||
|
ignoreLoadingGuard: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in new issue
Block a user