From 11d4e2ea177a5c3d1522448e1eb2ab45eab54052 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 15 Mar 2023 20:35:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=A8=20fileSizeFormatter=20?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index c86d4cd8..e016c1e2 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -138,9 +138,18 @@ export const generateUUID = () => { }) } -export const fileSizeFormatter = (row) => { +/** + * element plus 的文件大小 Formatter 实现 + * + * @param row 行数据 + * @param column 字段 + * @param cellValue 字段值 + */ +// @ts-ignore +export const fileSizeFormatter = (row, column, cellValue) => { + const fileSize = cellValue const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] - const srcSize = parseFloat(row.size) + const srcSize = parseFloat(fileSize) const index = Math.floor(Math.log(srcSize) / Math.log(1024)) const size = srcSize / Math.pow(1024, index) const sizeStr = size.toFixed(2) //保留的小数位数