feat: task detail files show completed percent

This commit is contained in:
Dr_rOot
2023-04-19 18:14:16 +08:00
parent a215df0360
commit 3ffce0566b
2 changed files with 18 additions and 9 deletions
@@ -25,19 +25,26 @@
width="80">
<template slot-scope="scope">{{ scope.row.extension | removeExtensionDot }}</template>
</el-table-column>
<el-table-column
v-if="mode === 'DETAIL'"
:label="`%`"
align="right"
width="50">
<template slot-scope="scope">{{ calcProgress(scope.row.length, scope.row.completedLength, 1) }}</template>
</el-table-column>
<el-table-column
v-if="mode === 'DETAIL'"
:label="`✓`"
align="right"
width="85">
<template slot-scope="scope">{{ scope.row.completedLength | bytesToSize }}</template>
</el-table-column>
<el-table-column
:label="$t('task.file-size')"
align="right"
width="85">
<template slot-scope="scope">{{ scope.row.length | bytesToSize }}</template>
</el-table-column>
<el-table-column
v-if="mode === 'DETAIL'"
:label="$t('task.file-completed-size')"
align="right"
width="95">
<template slot-scope="scope">{{ scope.row.completedLength | bytesToSize }}</template>
</el-table-column>
</el-table>
</div>
<el-row class="file-filters" :gutter="12">
@@ -84,6 +91,7 @@
} from '@shared/constants'
import {
bytesToSize,
calcProgress,
filterVideoFiles,
filterAudioFiles,
filterImageFiles,
@@ -149,6 +157,7 @@
}
},
methods: {
calcProgress,
toggleAllSelection () {
if (!this.$refs.torrentTable) {
return
+2 -2
View File
@@ -101,14 +101,14 @@ export function peerIdParser (str) {
return result
}
export function calcProgress (totalLength, completedLength) {
export function calcProgress (totalLength, completedLength, decimal = 2) {
const total = parseInt(totalLength, 10)
const completed = parseInt(completedLength, 10)
if (total === 0 || completed === 0) {
return 0
}
const percentage = completed / total * 100
const result = parseFloat(percentage.toFixed(2))
const result = parseFloat(percentage.toFixed(decimal))
return result
}