Skip to content

Commit

Permalink
fix(table): Update useDataSource.ts (#131)
Browse files Browse the repository at this point in the history
假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行
  • Loading branch information
1078889045 authored Dec 17, 2020
1 parent de25557 commit 877311f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/Table/src/hooks/useDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 877311f

Please sign in to comment.