diff --git a/src/components/deskModule/SystemMonitor/index.vue b/src/components/deskModule/SystemMonitor/index.vue index 88588d2..254679a 100644 --- a/src/components/deskModule/SystemMonitor/index.vue +++ b/src/components/deskModule/SystemMonitor/index.vue @@ -3,6 +3,7 @@ import { onMounted, onUnmounted, ref } from 'vue' import { NProgress } from 'naive-ui' import { getAll } from '@/api/system/systemMonitor' import { SvgIcon } from '@/components/common' +import { bytesToSize } from '@/utils/cmn' interface ProgressStyle { color: string @@ -35,12 +36,20 @@ function correctionNumber(v: number, keepNum = 2): number { return v === 0 ? 0 : Number(v.toFixed(keepNum)) } -function formatMemoryToGB(v: number): number { - return correctionNumber(v / 1024 / 1024 / 1024) +// function formatMemoryToGB(v: number): number { +// return correctionNumber(v / 1024 / 1024 / 1024) +// } + +function formatMemorySize(v: number): string { + return bytesToSize(v) } -function formatdiskToGB(v: number): number { - return correctionNumber(v / 1024) +function formatdiskSize(v: number): string { + return bytesToSize(v) +} + +function formatdiskToByte(v: number): number { + return v * 1024 * 1024 } onMounted(() => { getData() @@ -100,10 +109,10 @@ onUnmounted(() => {
- 内存 + RAM - {{ 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) }}
{ {{ item.mountpoint }} - {{ formatdiskToGB(item.total || 0) }} GB/{{ formatdiskToGB(item.used || 0) }} GB + {{ formatdiskSize(formatdiskToByte(item.total || 0)) }}/{{ formatdiskSize(formatdiskToByte(item.free || 0)) }}
{ } } } + +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]}` +}