fix table data with null records

This commit is contained in:
jaron 2024-10-29 09:05:09 +08:00 committed by GitHub
parent 9ad5d7170a
commit 9c81fe8064
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,19 +43,29 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
// Ensure that the size is greater than 0, If it is less than 0, it will cause paging calculation errors. // 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 pageSize = size <= 0 ? 10 : size;
const recordsWithIndex = records.map((item, index) => { let recordsData;
return { if (Array.isArray(records) && records.length > 0) {
...item, const recordsWithIndex = records.map((item, index) => {
index: (current - 1) * pageSize + index + 1 return {
...item,
index: (current - 1) * pageSize + index + 1
};
});
recordsData = {
data: recordsWithIndex,
pageNum: current,
pageSize,
total
}; };
}); } else {
recordsData = {
return { data: [],
data: recordsWithIndex, pageNum: current,
pageNum: current, pageSize,
pageSize, total: 0
total };
}; }
return recordsData;
}, },
getColumnChecks: cols => { getColumnChecks: cols => {
const checks: NaiveUI.TableColumnCheck[] = []; const checks: NaiveUI.TableColumnCheck[] = [];