diff --git a/.claude/settings.local.json b/.claude/settings.local.json index c1dc819..54e6365 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -15,7 +15,8 @@ "Bash(sed -i '' '/Console.WriteLine/d' ViewModels/Base/CrudPageViewModel.cs)", "Bash(sed -i '' '/Console.WriteLine/d' Views/MainWindow.axaml.cs)", "Bash(sed -i '' '/System.Console.WriteLine/d' ViewModels/Device/DeviceHostViewModel.cs)", - "Bash(sed -i '' '/System.Console.WriteLine/d' Views/Device/DeviceHostListView.axaml.cs)" + "Bash(sed -i '' '/System.Console.WriteLine/d' Views/Device/DeviceHostListView.axaml.cs)", + "Bash(git status *)" ] } } diff --git a/Sln.Wcs.UI/Views/Base/EntityEditWindow.axaml b/Sln.Wcs.UI/Views/Base/EntityEditWindow.axaml index 958dca6..5b8ce7e 100644 --- a/Sln.Wcs.UI/Views/Base/EntityEditWindow.axaml +++ b/Sln.Wcs.UI/Views/Base/EntityEditWindow.axaml @@ -15,12 +15,6 @@ - - - - - - diff --git a/Sln.Wcs.UI/Views/MainWindow.axaml b/Sln.Wcs.UI/Views/MainWindow.axaml index 46d209b..9d4f996 100644 --- a/Sln.Wcs.UI/Views/MainWindow.axaml +++ b/Sln.Wcs.UI/Views/MainWindow.axaml @@ -10,7 +10,7 @@ Background="#0A0E14" Foreground="#BCC8D6"> - + @@ -68,5 +68,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sln.Wcs.UI/Views/MainWindow.axaml.cs b/Sln.Wcs.UI/Views/MainWindow.axaml.cs index f1c19d2..c9c0b3d 100644 --- a/Sln.Wcs.UI/Views/MainWindow.axaml.cs +++ b/Sln.Wcs.UI/Views/MainWindow.axaml.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Net.NetworkInformation; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; @@ -15,6 +17,10 @@ public partial class MainWindow : Window { private readonly NavigationViewModel _navVm; private readonly List _openPopups = new(); + private readonly Process _currentProcess; + private TimeSpan _lastCpuTime; + private DateTime _lastCpuCheck; + private readonly DateTime _startTime; public MainWindow(NavigationViewModel navigationVm) { @@ -26,11 +32,19 @@ public partial class MainWindow : Window BuildMenu(); _navVm.LoadDefaultPage(); + _currentProcess = Process.GetCurrentProcess(); + _lastCpuTime = _currentProcess.TotalProcessorTime; + _lastCpuCheck = DateTime.UtcNow; + _startTime = DateTime.UtcNow; + // 时钟 var timer = new System.Timers.Timer(1000); timer.Elapsed += (_, _) => Avalonia.Threading.Dispatcher.UIThread.Post(() => - ClockText.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + { + ClockText.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + RefreshSystemStatus(); + }); timer.Start(); ClockText.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); @@ -38,6 +52,72 @@ public partial class MainWindow : Window LogoutBtn.Click += (_, _) => Close(); } + private void RefreshSystemStatus() + { + // CPU usage + var now = DateTime.UtcNow; + var currentCpuTime = _currentProcess.TotalProcessorTime; + var cpuUsedMs = (currentCpuTime - _lastCpuTime).TotalMilliseconds; + var elapsedMs = (now - _lastCpuCheck).TotalMilliseconds; + _lastCpuTime = currentCpuTime; + _lastCpuCheck = now; + + var cpuPercent = elapsedMs > 0 + ? cpuUsedMs / elapsedMs / Environment.ProcessorCount * 100.0 + : 0.0; + CpuUsageText.Text = $"{cpuPercent:F1}%"; + + // CPU indicator color + var cpuColor = cpuPercent switch + { + < 50 => "#00E676", + < 80 => "#FFB74D", + _ => "#FF5252" + }; + CpuStatusDot.Fill = Brush.Parse(cpuColor); + + // Memory usage + var memBytes = _currentProcess.WorkingSet64; + var memMB = memBytes / 1024.0 / 1024.0; + MemUsageText.Text = memMB >= 1024 + ? $"{memMB / 1024.0:F1} GB" + : $"{memMB:F0} MB"; + + // Memory indicator color + var memColor = memMB switch + { + < 512 => "#00E676", + < 1024 => "#FFB74D", + _ => "#FF5252" + }; + MemStatusDot.Fill = Brush.Parse(memColor); + + // Network status + var isNetworkAvailable = NetworkInterface.GetIsNetworkAvailable(); + var activeInterface = false; + if (isNetworkAvailable) + { + foreach (var ni in NetworkInterface.GetAllNetworkInterfaces()) + { + if (ni.OperationalStatus == OperationalStatus.Up + && ni.NetworkInterfaceType != NetworkInterfaceType.Loopback) + { + activeInterface = true; + break; + } + } + } + + NetStatusDot.Fill = Brush.Parse(activeInterface ? "#00E676" : "#FF5252"); + NetStatusText.Text = activeInterface ? "已连接" : "未连接"; + + // Uptime + var uptime = DateTime.UtcNow - _startTime; + UptimeText.Text = uptime.TotalDays >= 1 + ? $"{(int)uptime.TotalDays}d {uptime.Hours:D2}:{uptime.Minutes:D2}:{uptime.Seconds:D2}" + : $"{uptime.Hours:D2}:{uptime.Minutes:D2}:{uptime.Seconds:D2}"; + } + private void BuildMenu() { MenuContainer.Children.Clear();