refactor: Table 组件移除 OnDataSourceQuery 方法

#Comment
统一使用 OnQuery 方法
This commit is contained in:
Argo Zhang 2020-02-04 14:14:50 +08:00
parent 729fb3bde0
commit a34d621f42
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
5 changed files with 23 additions and 18 deletions

View File

@ -161,12 +161,6 @@ namespace Bootstrap.Admin.Pages.Components
[Parameter]
public Func<QueryPageOptions, QueryData<TItem>>? OnQuery { get; set; }
/// <summary>
/// 点击翻页回调方法
/// </summary>
[Parameter]
public Func<IEnumerable<TItem>>? OnDataSourceQuery { get; set; }
/// <summary>
/// 新建按钮回调方法
/// </summary>
@ -280,10 +274,6 @@ namespace Bootstrap.Admin.Pages.Components
Query();
});
if (EditModel == null && OnAdd != null) EditModel = OnAdd.Invoke();
if (OnDataSourceQuery != null)
{
Items = OnDataSourceQuery();
}
if (OnQuery != null)
{
var queryData = OnQuery(new QueryPageOptions() { PageItems = DefaultPageItems, SearchText = SearchText, SortName = SortName, SortOrder = SortOrder });

View File

@ -7,7 +7,7 @@
</div>
</div>
<div class="card-body">
<Table Id="online" EditModel="EditModel" ShowToolBar="true" ShowRefresh="true" TItem="Longbow.Web.OnlineUser" OnDataSourceQuery="QueryData">
<Table Id="online" EditModel="EditModel" ShowToolBar="true" ShowRefresh="true" TItem="Longbow.Web.OnlineUser" OnQuery="QueryData">
<TableHeader>
<LgbTableHeader TItem="string" @bind-Value="@context.ConnectionId"></LgbTableHeader>
<LgbTableHeader TItem="string" @bind-Value="@context.UserName"></LgbTableHeader>

View File

@ -193,7 +193,7 @@
<span>网站缓存</span>
</div>
<div class="card-body">
<Table Id="settings-cache" TItem="Longbow.Cache.ICacheItem" EditModel="ConsoleCaCheModel" OnDataSourceQuery="QueryData">
<Table Id="settings-cache" TItem="Longbow.Cache.ICacheItem" EditModel="ConsoleCaCheModel" OnQuery="QueryData">
<TableHeader>
<LgbTableHeader TItem="string" @bind-Value="@context.Desc"></LgbTableHeader>
<LgbTableHeader TItem="int" @bind-Value="@context.Interval"></LgbTableHeader>

View File

@ -1,6 +1,6 @@
using Longbow.Web;
using Bootstrap.Admin.Pages.Components;
using Longbow.Web;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Pages.Views.Admin.Components
@ -24,6 +24,14 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
/// <summary>
/// QueryData 方法
/// </summary>
protected IEnumerable<OnlineUser> QueryData() => (OnlineUSers?.OnlineUsers ?? new OnlineUser[0]).OrderByDescending(u => u.LastAccessTime);
protected QueryData<OnlineUser> QueryData(QueryPageOptions options)
{
var data = OnlineUSers?.OnlineUsers ?? new OnlineUser[0];
return new QueryData<OnlineUser>()
{
Items = data,
TotalCount = data.Count()
};
}
}
}

View File

@ -1,13 +1,12 @@
using Bootstrap.Admin.Pages.Components;
using Bootstrap.Admin.Pages.Extensions;
using Bootstrap.Admin.Pages.Shared;
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Cache;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Pages.Views.Admin.Components
{
@ -72,7 +71,15 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
/// <summary>
/// QueryData 方法
/// </summary>
protected IEnumerable<ICacheItem> QueryData() => CacheManager.ToList();
protected QueryData<ICacheItem> QueryData(QueryPageOptions options)
{
var data = CacheManager.ToList();
return new QueryData<ICacheItem>()
{
Items = data,
TotalCount = data.Count()
};
}
/// <summary>
/// 清除指定键值的方法