feat: 网站设置增加缓存列表与清除功能

This commit is contained in:
Argo Zhang 2020-01-26 14:24:45 +08:00
parent e8b824c6a0
commit 54835998dc
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
6 changed files with 103 additions and 39 deletions

View File

@ -161,6 +161,12 @@ namespace Bootstrap.Admin.Components
[Parameter] [Parameter]
public Func<int, int, string, QueryData<TItem>>? OnQuery { get; set; } public Func<int, int, string, QueryData<TItem>>? OnQuery { get; set; }
/// <summary>
/// 点击翻页回调方法
/// </summary>
[Parameter]
public Func<IEnumerable<TItem>>? OnDataSourceQuery { get; set; }
/// <summary> /// <summary>
/// 新建按钮回调方法 /// 新建按钮回调方法
/// </summary> /// </summary>
@ -226,7 +232,8 @@ namespace Bootstrap.Admin.Components
/// <summary> /// <summary>
/// 获得/设置 EditModel 实例 /// 获得/设置 EditModel 实例
/// </summary> /// </summary>
protected TItem EditModel { get; set; } [Parameter]
public TItem EditModel { get; set; }
/// <summary> /// <summary>
/// 获得/设置 QueryModel 实例 /// 获得/设置 QueryModel 实例
@ -251,10 +258,14 @@ namespace Bootstrap.Admin.Components
/// </summary> /// </summary>
protected override void OnInitialized() 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) if (OnQuery != null)
{ {
var queryData = OnQuery.Invoke(1, DefaultPageItems, SearchText); var queryData = OnQuery(1, DefaultPageItems, SearchText);
Items = queryData.Items; Items = queryData.Items;
TotalCount = queryData.TotalCount; TotalCount = queryData.TotalCount;
} }
@ -388,7 +399,7 @@ namespace Bootstrap.Admin.Components
/// </summary> /// </summary>
protected void Query() protected void Query()
{ {
if (OnQuery != null) Query(OnQuery.Invoke(PageIndex, PageItems, SearchText)); if (OnQuery != null) Query(OnQuery(PageIndex, PageItems, SearchText));
} }
/// <summary> /// <summary>

View File

@ -1,5 +1,6 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Cache;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Concurrent; 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.IsResource)), "菜单类型");
_displayNameCache.TryAdd((typeof(BootstrapMenu), nameof(BootstrapMenu.Application)), "所属应用"); _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; return services;
} }

View File

@ -192,13 +192,31 @@
<div class="card-header"> <div class="card-header">
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<span class="flex-fill">网站缓存</span> <span class="flex-fill">网站缓存</span>
<ConditionComponent AuthKey="clearAllCache">
<a href="#" class="fa fa-times-circle-o" title="全部清除" data-toggle="tooltip" data-placement="left" asp-auth=""></a>
</ConditionComponent>
<a href="#" class="fa fa-refresh ml-3" title="点击刷新" data-toggle="tooltip"></a>
</div> </div>
</div> </div>
<div class="card-body"> <div class="card-body">
<Table @ref="Table" Id="settings-cache" TItem="Longbow.Cache.ICacheItem" EditModel="ConsoleCaCheModel" OnDataSourceQuery="QueryData">
<TableHeader>
<LgbTableHeader TItem="string" @bind-Value="@context.Desc"></LgbTableHeader>
<LgbTableHeader TItem="int" @bind-Value="@context.Interval"></LgbTableHeader>
<LgbTableHeader TItem="string" @bind-Value="@context.Key"></LgbTableHeader>
<LgbTableHeader TItem="string" @bind-Value="@context.Value"></LgbTableHeader>
<LgbTableHeader TItem="int" @bind-Value="@context.ElapsedSeconds"></LgbTableHeader>
</TableHeader>
<RowTemplate>
<td>@context.Desc</td>
<td>@(context.Interval / 1000)</td>
<td>@context.Key</td>
<td>@context.Value</td>
<td>@context.ElapsedSeconds</td>
</RowTemplate>
<TableToolbarTemplate>
<TableToolbarButton class="btn btn-danger" Icon="fa fa-trash-o" Title="一键清除" OnClick="ClearCache" />
</TableToolbarTemplate>
<ButtonTemplate>
<button class='btn btn-sm btn-danger' asp-auth="del" @onclick="e => DeleteCache(context.Key)"><i class='fa fa-remove'></i><span>删除</span></button>
</ButtonTemplate>
</Table>
</div> </div>
</div> </div>
<Toast @ref="Toast" Id="toast_settings"></Toast> <Toast @ref="Toast" Id="toast_settings"></Toast>

View File

