feat: 增加 GetAll 接口实现自定义排序功能

This commit is contained in:
Argo-Tianyi 2021-12-31 13:26:57 +08:00
parent 2e11fce1fd
commit 3c7ce9cf24
5 changed files with 62 additions and 20 deletions

View File

@ -6,6 +6,11 @@ namespace BootstrapAdmin.DataAccess.EFCore.Services;
class DictService : IDict
{
public List<Dict> GetAll()
{
throw new NotImplementedException();
}
public Dictionary<string, string> GetApps()
{
throw new NotImplementedException();

View File

@ -11,18 +11,13 @@ class DictService : BaseDatabase, IDict
{
private string AppId { get; set; }
/// <summary>
///
/// </summary>
/// <param name="db"></param>
/// <param name="configuration"></param>
public DictService(IDatabase db, IConfiguration configuration)
{
Database = db;
AppId = configuration.GetValue("AppId", "BA");
}
private List<Dict> GetAll() => Database.Fetch<Dict>();
public List<Dict> GetAll() => Database.Fetch<Dict>();
public Dictionary<string, string> GetApps()
{

View File

@ -1,10 +1,18 @@
namespace BootstrapAdmin.Web.Core;
using BootstrapAdmin.DataAccess.Models;
namespace BootstrapAdmin.Web.Core;
/// <summary>
/// Dict 字典表接口
/// </summary>
public interface IDict
{
/// <summary>
/// 获得 所有数据方法
/// </summary>
/// <returns></returns>
List<Dict> GetAll();
/// <summary>
/// 获得 配置所有的 App 集合
/// </summary>

View File

@ -1,11 +1,11 @@
@page "/Admin/Dicts"
<AdminTable TItem="DataAccess.Models.Dict" TableSearchModel="DictsSearchModel">
<AdminTable TItem="DataAccess.Models.Dict" TableSearchModel="DictsSearchModel" OnQueryAsync="OnQueryAsync">
<ColumnsTemplete>
<TableColumn @bind-Field="context.Category" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.Name" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.Code" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.Define" Filterable="true" Searchable="true" Sortable="true" DefaultSort="true" DefaultSortOrder="SortOrder.Desc"></TableColumn>
<TableColumn @bind-Field="context.Define" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
</ColumnsTemplete>
<CustomerSearchTemplate>
@if (context is DictsSearchModel searchModel)

View File

@ -1,4 +1,5 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Core;
using BootstrapAdmin.Web.Models;
namespace BootstrapAdmin.Web.Pages.Admin
@ -8,21 +9,54 @@ namespace BootstrapAdmin.Web.Pages.Admin
/// </summary>
public partial class Dicts
{
private IEnumerable<SelectedItem>? EditDefines { get; set; }
private ITableSearchModel DictsSearchModel { get; set; } = new DictsSearchModel();
private IEnumerable<SelectedItem>? LookUp { get; set; }
[Inject]
[NotNull]
private IDict? DictService { get; set; }
private ITableSearchModel? DictsSearchModel { get; set; } = new DictsSearchModel();
/// <summary>
///
/// </summary>
protected override void OnInitialized()
private Task<QueryData<Dict>> OnQueryAsync(QueryPageOptions options)
{
base.OnInitialized();
var ret = new QueryData<Dict>()
{
IsSorted = true,
IsFiltered = true,
IsSearch = true
};
EditDefines = typeof(EnumDictDefine).ToSelectList();
LookUp = EditDefines;
var items = DictService.GetAll();
// 处理模糊查询
if (!string.IsNullOrEmpty(options.SearchText))
{
items = items.Where(i => i.Category.Contains(options.SearchText) || i.Name.Contains(options.SearchText)).ToList();
}
// 处理高级查询
if (options.CustomerSearchs.Any())
{
items = items.Where(options.CustomerSearchs.GetFilterFunc<Dict>()).ToList();
}
// 处理过滤
if (options.Filters.Any())
{
items = items.Where(options.Filters.GetFilterFunc<Dict>()).ToList();
}
// 处理排序
if (!string.IsNullOrEmpty(options.SortName))
{
items = items.Sort<Dict>(options.SortName, options.SortOrder).ToList();
}
else
{
items = items.OrderBy(i => i.Define).ThenBy(i => i.Category).ThenBy(i => i.Name).ToList();
}
ret.TotalCount = items.Count;
ret.Items = items;
return Task.FromResult(ret);
}
}
}