fix(hooks): prevent program freezing when pagesize returns 0 (#545)

This commit is contained in:
青菜白玉汤 2024-07-15 13:37:40 +08:00 committed by Soybean
parent 793b16e9ba
commit f4eeb2ed63

View File

@ -40,17 +40,20 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
transformer: res => { transformer: res => {
const { records = [], current = 1, size = 10, total = 0 } = res.data || {}; 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) => { const recordsWithIndex = records.map((item, index) => {
return { return {
...item, ...item,
index: (current - 1) * size + index + 1 index: (current - 1) * pageSize + index + 1
}; };
}); });
return { return {
data: recordsWithIndex, data: recordsWithIndex,
pageNum: current, pageNum: current,
pageSize: size, pageSize,
total total
}; };
}, },