A full-featured download manager.
refactor: util bytesToSize precision
Dr_rOota9f5312a90c2
diff --git a/src/renderer/components/Task/TaskProgressInfo.vue b/src/renderer/components/Task/TaskProgressInfo.vueindex b92c5b34..d5564088 100644--- a/src/renderer/components/Task/TaskProgressInfo.vue+++ b/src/renderer/components/Task/TaskProgressInfo.vue@@ -2,8 +2,8 @@<el-row class="task-progress-info"><el-col :span="6" class="task-progress-info-left"><div v-if="task.completedLength > 0 || task.totalLength > 0">- <span>{{ task.completedLength | bytesToSize }}</span>- <span v-if="task.totalLength > 0"> / {{ task.totalLength | bytesToSize }}</span>+ <span>{{ task.completedLength | bytesToSize(2) }}</span>+ <span v-if="task.totalLength > 0"> / {{ task.totalLength | bytesToSize(2) }}</span></div></el-col><el-col :span="18" class="task-progress-info-right">diff --git a/src/renderer/components/TaskDetail/TaskActivity.vue b/src/renderer/components/TaskDetail/TaskActivity.vueindex 8cc1273f..dad98113 100644--- a/src/renderer/components/TaskDetail/TaskActivity.vue+++ b/src/renderer/components/TaskDetail/TaskActivity.vue@@ -33,8 +33,8 @@</el-form-item><el-form-item><div class="form-static-value">- <span>{{ task.completedLength | bytesToSize }}</span>- <span v-if="task.totalLength > 0"> / {{ task.totalLength | bytesToSize }}</span>+ <span>{{ task.completedLength | bytesToSize(2) }}</span>+ <span v-if="task.totalLength > 0"> / {{ task.totalLength | bytesToSize(2) }}</span><span class="task-time-remaining" v-if="isActive && remaining > 0">{{remaining | timeFormat({diff --git a/src/shared/utils/index.js b/src/shared/utils/index.jsindex d431dc48..7278d8c7 100644--- a/src/shared/utils/index.js+++ b/src/shared/utils/index.js@@ -23,13 +23,13 @@ import {UNKNOWN_PEERID} from '@shared/constants'-export function bytesToSize (bytes) {+export function bytesToSize (bytes, precision = 1) {const b = parseInt(bytes, 10)const sizes = ['B', 'KB', 'MB', 'GB', 'TB']if (b === 0) { return '0 KB' }const i = parseInt(Math.floor(Math.log(b) / Math.log(1024)), 10)if (i === 0) { return `${b} ${sizes[i]}` }- return `${(b / (1024 ** i)).toFixed(1)} ${sizes[i]}`+ return `${(b / (1024 ** i)).toFixed(precision)} ${sizes[i]}`}export function bitfieldToPercent (text) {