mirror of
https://github.com/vbenjs/vben-admin-thin-next.git
synced 2025-01-24 18:40:19 +08:00
fix(table): Update useDataSource.ts (#131)
假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行
This commit is contained in:
parent
de25557f86
commit
877311f9df
@ -89,10 +89,12 @@ export function useDataSource(
|
|||||||
loadingRef.value = true;
|
loadingRef.value = true;
|
||||||
const { pageField, sizeField, listField, totalField } = fetchSetting || FETCH_SETTING;
|
const { pageField, sizeField, listField, totalField } = fetchSetting || FETCH_SETTING;
|
||||||
let pageParams: any = {};
|
let pageParams: any = {};
|
||||||
|
|
||||||
|
const { current, pageSize } = unref(getPaginationRef) as PaginationProps;
|
||||||
|
|
||||||
if (isBoolean(getPaginationRef)) {
|
if (isBoolean(getPaginationRef)) {
|
||||||
pageParams = {};
|
pageParams = {};
|
||||||
} else {
|
} else {
|
||||||
const { current, pageSize } = unref(getPaginationRef) as PaginationProps;
|
|
||||||
pageParams[pageField] = (opt && opt.page) || current;
|
pageParams[pageField] = (opt && opt.page) || current;
|
||||||
pageParams[sizeField] = pageSize;
|
pageParams[sizeField] = pageSize;
|
||||||
}
|
}
|
||||||
@ -112,6 +114,16 @@ export function useDataSource(
|
|||||||
const res = await api(params);
|
const res = await api(params);
|
||||||
let resultItems: any[] = get(res, listField);
|
let resultItems: any[] = get(res, listField);
|
||||||
const resultTotal: number = get(res, totalField);
|
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)) {
|
if (afterFetch && isFunction(afterFetch)) {
|
||||||
resultItems = afterFetch(resultItems) || resultItems;
|
resultItems = afterFetch(resultItems) || resultItems;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user