From 877311f9df70b7d76f8a0f8b5082f061de439ec8 Mon Sep 17 00:00:00 2001 From: Pom <1078889045@qq.com> Date: Thu, 17 Dec 2020 17:18:18 +0800 Subject: [PATCH] fix(table): Update useDataSource.ts (#131) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行 --- src/components/Table/src/hooks/useDataSource.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 4a65e978..d1df9dbb 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -89,10 +89,12 @@ export function useDataSource( loadingRef.value = true; const { pageField, sizeField, listField, totalField } = fetchSetting || FETCH_SETTING; let pageParams: any = {}; + + const { current, pageSize } = unref(getPaginationRef) as PaginationProps; + if (isBoolean(getPaginationRef)) { pageParams = {}; } else { - const { current, pageSize } = unref(getPaginationRef) as PaginationProps; pageParams[pageField] = (opt && opt.page) || current; pageParams[sizeField] = pageSize; } @@ -112,6 +114,16 @@ export function useDataSource( const res = await api(params); let resultItems: any[] = get(res, listField); const resultTotal: number = get(res, totalField); + + // 假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行 + var currentTotalPage = Math.ceil(resultTotal / pageSize); + if (current > currentTotalPage) { + setPagination({ + current: currentTotalPage, + }); + fetch(opt); + } + if (afterFetch && isFunction(afterFetch)) { resultItems = afterFetch(resultItems) || resultItems; }