Skip to content

Commit

Permalink
fix(hooks): prevent program freezing when pagesize returns 0 (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
Azir-11 authored and honghuangdc committed Jul 19, 2024
1 parent 793b16e commit f4eeb2e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hooks/common/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ export function useTable<A extends NaiveUI.TableApiFn>(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
};
},
Expand Down

0 comments on commit f4eeb2e

Please sign in to comment.