mirror of
https://gitee.com/yudaocode/yudao-ui-admin-vben.git
synced 2025-12-30 10:32:25 +00:00
feat: add formatFileSize
This commit is contained in:
@@ -350,6 +350,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,
|
||||
});
|
||||
|
||||
@@ -76,15 +76,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
field: 'size',
|
||||
title: '文件大小',
|
||||
minWidth: 80,
|
||||
formatter: ({ cellValue }) => {
|
||||
// TODO @xingyu:【优先级:中】要不要搞到一个方法里?
|
||||
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(2);
|
||||
return `${formattedSize} ${unitArr[index]}`;
|
||||
},
|
||||
formatter: 'formatFileSize',
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -76,15 +76,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
field: 'size',
|
||||
title: '文件大小',
|
||||
minWidth: 80,
|
||||
formatter: ({ cellValue }) => {
|
||||
// TODO @xingyu:【优先级:中】要不要搞到一个方法里?
|
||||
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(2);
|
||||
return `${formattedSize} ${unitArr[index]}`;
|
||||
},
|
||||
formatter: 'formatFileSize',
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
|
||||
@@ -202,6 +202,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,
|
||||
});
|
||||
|
||||
@@ -76,15 +76,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
field: 'size',
|
||||
title: '文件大小',
|
||||
minWidth: 80,
|
||||
formatter: ({ cellValue }) => {
|
||||
// TODO @xingyu:【优先级:中】要不要搞到一个方法里?
|
||||
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(2);
|
||||
return `${formattedSize} ${unitArr[index]}`;
|
||||
},
|
||||
formatter: 'formatFileSize',
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
|
||||
Reference in New Issue
Block a user