fix: table pagination current error

This commit is contained in:
tangjinzhou 2021-10-01 17:08:51 +08:00
parent 1add0d251c
commit 1fb40a31e4

View File

@ -63,20 +63,22 @@ export default function usePagination(
})); }));
// ============ Basic Pagination Config ============ // ============ Basic Pagination Config ============
const mergedPagination = computed(() => const mergedPagination = computed(() => {
extendsObject<Partial<TablePaginationConfig>>(innerPagination.value, pagination.value, { const mP = extendsObject<Partial<TablePaginationConfig>>(
total: paginationTotal.value > 0 ? paginationTotal.value : totalRef.value, innerPagination.value,
}), pagination.value,
); {
total: paginationTotal.value > 0 ? paginationTotal.value : totalRef.value,
// Reset `current` if data length or pageSize changed },
const maxPage = Math.ceil( );
(paginationTotal.value || totalRef.value) / mergedPagination.value.pageSize!, // Reset `current` if data length or pageSize changed
); const maxPage = Math.ceil((paginationTotal.value || totalRef.value) / mP.pageSize!);
if (mergedPagination.value.current! > maxPage) { if (mP.current! > maxPage) {
// Prevent a maximum page count of 0 // Prevent a maximum page count of 0
mergedPagination.value.current = maxPage || 1; mP.current = maxPage || 1;
} }
return mP;
});
const refreshPagination = (current = 1, pageSize?: number) => { const refreshPagination = (current = 1, pageSize?: number) => {
if (pagination.value === false) return; if (pagination.value === false) return;