This commit is contained in:
Shikong 2023-07-19 17:04:32 +08:00
parent 4b20b67e4d
commit b4441bcdfb
3 changed files with 25 additions and 10 deletions

View File

@ -15,6 +15,7 @@ declare module 'vue' {
ElProgress: typeof import('element-plus/es')['ElProgress']
ElRow: typeof import('element-plus/es')['ElRow']
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
ElStatistic: typeof import('element-plus/es')['ElStatistic']
ElTableV2: typeof import('element-plus/es')['ElTableV2']
ElTabPane: typeof import('element-plus/es')['ElTabPane']
ElTabs: typeof import('element-plus/es')['ElTabs']

View File

@ -7,18 +7,28 @@ const networkSumRate = useNetworkSumRate()
</script>
<template>
<div>实时下载速度:</div>
<div> {{bytesToSizeWithUnit(networkSumRate.recv)}}/s </div>
<div class="text-center">
<el-statistic title="实时下载速度"
:formatter="bytesToSizeWithUnit"
suffix="/s"
:value="networkSumRate.recv">
</el-statistic>
<div>
接收: {{bytesToSizeWithUnit(networkSumCounter.bytesRecv || 0)}}
</div>
<el-statistic title="接收"
:formatter="bytesToSizeWithUnit"
:value="networkSumCounter.bytesRecv">
</el-statistic>
<div>实时上传速度:</div>
<div>{{bytesToSizeWithUnit(networkSumRate.sent)}}/s </div>
<el-statistic title="实时上传速度"
:formatter="bytesToSizeWithUnit"
suffix="/s"
:value="networkSumRate.sent">
</el-statistic>
<div>
发送: {{bytesToSizeWithUnit(networkSumCounter.bytesSent || 0)}}
<el-statistic title="发送"
:formatter="bytesToSizeWithUnit"
:value="networkSumCounter.bytesSent">
</el-statistic>
</div>
</template>

View File

@ -68,7 +68,11 @@ export function convertToFileSizeWithUnit(anySize:string, defaultUnit:FileUnitTy
}
}
export function bytesToSizeWithUnit(byteSize:number){
export function bytesToSizeWithUnit(byteSize?:number){
if(byteSize == null){
return `0${FileUnit.B.unit}`
}
let targetUnitIndex = Object.values(FileUnit).findIndex(item => item.size > byteSize) || 0
let targetUnit:FileUnitType
if(targetUnitIndex > 0){