首页图表改造,对接数据接口

This commit is contained in:
zCans
2023-03-26 22:33:17 +08:00
parent 07de9eec98
commit 98ac3c67c1
7 changed files with 146 additions and 95 deletions
+29
View File
@@ -0,0 +1,29 @@
const SIZE_UNINTS = ['B', 'KB', 'MB', 'GB', 'TB']
const SIZE_SYSTEM = 1024
/**
* 根据字节数获取大小描述
* 1、小于1024字节的以B为单位
* 2、小于1024KB的以KB为单位
* 3、小于1024M的以MB为单位
* 4、小于1024G的以GB为单位
* 5、其他以TB为单位
*/
export function getSizeDescByByteCount(byteCount) {
if (byteCount <= 0) {
return '0B'
}
let res = byteCount
let index = 0
while (index < SIZE_UNINTS.length && res >= SIZE_SYSTEM) {
res /= SIZE_SYSTEM
index++
}
if (index >= SIZE_UNINTS.length) {
index = SIZE_UNINTS.length - 1
res *= 1024
}
return parseFloat(res.toFixed(2)) + SIZE_UNINTS[index]
}