From b6f0a4e37f7ae7fdb78908be0836171af7e0da94 Mon Sep 17 00:00:00 2001 From: gaoxq <376340421@qq.com> Date: Thu, 26 Mar 2026 16:43:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/apps/web/SysAnalysisController.java | 13 +++++++------ .../java/com/jeesite/modules/utils/KeyUtil.java | 9 +++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/web-api/src/main/java/com/jeesite/modules/apps/web/SysAnalysisController.java b/web-api/src/main/java/com/jeesite/modules/apps/web/SysAnalysisController.java index e17fb52..ee5bae0 100644 --- a/web-api/src/main/java/com/jeesite/modules/apps/web/SysAnalysisController.java +++ b/web-api/src/main/java/com/jeesite/modules/apps/web/SysAnalysisController.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.system.oshi.CpuInfo; import cn.hutool.system.oshi.OshiUtil; import com.jeesite.modules.apps.Module.ChartInfo; +import com.jeesite.modules.utils.KeyUtil; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -23,17 +24,17 @@ public class SysAnalysisController { long uptimeMs = OshiUtil.getOs().getSystemUptime(); String runTime = DateUtil.formatBetween(uptimeMs); // 系统使用率(红色) - chartInfoList.add(new ChartInfo("sys", "系统使用率", cpuInfo.getSys(), "#F43F5E", runTime)); + chartInfoList.add(new ChartInfo("sys", "系统使用率", cpuInfo.getSys(), KeyUtil.getColor(), runTime)); // 用户使用率(蓝色) - chartInfoList.add(new ChartInfo("user", "用户使用率", cpuInfo.getUser(), "#3B82F6", runTime)); + chartInfoList.add(new ChartInfo("user", "用户使用率", cpuInfo.getUser(), KeyUtil.getColor(), runTime)); // CPU等待率(橙色) - chartInfoList.add(new ChartInfo("wait", "CPU等待率", cpuInfo.getWait(), "#F97316", runTime)); + chartInfoList.add(new ChartInfo("wait", "CPU等待率", cpuInfo.getWait(), KeyUtil.getColor(), runTime)); // CPU空闲率(绿色) - chartInfoList.add(new ChartInfo("free", "CPU空闲率", cpuInfo.getFree(), "#10B981", runTime)); + chartInfoList.add(new ChartInfo("free", "CPU空闲率", cpuInfo.getFree(), KeyUtil.getColor(), runTime)); // CPU总使用率(粉色) - chartInfoList.add(new ChartInfo("used", "CPU总使用率", cpuInfo.getUsed(), "#EC4899", runTime)); + chartInfoList.add(new ChartInfo("used", "CPU总使用率", cpuInfo.getUsed(), KeyUtil.getColor(), runTime)); // 系统运行时间(紫色) - chartInfoList.add(new ChartInfo("time", "系统运行时间", 0, "#8B5CF6", runTime)); + chartInfoList.add(new ChartInfo("time", "系统运行时间", 0, KeyUtil.getColor(), runTime)); return chartInfoList; } } diff --git a/web-api/src/main/java/com/jeesite/modules/utils/KeyUtil.java b/web-api/src/main/java/com/jeesite/modules/utils/KeyUtil.java index 4568fb7..2369090 100644 --- a/web-api/src/main/java/com/jeesite/modules/utils/KeyUtil.java +++ b/web-api/src/main/java/com/jeesite/modules/utils/KeyUtil.java @@ -1,5 +1,6 @@ package com.jeesite.modules.utils; +import java.awt.*; import java.util.Random; public class KeyUtil { @@ -45,4 +46,12 @@ public class KeyUtil { return key.toString(); } } + + public static String getColor() { + int r = 100 + (int) (Math.random() * 140); + int g = 100 + (int) (Math.random() * 140); + int b = 100 + (int) (Math.random() * 140); + Color color = new Color(r, g, b); + return "#" + Integer.toHexString(color.getRGB()).substring(2).toUpperCase(); + } }