From 7983abac84a3d38c03062e5580a0a943399e20a7 Mon Sep 17 00:00:00 2001 From: Dongsheng Zhao <41723543+Blackman99@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:39:42 +0800 Subject: [PATCH] fix: total pages less than maxDisplayPages --- packages/ui/src/components/CPagination.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/components/CPagination.svelte b/packages/ui/src/components/CPagination.svelte index ef4d3ae..9c112ef 100644 --- a/packages/ui/src/components/CPagination.svelte +++ b/packages/ui/src/components/CPagination.svelte @@ -84,12 +84,13 @@ } $: boundaryLeft = Math.floor(maxDisplayPages / 2) + $: displayPages = maxDisplayPages < pages ? maxDisplayPages : pages $: pagesArray = Array.from({ - length: maxDisplayPages < pages ? maxDisplayPages : pages, + length: displayPages, }).map((_, i) => { if (current <= boundaryLeft) return i + 1 - if (current >= pages - boundaryLeft) return pages - maxDisplayPages + i + 1 + if (current >= pages - boundaryLeft) return pages - displayPages + i + 1 return i <= boundaryLeft ? current - boundaryLeft + i