From 9612e48bbb408da268f46c3ef66655dd465e6b76 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 3 Jan 2022 02:31:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=81=A5=E5=BA=B7?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Admin/Healths.razor | 29 ++++++ .../Pages/Admin/Healths.razor.cs | 97 ++++++++++++++----- .../BootstrapAdmin.Web/Utils/LookupHelper.cs | 12 +++ .../BootstrapAdmin.Web/wwwroot/css/site.css | 8 -- 4 files changed, 112 insertions(+), 34 deletions(-) diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor index 6c3d4293..de5a5105 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor @@ -1 +1,30 @@ @page "/Admin/Healths" +@using Bootstrap.Security.Blazor.HealthChecks + + + +
+ 健康检查结果 + @Duration + @GetTagText() +
+
+ + + + + + + + + + + + + + +
+
+
diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor.cs index 520e1ea5..0a8eebf3 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Healths.razor.cs @@ -1,4 +1,7 @@ -using BootstrapAdmin.Web.Services; +using Bootstrap.Security.Blazor.HealthChecks; +using BootstrapAdmin.Web.Components; +using BootstrapAdmin.Web.Services; +using BootstrapAdmin.Web.Utils; using Microsoft.Extensions.Diagnostics.HealthChecks; using System; using System.Text.Json; @@ -16,32 +19,74 @@ public partial class Healths [NotNull] private NavigationManager? NavigationManager { get; set; } - /// - /// OnInitializedAsync - /// - /// - protected override async Task OnInitializedAsync() + private TimeSpan Duration { get; set; } + + private HealthStatus Status { get; set; } + + [Inject] + [NotNull] + private DialogService? DialogService { get; set; } + + [NotNull] + private HttpClient? Client { get; set; } + + protected override void OnInitialized() { - await base.OnInitializedAsync(); + base.OnInitialized(); - var client = HttpClientFactory.CreateClient(); - client.BaseAddress = new Uri(NavigationManager.BaseUri); - var payload = await client.GetStringAsync("/Healths"); - - var serializeOption = new JsonSerializerOptions - { - PropertyNamingPolicy = null, - PropertyNameCaseInsensitive = true - }; - serializeOption.Converters.Add(new StringToTimeSpanConverter()); - - var report = JsonSerializer.Deserialize(payload, serializeOption); - if (report != null) - { - foreach (var entry in report.Keys) - { - var item = report.Entries[entry]; - } - } + Client = HttpClientFactory.CreateClient(); + Client.BaseAddress = new Uri(NavigationManager.BaseUri); } + + private async Task> OnQueryAsync(QueryPageOptions options) + { + var payload = await Client.GetStringAsync("/Healths"); + var report = HealthsCheckHelper.Parse(payload); + + var ret = new QueryData() + { + IsSorted = true, + IsFiltered = true, + IsSearch = true + }; + + ret.Items = report.Items; + Duration = report.Duration; + Status = report.Status; + + return ret; + } + + private static List GetNameLookup() => LookupHelper.GetCheckItems(); + + private string? GetTagText(HealthStatus? status = null) => (status ?? Status) switch + { + HealthStatus.Healthy => "健康", + HealthStatus.Degraded => "亚健康", + _ => "不健康" + }; + + private Color GetTagColor(HealthStatus? status = null) => (status ?? Status) switch + { + HealthStatus.Healthy => Color.Success, + HealthStatus.Degraded => Color.Warning, + _ => Color.Danger + }; + + private string? GetTagIcon(HealthStatus? status = null) => (status ?? Status) switch + { + HealthStatus.Healthy => "fa fa-check-circle", + HealthStatus.Degraded => "fa fa-exclamation-circle", + _ => "fa fa-times-circle" + }; + + private Task OnRowButtonClick(HealthsCheckReportItem item) => DialogService.Show(new DialogOption() + { + Title = $"{LookupHelper.GetCheckItems().FirstOrDefault(i => i.Value == item.Name)?.Text} - 详细数据", + IsScrolling = true, + Component = BootstrapDynamicComponent.CreateComponent(new Dictionary + { + { nameof(HealthCheckDetails.Data), item.Data } + }) + }); } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Utils/LookupHelper.cs b/src/blazor/admin/BootstrapAdmin.Web/Utils/LookupHelper.cs index 0c6a8838..07154199 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Utils/LookupHelper.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Utils/LookupHelper.cs @@ -15,4 +15,16 @@ static class LookupHelper new SelectedItem("App", "应用程序"), new SelectedItem("DB", "数据库") }; + + public static List GetCheckItems() => new() + { + new("db", "数据库"), + new("environment", "环境变量"), + new("dotnet-runtime", "运行时"), + new("file", "文件系统"), + new("gc", "回收器"), + new("app-mem", "程序内存"), + new("sys-mem", "系统内存"), + new("Gitee", "Gitee") + }; } diff --git a/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css b/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css index f2cec0aa..210edf02 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css +++ b/src/blazor/admin/BootstrapAdmin.Web/wwwroot/css/site.css @@ -45,14 +45,6 @@ height: calc(100vh - var(--bb-layout-header-height) - var(--bb-tab-header-height) - var(--bb-footer-height)); } -.table-scroll { - overflow: hidden; -} - - .table-scroll:hover { - overflow-y: auto; - } - .tabs-body-content .error-stack { height: calc(100vh - var(--bb-layout-header-height) - var(--bb-tab-header-height) - var(--bb-footer-height)); overflow: auto;