From 0e3622b2c2b89123bceb67dcedf426c9bd298a6b Mon Sep 17 00:00:00 2001 From: Argo Date: Sat, 16 May 2020 23:29:11 +0800 Subject: [PATCH] =?UTF-8?q?!82=20=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9ATable=20=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E5=9B=9E=E8=B0=83=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Table 增加异步回调方法支持 * fix: 消除时间线组件警告信息 * doc: 增加 readme 文档 * Merge branch 'master' into dev * doc: 更正 Modal 示例文档 --- BootstrapBlazor.sln | 6 ++ .../Pages/Timelines.razor.cs | 6 +- .../wwwroot/code/modal.1.txt | 8 +- .../wwwroot/code/modal.2.txt | 8 +- .../wwwroot/code/modal.3.txt | 24 ++++-- .../wwwroot/code/modal.4.txt | 8 +- .../wwwroot/code/modal.5.txt | 86 ++++++++++--------- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- .../Components/Table/Table.razor | 2 +- .../Components/Table/TableBase.cs | 14 ++- .../Components/Table/TableBase_Edit.cs | 18 +++- .../Components/Table/TableBase_Pagination.cs | 16 ++-- .../Components/Table/TableBase_Search.cs | 9 +- .../Components/Table/TableBase_Toolbar.cs | 30 +++++-- 14 files changed, 156 insertions(+), 81 deletions(-) diff --git a/BootstrapBlazor.sln b/BootstrapBlazor.sln index a5a42a760..6e68a9103 100644 --- a/BootstrapBlazor.sln +++ b/BootstrapBlazor.sln @@ -38,6 +38,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{F07542 .github\workflows\build.yml = .github\workflows\build.yml EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{9437A6C6-CF87-4B75-916B-C1EF558BD8EF}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + README.zh-CN.md = README.zh-CN.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/BootstrapBlazor.WebConsole/Pages/Timelines.razor.cs b/src/BootstrapBlazor.WebConsole/Pages/Timelines.razor.cs index 79c6901c8..44e8f2900 100644 --- a/src/BootstrapBlazor.WebConsole/Pages/Timelines.razor.cs +++ b/src/BootstrapBlazor.WebConsole/Pages/Timelines.razor.cs @@ -37,7 +37,7 @@ namespace BootstrapBlazor.WebConsole.Pages /// /// /// - protected IEnumerable items { get; set; } = new SelectedItem[] + private IEnumerable items { get; set; } = new SelectedItem[] { new SelectedItem("1","正序"){ Active=true }, new SelectedItem("2","反序") @@ -46,7 +46,7 @@ namespace BootstrapBlazor.WebConsole.Pages /// /// /// - protected readonly IEnumerable timelineitems = new TimelineItem[] + private readonly IEnumerable timelineitems = new TimelineItem[] { new TimelineItem{ Content="创建时间",DateTime=DateTime.Now.ToString("yyyy-MM-dd")}, new TimelineItem{ Content="通过审核",DateTime=DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}, @@ -56,7 +56,7 @@ namespace BootstrapBlazor.WebConsole.Pages /// /// /// - protected readonly IEnumerable timelineitemsColor = new TimelineItem[] + private readonly IEnumerable timelineitemsColor = new TimelineItem[] { new TimelineItem{ Color=Color.Warning, Content="创建时间",DateTime=DateTime.Now.ToString("yyyy-MM-dd")}, new TimelineItem{ Color=Color.Info, Content="通过审核",DateTime=DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}, diff --git a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.1.txt b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.1.txt index fe5f20964..c5c8de1ac 100644 --- a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.1.txt +++ b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.1.txt @@ -1,6 +1,8 @@  - -
我是弹窗内正文
-
+ + +
我是弹窗内正文
+
+
diff --git a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.2.txt b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.2.txt index be2efd495..fe95c7ff1 100644 --- a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.2.txt +++ b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.2.txt @@ -1,6 +1,8 @@  - -
我是弹窗内正文
-
+ + +
我是弹窗内正文
+
+
diff --git a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.3.txt b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.3.txt index 8c1959a06..d3bd45a38 100644 --- a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.3.txt +++ b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.3.txt @@ -1,18 +1,24 @@  - -
我是弹窗内正文
-
+ + +
我是弹窗内正文
+
+
- -
我是弹窗内正文
-
+ + +
我是弹窗内正文
+
+
- -
我是弹窗内正文
-
+ + +
我是弹窗内正文
+
+
diff --git a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.4.txt b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.4.txt index 3fa9e1f20..55a8bfec4 100644 --- a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.4.txt +++ b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.4.txt @@ -1,6 +1,8 @@  - -
我是弹窗内正文
-
+ + +
我是弹窗内正文
+
+
diff --git a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.5.txt b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.5.txt index 15333362c..66084a309 100644 --- a/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.5.txt +++ b/src/BootstrapBlazor.WebConsole/wwwroot/code/modal.5.txt @@ -1,47 +1,51 @@  - -

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-
+ + +

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+
+
- -

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

-

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

-

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

-
-
\ No newline at end of file + + +

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+

Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.

+

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

+

Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.

+
+
+ diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index c78872099..fb3161af6 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -4,7 +4,7 @@ netcoreapp3.1 Library true - 3.1.2 + 3.1.3-beta01 diff --git a/src/BootstrapBlazor/Components/Table/Table.razor b/src/BootstrapBlazor/Components/Table/Table.razor index 429e650f9..c4e07c39a 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor +++ b/src/BootstrapBlazor/Components/Table/Table.razor @@ -121,7 +121,7 @@ } - @if (OnSave != null || OnAdd != null) + @if (OnSave != null || OnSaveAsync != null || OnAdd != null || OnAddAsync != null) { diff --git a/src/BootstrapBlazor/Components/Table/TableBase.cs b/src/BootstrapBlazor/Components/Table/TableBase.cs index 2d1c956f4..02689aef3 100644 --- a/src/BootstrapBlazor/Components/Table/TableBase.cs +++ b/src/BootstrapBlazor/Components/Table/TableBase.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace BootstrapBlazor.Components { @@ -76,20 +77,25 @@ namespace BootstrapBlazor.Components /// /// OnInitialized 方法 /// - protected override void OnInitialized() + protected override async Task OnInitializedAsync() { - base.OnInitialized(); + await base.OnInitializedAsync(); // 初始化每页显示数量 if (IsPagination) { PageItems = PageItemsSource?.FirstOrDefault() ?? QueryPageOptions.DefaultPageItems; - if (Items != null) throw new InvalidOperationException($"Please set {nameof(OnQuery)} instead set {nameof(Items)} property when {nameof(IsPagination)} be set True."); + if (Items != null) throw new InvalidOperationException($"Please set {nameof(OnQuery)} or {nameof(OnQueryAsync)} instead set {nameof(Items)} property when {nameof(IsPagination)} be set True."); } // 初始化 EditModel - if (EditModel == null) EditModel = OnAdd?.Invoke() ?? new TItem(); + if (EditModel == null) + { + if (OnAdd != null) EditModel = OnAdd(); + else if (OnAddAsync != null) EditModel = await OnAddAsync(); + else new TItem(); + } // 设置 OnSort 回调方法 OnSort = new Action((sortName, sortOrder) => diff --git a/src/BootstrapBlazor/Components/Table/TableBase_Edit.cs b/src/BootstrapBlazor/Components/Table/TableBase_Edit.cs index 304c1d361..ca62fd02f 100644 --- a/src/BootstrapBlazor/Components/Table/TableBase_Edit.cs +++ b/src/BootstrapBlazor/Components/Table/TableBase_Edit.cs @@ -88,9 +88,10 @@ namespace BootstrapBlazor.Components protected void QueryData() { SelectedItems.Clear(); + QueryData? queryData = null; if (OnQuery != null) { - var queryData = OnQuery(new QueryPageOptions() + queryData = OnQuery(new QueryPageOptions() { PageIndex = PageIndex, PageItems = PageItems, @@ -98,6 +99,21 @@ namespace BootstrapBlazor.Components SortOrder = SortOrder, SortName = SortName }); + } + else if (OnQueryAsync != null) + { + var task = OnQueryAsync(new QueryPageOptions() + { + PageIndex = PageIndex, + PageItems = PageItems, + SearchText = SearchText, + SortOrder = SortOrder, + SortName = SortName + }); + queryData = task.GetAwaiter().GetResult(); + } + if (queryData != null) + { Items = queryData.Items; TotalCount = queryData.TotalCount; IsFiltered = queryData.IsFiltered; diff --git a/src/BootstrapBlazor/Components/Table/TableBase_Pagination.cs b/src/BootstrapBlazor/Components/Table/TableBase_Pagination.cs index 6f698b247..1ca5b356b 100644 --- a/src/BootstrapBlazor/Components/Table/TableBase_Pagination.cs +++ b/src/BootstrapBlazor/Components/Table/TableBase_Pagination.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace BootstrapBlazor.Components { @@ -22,6 +23,12 @@ namespace BootstrapBlazor.Components [Parameter] public Func>? OnQuery { get; set; } + /// + /// 点击翻页异步回调方法 + /// + [Parameter] + public Func>>? OnQueryAsync { get; set; } + /// /// 获得/设置 数据总条目 /// @@ -57,12 +64,9 @@ namespace BootstrapBlazor.Components /// protected void OnPageItemsChanged(int pageItems) { - if (OnQuery != null) - { - PageIndex = 1; - PageItems = pageItems; - Query(); - } + PageIndex = 1; + PageItems = pageItems; + Query(); } } } diff --git a/src/BootstrapBlazor/Components/Table/TableBase_Search.cs b/src/BootstrapBlazor/Components/Table/TableBase_Search.cs index b3e552e7e..f580fd8e3 100644 --- a/src/BootstrapBlazor/Components/Table/TableBase_Search.cs +++ b/src/BootstrapBlazor/Components/Table/TableBase_Search.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using System; +using System.Threading.Tasks; namespace BootstrapBlazor.Components { @@ -64,12 +65,18 @@ namespace BootstrapBlazor.Components /// [Parameter] public Action? OnResetSearch { get; set; } + /// + /// 重置搜索按钮异步回调方法 + /// + [Parameter] public Func? OnResetSearchAsync { get; set; } + /// /// 重置查询方法 /// protected void ResetSearchClick() { - OnResetSearch?.Invoke(SearchModel); + if (OnResetSearch != null) OnResetSearch.Invoke(SearchModel); + else if (OnResetSearchAsync != null) OnResetSearchAsync(SearchModel).GetAwaiter().GetResult(); SearchClick(); } diff --git a/src/BootstrapBlazor/Components/Table/TableBase_Toolbar.cs b/src/BootstrapBlazor/Components/Table/TableBase_Toolbar.cs index 69cb2087d..c8a814739 100644 --- a/src/BootstrapBlazor/Components/Table/TableBase_Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/TableBase_Toolbar.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components.Forms; using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace BootstrapBlazor.Components { @@ -54,10 +55,10 @@ namespace BootstrapBlazor.Components public Func? OnAdd { get; set; } /// - /// 获得/设置 编辑按钮回调方法 + /// 获得/设置 新建按钮回调方法 /// [Parameter] - public Action? OnEdit { get; set; } + public Func>? OnAddAsync { get; set; } /// /// 获得/设置 保存按钮回调方法 @@ -65,18 +66,33 @@ namespace BootstrapBlazor.Components [Parameter] public Func? OnSave { get; set; } + /// + /// 获得/设置 保存按钮异步回调方法 + /// + [Parameter] + public Func>? OnSaveAsync { get; set; } + /// /// 获得/设置 删除按钮回调方法 /// [Parameter] public Func, bool>? OnDelete { get; set; } + /// + /// 获得/设置 删除按钮异步回调方法 + /// + [Parameter] + public Func, Task>? OnDeleteAsync { get; set; } + /// /// 新建按钮方法 /// public void Add() { - if (OnAdd != null) EditModel = OnAdd.Invoke() ?? new TItem(); + if (OnAdd != null) EditModel = OnAdd.Invoke(); + else if (OnAddAsync != null) EditModel = OnAddAsync().GetAwaiter().GetResult(); + else new TItem(); + SelectedItems.Clear(); EditModalTitleString = AddModalTitle; EditModal?.Toggle(); @@ -109,7 +125,9 @@ namespace BootstrapBlazor.Components /// protected void Save(EditContext context) { - var valid = OnSave?.Invoke((TItem)context.Model) ?? false; + var valid = false; + if (OnSave != null) valid = OnSave.Invoke((TItem)context.Model); + else if (OnSaveAsync != null) valid = OnSaveAsync.Invoke((TItem)context.Model).GetAwaiter().GetResult(); var option = new ToastOption(); option.Category = valid ? ToastCategory.Success : ToastCategory.Error; option.Title = "保存数据"; @@ -151,7 +169,9 @@ namespace BootstrapBlazor.Components /// protected void Delete() { - var ret = OnDelete?.Invoke(SelectedItems) ?? false; + var ret = false; + if (OnDelete != null) ret = OnDelete.Invoke(SelectedItems); + else if (OnDeleteAsync != null) ret = OnDeleteAsync.Invoke(SelectedItems).GetAwaiter().GetResult(); var op = new ToastOption() { Title = "删除数据"