feat: add formatFileSize

This commit is contained in:
xingyu4j
2025-10-17 14:38:52 +08:00
parent 4f7b7c0e59
commit 09afe93a7a
6 changed files with 36 additions and 27 deletions

View File

@@ -340,6 +340,17 @@ setupVbenVxeTable({
return `${erpNumberFormatter(fenToYuan(cellValue), digits)}`;
},
});
vxeUI.formats.add('formatFileSize', {
tableCellFormatMethod({ cellValue }, digits = 2) {
if (!cellValue) return '0 B';
const unitArr = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const index = Math.floor(Math.log(cellValue) / Math.log(1024));
const size = cellValue / 1024 ** index;
const formattedSize = size.toFixed(digits);
return `${formattedSize} ${unitArr[index]}`;
},
});
},
useVbenForm,
});