From 93ae66740f1228bfdabf953f648e9ba3c564d930 Mon Sep 17 00:00:00 2001 From: jlzhou <12020042@qq.com> Date: Wed, 4 Sep 2024 10:11:22 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=96=B0=E5=A2=9E=E5=8E=9F=E5=9E=8B?= =?UTF-8?q?=E6=96=B9=E6=B3=95toFileSize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-ui/src/utils/modules/prototypes.js | 14 ++++++++++++++ uniapp/src/w-components/modules/prototypes.js | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/admin-ui/src/utils/modules/prototypes.js b/admin-ui/src/utils/modules/prototypes.js index d580df8..b8eddc3 100644 --- a/admin-ui/src/utils/modules/prototypes.js +++ b/admin-ui/src/utils/modules/prototypes.js @@ -178,4 +178,18 @@ export default function() { return `${hh.toString().padStart(2,"0")}:${mm.toString().padStart(2,"0")}:${ss.toString().padStart(2,"0")}` } + + Number.prototype.toFileSize = function () { + let value = this; + if (null == value || value == '') { + return "0 Bytes"; + } + var unitArr = new Array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"); + var index = 0; + var srcsize = parseFloat(value); + index = Math.floor(Math.log(srcsize) / Math.log(1024)); + var size = srcsize / Math.pow(1024, index); + size = size.toFixed(2);//保留的小数位数 + return size + unitArr[index]; + } }; \ No newline at end of file diff --git a/uniapp/src/w-components/modules/prototypes.js b/uniapp/src/w-components/modules/prototypes.js index 9fe69b2..48dcaa6 100644 --- a/uniapp/src/w-components/modules/prototypes.js +++ b/uniapp/src/w-components/modules/prototypes.js @@ -181,4 +181,18 @@ export default function () { return `${hh.toString().padStart(2, "0")}:${mm.toString().padStart(2, "0")}:${ss.toString().padStart(2, "0")}` } + + Number.prototype.toFileSize = function () { + let value = this; + if (null == value || value == '') { + return "0 Bytes"; + } + var unitArr = new Array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"); + var index = 0; + var srcsize = parseFloat(value); + index = Math.floor(Math.log(srcsize) / Math.log(1024)); + var size = srcsize / Math.pow(1024, index); + size = size.toFixed(2);//保留的小数位数 + return size + unitArr[index]; + } }; \ No newline at end of file