From f4eeb2ed6357e9a2ece2efac9d482f4bfbec3c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E8=8F=9C=E7=99=BD=E7=8E=89=E6=B1=A4?= <79054161+Azir-11@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:37:40 +0800 Subject: [PATCH] fix(hooks): prevent program freezing when pagesize returns 0 (#545) --- src/hooks/common/table.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hooks/common/table.ts b/src/hooks/common/table.ts index d189060b..6619f8b3 100644 --- a/src/hooks/common/table.ts +++ b/src/hooks/common/table.ts @@ -40,17 +40,20 @@ export function useTable(config: NaiveUI.NaiveTabl transformer: res => { const { records = [], current = 1, size = 10, total = 0 } = res.data || {}; + // Ensure that the size is greater than 0, If it is less than 0, it will cause paging calculation errors. + const pageSize = size <= 0 ? 10 : size; + const recordsWithIndex = records.map((item, index) => { return { ...item, - index: (current - 1) * size + index + 1 + index: (current - 1) * pageSize + index + 1 }; }); return { data: recordsWithIndex, pageNum: current, - pageSize: size, + pageSize, total }; },