feat: 更新依赖包支持多列排序

This commit is contained in:
Argo-Tianyi 2022-01-05 03:46:25 +08:00
parent 09de55a641
commit ecff092ea4
8 changed files with 19 additions and 55 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="6.1.2-beta10" />
<PackageReference Include="BootstrapBlazor" Version="6.1.2-beta12" />
<PackageReference Include="Longbow.Security.Cryptography" Version="5.2.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.1" />
<PackageReference Include="PetaPoco.Extensions" Version="5.2.0" />

View File

@ -44,6 +44,10 @@ public static class DatabaseExtensions
{
sql.OrderBy(sortOrder == SortOrder.Asc ? sortName : $"{sortName} desc");
}
else if (options.SortList != null && options.SortList.Any())
{
sql.OrderBy(string.Join(",", options.SortList));
}
return db.FetchAsync<TModel>(sql);
}

View File

@ -5,7 +5,7 @@
IsTree="IsTree" OnTreeExpand="OnTreeExpand!" TreeIcon="fa-chevron-circle-right"
ShowDefaultButtons="ShowDefaultButtons" ShowAdvancedSearch="ShowAdvancedSearch"
ShowEmpty="true" EmptyText="暂无数据" EmptyImage="images/empty.svg"
UseInjectDataService="true" DataService="DataService" OnQueryAsync="OnQueryAsync!"
UseInjectDataService="true" DataService="DataService" OnQueryAsync="OnQueryAsync!" SortList="SortList"
ShowSkeleton="true" ShowToolbar="true" ShowExtendButtons="ShowExtendButtons" ShowSearch="true"
ShowCardView="true" ShowColumnList="true" ExtendButtonColumnWidth="@ExtendButtonColumnWidth"
CustomerSearchModel="@TableSearchModel">

View File

@ -18,6 +18,12 @@
[Parameter]
public int ExtendButtonColumnWidth { get; set; } = 130;
/// <summary>
///
/// </summary>
[Parameter]
public List<string>? SortList { get; set; }
/// <summary>
///
/// </summary>

View File

@ -1,6 +1,6 @@
@page "/Admin/Dicts"
<AdminTable TItem="DataAccess.Models.Dict" TableSearchModel="DictsSearchModel" OnQueryAsync="OnQueryAsync">
<AdminTable TItem="DataAccess.Models.Dict" TableSearchModel="DictsSearchModel" SortList="SortList">
<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>

View File

@ -1,6 +1,4 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Core;
using BootstrapAdmin.Web.Models;
using BootstrapAdmin.Web.Models;
namespace BootstrapAdmin.Web.Pages.Admin
{
@ -11,52 +9,6 @@ namespace BootstrapAdmin.Web.Pages.Admin
{
private ITableSearchModel DictsSearchModel { get; set; } = new DictsSearchModel();
[Inject]
[NotNull]
private IDict? DictService { get; set; }
private Task<QueryData<Dict>> OnQueryAsync(QueryPageOptions options)
{
var ret = new QueryData<Dict>()
{
IsSorted = true,
IsFiltered = true,
IsSearch = true
};
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);
}
private List<string> SortList { get; } = new List<string> { "Define", "Category", "Name" };
}
}

View File

@ -32,7 +32,7 @@
<AdminAlert Text="演示系统禁止修改内置后台任务" IsShow="IsDemo" />
<Table TItem="TasksModel" ExtendButtonColumnWidth="270" IsBordered="true" IsStriped="true"
IsMultipleSelect="true" IsFixedHeader="false"
IsMultipleSelect="true" IsFixedHeader="false" SortList="SortList"
ShowToolbar="true" ShowExtendButtons="true" SelectedRows="SelectedRows"
ShowEditButtonCallback="OnShowButtonCallback" ShowDeleteButtonCallback="OnShowButtonCallback"
OnQueryAsync="OnQueryAsync" OnDeleteAsync="OnDeleteAsync" OnSaveAsync="OnSaveAsync">

View File

@ -27,6 +27,8 @@ public partial class Tasks
private bool IsDemo { get; set; }
private List<string> SortList { get; } = new List<string>() { "Name", "LastRuntime desc" };
protected override void OnInitialized()
{
base.OnInitialized();
@ -36,7 +38,7 @@ public partial class Tasks
private Task<QueryData<TasksModel>> OnQueryAsync(QueryPageOptions options)
{
var tasks = TaskServicesManager.ToList().OrderBy(i => i.Name).ToTasksModelList();
var tasks = TaskServicesManager.ToList().ToTasksModelList();
var model = tasks.FirstOrDefault(i => i.Name == SelectedRows.FirstOrDefault()?.Name);
SelectedRows.Clear();
if (model != null)