From 54835998dcedcac14375870935f777fa8020ff01 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 26 Jan 2020 14:24:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=91=E7=AB=99=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98=E5=88=97=E8=A1=A8=E4=B8=8E?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bootstrap.Admin/Components/TableBase.cs | 19 +++++-- .../Extensions/DisplayNamesExtensions.cs | 7 +++ .../Pages/Admin/Settings.razor | 26 +++++++-- .../Pages/Components/SettingsBase.cs | 32 +++++++++++ src/admin/Bootstrap.Admin/Shared/Table.razor | 56 +++++++++---------- .../Bootstrap.DataAccess.csproj | 2 +- 6 files changed, 103 insertions(+), 39 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Components/TableBase.cs b/src/admin/Bootstrap.Admin/Components/TableBase.cs index 6447c497..a2605743 100644 --- a/src/admin/Bootstrap.Admin/Components/TableBase.cs +++ b/src/admin/Bootstrap.Admin/Components/TableBase.cs @@ -161,6 +161,12 @@ namespace Bootstrap.Admin.Components [Parameter] public Func>? OnQuery { get; set; } + /// + /// 点击翻页回调方法 + /// + [Parameter] + public Func>? OnDataSourceQuery { get; set; } + /// /// 新建按钮回调方法 /// @@ -226,7 +232,8 @@ namespace Bootstrap.Admin.Components /// /// 获得/设置 EditModel 实例 /// - protected TItem EditModel { get; set; } + [Parameter] + public TItem EditModel { get; set; } /// /// 获得/设置 QueryModel 实例 @@ -251,10 +258,14 @@ namespace Bootstrap.Admin.Components /// protected override void OnInitialized() { - if (OnAdd != null) EditModel = OnAdd.Invoke(); + if (EditModel == null && OnAdd != null) EditModel = OnAdd.Invoke(); + if (OnDataSourceQuery != null) + { + Items = OnDataSourceQuery(); + } if (OnQuery != null) { - var queryData = OnQuery.Invoke(1, DefaultPageItems, SearchText); + var queryData = OnQuery(1, DefaultPageItems, SearchText); Items = queryData.Items; TotalCount = queryData.TotalCount; } @@ -388,7 +399,7 @@ namespace Bootstrap.Admin.Components /// protected void Query() { - if (OnQuery != null) Query(OnQuery.Invoke(PageIndex, PageItems, SearchText)); + if (OnQuery != null) Query(OnQuery(PageIndex, PageItems, SearchText)); } /// diff --git a/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs b/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs index 9eab8d6d..3fd12411 100644 --- a/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs +++ b/src/admin/Bootstrap.Admin/Extensions/DisplayNamesExtensions.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using Bootstrap.Security; +using Longbow.Cache; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Concurrent; @@ -43,6 +44,12 @@ namespace Microsoft.AspNetCore.Builder _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.IsResource)), "菜单类型"); _displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Application)), "所属应用"); + // 缓存显示名称 + _displayNameCache.TryAdd((typeof(CacheItem), nameof(CacheItem.Key)), "缓存 Key"); + _displayNameCache.TryAdd((typeof(CacheItem), nameof(CacheItem.Value)), "缓存值"); + _displayNameCache.TryAdd((typeof(CacheItem), nameof(CacheItem.Interval)), "缓存时长(秒)"); + _displayNameCache.TryAdd((typeof(CacheItem), nameof(CacheItem.ElapsedSeconds)), "已过时长(秒)"); + _displayNameCache.TryAdd((typeof(CacheItem), nameof(CacheItem.Desc)), "缓存说明"); return services; } diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor index f3f18d3b..d6b30d55 100644 --- a/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor +++ b/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor @@ -192,13 +192,31 @@
网站缓存 - - - -
+ + + + + + + + + + + + + + + + + + + + + +
@context.Desc@(context.Interval / 1000)@context.Key@context.Value@context.ElapsedSeconds
diff --git a/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs index 11f6e0ac..c556e047 100644 --- a/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs @@ -3,7 +3,9 @@ using Bootstrap.Admin.Extensions; using Bootstrap.Admin.Shared; using Bootstrap.DataAccess; using Bootstrap.Security; +using Longbow.Cache; using Microsoft.AspNetCore.Components; +using System; using System.Collections.Generic; namespace Bootstrap.Pages.Admin.Components @@ -18,12 +20,27 @@ namespace Bootstrap.Pages.Admin.Components ///
protected EditModel Model { get; set; } = new EditModel(); + /// + /// 获得 CacheItem 实例 + /// + protected ICacheItem ConsoleCaCheModel { get; set; } = new CacheItem(""); + + /// + /// 获得 CacheItem 实例 + /// + protected ICacheItem ClientCaCheModel { get; set; } = new CacheItem(""); + /// /// 获得/设置 默认母版页实例 /// [CascadingParameter(Name = "Default")] public DefaultLayout? RootLayout { get; protected set; } + /// + /// 获得/设置 Table 实例 + /// + protected Table? Table { get; set; } + /// /// Toast 组件实例 /// @@ -56,6 +73,21 @@ namespace Bootstrap.Pages.Admin.Components Model.Themes = DictHelper.RetrieveThemes(); } + /// + /// QueryData 方法 + /// + protected IEnumerable QueryData() => CacheManager.ToList(); + + /// + /// 清除指定键值的方法 + /// + protected void DeleteCache(string key) => CacheManager.Clear(key); + + /// + /// 清除所有缓存方法 + /// + protected void ClearCache() => CacheManager.Clear(); + /// /// 保存 Balzor 方法 /// diff --git a/src/admin/Bootstrap.Admin/Shared/Table.razor b/src/admin/Bootstrap.Admin/Shared/Table.razor index 38a52fdb..becb2f03 100644 --- a/src/admin/Bootstrap.Admin/Shared/Table.razor +++ b/src/admin/Bootstrap.Admin/Shared/Table.razor @@ -2,10 +2,10 @@ @inherits TableBase
-
-
- @if(ShowToolBar) - { + @if(ShowToolBar) + { +
+
@if(ShowDefaultButtons) @@ -16,40 +16,36 @@ } @TableToolbarTemplate - } -
-
- @if(ShowToolBar) - { +
+
@if(ShowRefresh) { } - } -
- @if(ShowSearch) - { - - + } +
+ }
@if(FixedHeader) { diff --git a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index dc388bd2..5442cfcd 100644 --- a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -8,7 +8,7 @@ - +