feat: add formatFileSize
This commit is contained in:
@@ -350,6 +350,17 @@ setupVbenVxeTable({
|
|||||||
return `${erpNumberFormatter(fenToYuan(cellValue), digits)}`;
|
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,
|
useVbenForm,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -76,15 +76,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
field: 'size',
|
field: 'size',
|
||||||
title: '文件大小',
|
title: '文件大小',
|
||||||
minWidth: 80,
|
minWidth: 80,
|
||||||
formatter: ({ cellValue }) => {
|
formatter: 'formatFileSize',
|
||||||
// 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]}`;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'type',
|
field: 'type',
|
||||||
|
|||||||
@@ -340,6 +340,17 @@ setupVbenVxeTable({
|
|||||||
return `${erpNumberFormatter(fenToYuan(cellValue), digits)}`;
|
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,
|
useVbenForm,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -76,15 +76,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
field: 'size',
|
field: 'size',
|
||||||
title: '文件大小',
|
title: '文件大小',
|
||||||
minWidth: 80,
|
minWidth: 80,
|
||||||
formatter: ({ cellValue }) => {
|
formatter: 'formatFileSize',
|
||||||
// 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]}`;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'type',
|
field: 'type',
|
||||||
|
|||||||
@@ -202,6 +202,17 @@ setupVbenVxeTable({
|
|||||||
return `${erpNumberFormatter(fenToYuan(cellValue), digits)}`;
|
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,
|
useVbenForm,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -76,15 +76,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
field: 'size',
|
field: 'size',
|
||||||
title: '文件大小',
|
title: '文件大小',
|
||||||
minWidth: 80,
|
minWidth: 80,
|
||||||
formatter: ({ cellValue }) => {
|
formatter: 'formatFileSize',
|
||||||
// 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]}`;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'type',
|
field: 'type',
|
||||||
|
|||||||
Reference in New Issue
Block a user