完整横条显示并对容量尺寸单位优化自动识别
This commit is contained in:
parent
fe967a9314
commit
8dfec7e4b7
@ -3,6 +3,7 @@ import { onMounted, onUnmounted, ref } from 'vue'
|
|||||||
import { NProgress } from 'naive-ui'
|
import { NProgress } from 'naive-ui'
|
||||||
import { getAll } from '@/api/system/systemMonitor'
|
import { getAll } from '@/api/system/systemMonitor'
|
||||||
import { SvgIcon } from '@/components/common'
|
import { SvgIcon } from '@/components/common'
|
||||||
|
import { bytesToSize } from '@/utils/cmn'
|
||||||
|
|
||||||
interface ProgressStyle {
|
interface ProgressStyle {
|
||||||
color: string
|
color: string
|
||||||
@ -35,12 +36,20 @@ function correctionNumber(v: number, keepNum = 2): number {
|
|||||||
return v === 0 ? 0 : Number(v.toFixed(keepNum))
|
return v === 0 ? 0 : Number(v.toFixed(keepNum))
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatMemoryToGB(v: number): number {
|
// function formatMemoryToGB(v: number): number {
|
||||||
return correctionNumber(v / 1024 / 1024 / 1024)
|
// return correctionNumber(v / 1024 / 1024 / 1024)
|
||||||
|
// }
|
||||||
|
|
||||||
|
function formatMemorySize(v: number): string {
|
||||||
|
return bytesToSize(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatdiskToGB(v: number): number {
|
function formatdiskSize(v: number): string {
|
||||||
return correctionNumber(v / 1024)
|
return bytesToSize(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatdiskToByte(v: number): number {
|
||||||
|
return v * 1024 * 1024
|
||||||
}
|
}
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getData()
|
getData()
|
||||||
@ -100,10 +109,10 @@ onUnmounted(() => {
|
|||||||
<div>
|
<div>
|
||||||
<div class="mb-1">
|
<div class="mb-1">
|
||||||
<span>
|
<span>
|
||||||
内存
|
RAM
|
||||||
</span>
|
</span>
|
||||||
<span class="float-right">
|
<span class="float-right">
|
||||||
{{ formatMemoryToGB(systemMonitorData?.memoryInfo.total || 0) }} GB/{{ correctionNumber(formatMemoryToGB(systemMonitorData?.memoryInfo.total || 0) - formatMemoryToGB(systemMonitorData?.memoryInfo.free || 0)) }} GB
|
{{ formatMemorySize(systemMonitorData?.memoryInfo.total || 0) }}/{{ formatMemorySize(systemMonitorData?.memoryInfo.free || 0) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<NProgress
|
<NProgress
|
||||||
@ -143,7 +152,7 @@ onUnmounted(() => {
|
|||||||
{{ item.mountpoint }}
|
{{ item.mountpoint }}
|
||||||
</span>
|
</span>
|
||||||
<span class="float-right">
|
<span class="float-right">
|
||||||
{{ formatdiskToGB(item.total || 0) }} GB/{{ formatdiskToGB(item.used || 0) }} GB
|
{{ formatdiskSize(formatdiskToByte(item.total || 0)) }}/{{ formatdiskSize(formatdiskToByte(item.free || 0)) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<NProgress
|
<NProgress
|
||||||
|
@ -221,3 +221,11 @@ export async function copyToClipboard(text: string): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function bytesToSize(bytes: number) {
|
||||||
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']
|
||||||
|
if (bytes === 0)
|
||||||
|
return '0B'
|
||||||
|
const i = parseInt(String(Math.floor(Math.log(bytes) / Math.log(1024))))
|
||||||
|
return `${(bytes / 1024 ** i).toFixed(1)} ${sizes[i]}`
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user