浏览代码

fea: 增加子节处理函数

vera_min 1 年之前
父节点
当前提交
253aa6e8e9
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      src/utils/common.ts

+ 10 - 0
src/utils/common.ts

@@ -59,3 +59,13 @@ export function selectDictLabel(data: any[], value: string): string {
     })
     return actions.join('');
 }
+
+export function formatSize(kb:number) {
+    if (kb <= 0) {
+        return "0 B";
+    }
+
+    const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
+    const i = Math.floor(Math.log(kb) / Math.log(1024));
+    return (kb / Math.pow(1024, i)).toFixed(2) + " " + units[i];
+}