From b6e3a583ff1e3cb9f4ad0347dc2c38d403e3a3dd Mon Sep 17 00:00:00 2001
From: dlarmor <121919810@qq.com>
Date: Wed, 15 Mar 2023 10:07:27 +0800
Subject: [PATCH] file finished todo
---
src/utils/index.ts | 9 ++++++++
src/views/infra/file/index.vue | 13 ++----------
src/views/infra/fileConfig/index.vue | 31 +++++++++++-----------------
3 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/src/utils/index.ts b/src/utils/index.ts
index d3058473..c86d4cd8 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -137,3 +137,12 @@ export const generateUUID = () => {
return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
})
}
+
+export const fileSizeFormatter = (row) => {
+ const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
+ const srcSize = parseFloat(row.size)
+ const index = Math.floor(Math.log(srcSize) / Math.log(1024))
+ const size = srcSize / Math.pow(1024, index)
+ const sizeStr = size.toFixed(2) //保留的小数位数
+ return sizeStr + ' ' + unitArr[index]
+}
diff --git a/src/views/infra/file/index.vue b/src/views/infra/file/index.vue
index 7c88ffb0..5137ec3e 100644
--- a/src/views/infra/file/index.vue
+++ b/src/views/infra/file/index.vue
@@ -50,7 +50,7 @@
align="center"
prop="size"
width="120"
- :formatter="sizeFormat"
+ :formatter="fileSizeFormatter"
/>