From 8dfec7e4b78cc393fad96df9d452c5f2dd4933bb Mon Sep 17 00:00:00 2001 From: Sun <95302870@qq.com> Date: Wed, 3 Jan 2024 20:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=95=B4=E6=A8=AA=E6=9D=A1=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=B9=B6=E5=AF=B9=E5=AE=B9=E9=87=8F=E5=B0=BA=E5=AF=B8?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8=E8=AF=86?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deskModule/SystemMonitor/index.vue | 23 +++++++++++++------ src/utils/cmn/index.ts | 8 +++++++ 2 files changed, 24 insertions(+), 7 deletions(-) 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]}` +}