diff --git a/apps/web-antd/src/adapter/vxe-table.ts b/apps/web-antd/src/adapter/vxe-table.ts index 7fe887645..888287c60 100644 --- a/apps/web-antd/src/adapter/vxe-table.ts +++ b/apps/web-antd/src/adapter/vxe-table.ts @@ -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, }); diff --git a/apps/web-antd/src/views/infra/file/data.ts b/apps/web-antd/src/views/infra/file/data.ts index 56d583134..9ee70319b 100644 --- a/apps/web-antd/src/views/infra/file/data.ts +++ b/apps/web-antd/src/views/infra/file/data.ts @@ -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', diff --git a/apps/web-ele/src/adapter/vxe-table.ts b/apps/web-ele/src/adapter/vxe-table.ts index 8dd26b32b..f323fd76c 100644 --- a/apps/web-ele/src/adapter/vxe-table.ts +++ b/apps/web-ele/src/adapter/vxe-table.ts @@ -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, }); diff --git a/apps/web-ele/src/views/infra/file/data.ts b/apps/web-ele/src/views/infra/file/data.ts index 3e97d47fd..41397fbfe 100644 --- a/apps/web-ele/src/views/infra/file/data.ts +++ b/apps/web-ele/src/views/infra/file/data.ts @@ -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', diff --git a/apps/web-naive/src/adapter/vxe-table.ts b/apps/web-naive/src/adapter/vxe-table.ts index 2c89b04db..44d2f7bfc 100644 --- a/apps/web-naive/src/adapter/vxe-table.ts +++ b/apps/web-naive/src/adapter/vxe-table.ts @@ -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, }); diff --git a/apps/web-naive/src/views/infra/file/data.ts b/apps/web-naive/src/views/infra/file/data.ts index 5741f0bb1..cfae4a391 100644 --- a/apps/web-naive/src/views/infra/file/data.ts +++ b/apps/web-naive/src/views/infra/file/data.ts @@ -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',