From ecff092ea4e4a99956e86ed86fc03fc6f793be43 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Wed, 5 Jan 2022 03:46:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=8C=85=E6=94=AF=E6=8C=81=E5=A4=9A=E5=88=97=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapAdmin.DataAccess.PetaPoco.csproj | 2 +- .../Extensions/DatabaseExtensions.cs | 4 ++ .../Components/AdminTable.razor | 2 +- .../Components/AdminTable.razor.cs | 6 +++ .../Pages/Admin/Dicts.razor | 2 +- .../Pages/Admin/Dicts.razor.cs | 52 +------------------ .../Pages/Admin/Tasks.razor | 2 +- .../Pages/Admin/Tasks.razor.cs | 4 +- 8 files changed, 19 insertions(+), 55 deletions(-) diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj index 7d2d6dc8..e77c8a27 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj @@ -1,7 +1,7 @@  - + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs index b9f32044..4912b1a8 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs @@ -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(sql); } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor b/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor index 083cc82a..14c946aa 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor @@ -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"> diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor.cs index f3bc00cd..ab4fe596 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/AdminTable.razor.cs @@ -18,6 +18,12 @@ [Parameter] public int ExtendButtonColumnWidth { get; set; } = 130; + /// + /// + /// + [Parameter] + public List? SortList { get; set; } + /// /// /// diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor index 8daa438a..80aec772 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor @@ -1,6 +1,6 @@ @page "/Admin/Dicts" - + diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor.cs index 740fe7fa..675da304 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Dicts.razor.cs @@ -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> OnQueryAsync(QueryPageOptions options) - { - var ret = new QueryData() - { - 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()).ToList(); - } - - // 处理过滤 - if (options.Filters.Any()) - { - items = items.Where(options.Filters.GetFilterFunc()).ToList(); - } - - // 处理排序 - if (!string.IsNullOrEmpty(options.SortName)) - { - items = items.Sort(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 SortList { get; } = new List { "Define", "Category", "Name" }; } } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor index 20c893fe..7fb3ac3e 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor @@ -32,7 +32,7 @@ diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor.cs index ba8077c6..7d91579f 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Tasks.razor.cs @@ -27,6 +27,8 @@ public partial class Tasks private bool IsDemo { get; set; } + private List SortList { get; } = new List() { "Name", "LastRuntime desc" }; + protected override void OnInitialized() { base.OnInitialized(); @@ -36,7 +38,7 @@ public partial class Tasks private Task> 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)