feat: 看板上下行数据

This commit is contained in:
TsMask
2024-01-29 15:18:02 +08:00
parent e3f206b541
commit c9d571ce1d
3 changed files with 64 additions and 43 deletions

View File

@@ -151,15 +151,25 @@ export function parseSizeFromKbs(sizeByte: number, timeInterval: number): any {
/**
* 字节数转换单位
* @param sizeByte 数值大小
* @returns
* @param bits 比特b大小
* @returns MB
*/
export function formatBytes(bytes: number): string {
if (bytes === 0) {
return '0 B'; // 处理 bytes 为 0 的情况
export function parseSizeFromBytes(bits: number | string): string {
bits = Number(bits) || 0;
const byte = bits / 8;
const kb = byte / 1024;
const mb = kb / 1024;
const gb = mb / 1024;
const tb = gb / 1024;
if (tb >= 1) {
return tb.toFixed(2) + ' TB';
} else if (gb >= 1) {
return gb.toFixed(2) + ' GB';
} else if (mb >= 1) {
return mb.toFixed(2) + ' MB';
} else if (kb >= 1) {
return kb.toFixed(2) + ' KB';
}
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
const unitIndex = Math.floor(Math.log2(bytes) / 10);
const result =(bytes / Math.pow(1024, unitIndex)).toFixed(2) + ' ' + units[unitIndex];
return result;
return bits + ' B';
}