@ -3,7 +3,9 @@ using Bootstrap.Admin.Extensions;
using Bootstrap.Admin.Shared; using Bootstrap.Admin.Shared;
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Cache;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Bootstrap.Pages.Admin.Components namespace Bootstrap.Pages.Admin.Components
@ -18,12 +20,27 @@ namespace Bootstrap.Pages.Admin.Components
/// </summary> /// </summary>
protected EditModel Model { get; set; } = new EditModel(); protected EditModel Model { get; set; } = new EditModel();
/// <summary>
/// 获得 CacheItem 实例
/// </summary>
protected ICacheItem ConsoleCaCheModel { get; set; } = new CacheItem("");
/// <summary>
/// 获得 CacheItem 实例
/// </summary>
protected ICacheItem ClientCaCheModel { get; set; } = new CacheItem("");
/// <summary> /// <summary>
/// 获得/设置 默认母版页实例 /// 获得/设置 默认母版页实例
/// </summary> /// </summary>
[CascadingParameter(Name = "Default")] [CascadingParameter(Name = "Default")]
public DefaultLayout? RootLayout { get; protected set; } public DefaultLayout? RootLayout { get; protected set; }
/// <summary>
/// 获得/设置 Table 实例
/// </summary>
protected Table<ICacheItem>? Table { get; set; }
/// <summary> /// <summary>
/// Toast 组件实例 /// Toast 组件实例
/// </summary> /// </summary>
@ -56,6 +73,21 @@ namespace Bootstrap.Pages.Admin.Components
Model.Themes = DictHelper.RetrieveThemes(); Model.Themes = DictHelper.RetrieveThemes();
} }
/// <summary>
/// QueryData 方法
/// </summary>
protected IEnumerable<ICacheItem> QueryData() => CacheManager.ToList();
/// <summary>
/// 清除指定键值的方法
/// </summary>
protected void DeleteCache(string key) => CacheManager.Clear(key);
/// <summary>
/// 清除所有缓存方法
/// </summary>
protected void ClearCache() => CacheManager.Clear();
/// <summary> /// <summary>
/// 保存 Balzor 方法 /// 保存 Balzor 方法
/// </summary> /// </summary>

View File

@ -2,10 +2,10 @@
@inherits TableBase<TItem> @inherits TableBase<TItem>
<div class="bootstrap-table"> <div class="bootstrap-table">
<div class="fixed-table-toolbar">
<div class="float-left bs-bars">
@if(ShowToolBar) @if(ShowToolBar)
{ {
<div class="fixed-table-toolbar">
<div class="float-left bs-bars">
<TableToolbar> <TableToolbar>
<TableToolbarContent /> <TableToolbarContent />
@if(ShowDefaultButtons) @if(ShowDefaultButtons)
@ -16,18 +16,14 @@
} }
@TableToolbarTemplate @TableToolbarTemplate
</TableToolbar> </TableToolbar>
}
</div> </div>
<div class="float-right columns columns-right"> <div class="float-right columns columns-right">
@if(ShowToolBar)
{
@if(ShowRefresh) @if(ShowRefresh)
{ {
<button class="btn btn-secondary" type="button" title="刷新" @onclick="Query"> <button class="btn btn-secondary" type="button" title="刷新" @onclick="Query">
<i class="fa fa-refresh"></i><span>刷新</span> <i class="fa fa-refresh"></i><span>刷新</span>
</button> </button>
} }
}
</div> </div>
@if(ShowSearch) @if(ShowSearch)
{ {
@ -49,7 +45,7 @@
</div> </div>
} }
</div> </div>
}
<div class="@(FixedHeader ? "table-wrapper table-fixed-header table-fixed" : "table-wrapper")"> <div class="@(FixedHeader ? "table-wrapper table-fixed-header table-fixed" : "table-wrapper")">
@if(FixedHeader) @if(FixedHeader)
{ {

View File

@ -8,7 +8,7 @@
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.1.1" /> <PackageReference Include="Bootstrap.Security.DataAccess" Version="3.1.1" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.1.1" /> <PackageReference Include="Bootstrap.Security.Mvc" Version="3.1.1" />
<PackageReference Include="Longbow" Version="3.1.0" /> <PackageReference Include="Longbow" Version="3.1.0" />
<PackageReference Include="Longbow.Cache" Version="3.1.1" /> <PackageReference Include="Longbow.Cache" Version="3.1.2-beta-01" />
<PackageReference Include="Longbow.Data" Version="3.1.0" /> <PackageReference Include="Longbow.Data" Version="3.1.0" />
<PackageReference Include="Longbow.GiteeAuth" Version="3.1.0" /> <PackageReference Include="Longbow.GiteeAuth" Version="3.1.0" />
<PackageReference Include="Longbow.GitHubAuth" Version="3.1.0" /> <PackageReference Include="Longbow.GitHubAuth" Version="3.1.0" />