优化bytes助手函数

This commit is contained in:
2022-10-14 11:57:19 +08:00
parent 77b7258417
commit 947b5ef75f

View File

@@ -1142,15 +1142,8 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
}, },
bytes: (data) => { bytes: (data) => {
var size = admin.table.returnColumnValue(data); var size = admin.table.returnColumnValue(data);
if (size > 0) { sizeReadable = admin.bytes(size)
const kb = 1024 return sizeReadable
const unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(size) / Math.log(kb))
const num = (size / Math.pow(kb, i)).toPrecision(3)
const u = unit[i]
return num + u;
}
return '0B'
}, },
copyText(data) { copyText(data) {
var option = data.LAY_COL; var option = data.LAY_COL;
@@ -2314,6 +2307,18 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
return !1 return !1
}, },
bytes(size) {
if (size > 0) {
const kb = 1024
const unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(size) / Math.log(kb))
const num = (size / Math.pow(kb, i)).toPrecision(3)
const u = unit[i]
return num + u;
}
return '0B';
}
}; };
return admin; return admin;
}); });