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