!82 增加功能:Table 组件支持异步回调方法

* feat: Table 增加异步回调方法支持
* fix: 消除时间线组件警告信息
* doc: 增加 readme 文档
* Merge branch 'master' into dev
* doc: 更正 Modal 示例文档
pull/82/MERGE
Argo 5 years ago
parent e4bd45c0d8
commit 0e3622b2c2

@ -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

@ -37,7 +37,7 @@ namespace BootstrapBlazor.WebConsole.Pages
/// <summary>
///
/// </summary>
protected IEnumerable<SelectedItem> items { get; set; } = new SelectedItem[]
private IEnumerable<SelectedItem> items { get; set; } = new SelectedItem[]
{
new SelectedItem("1","正序"){ Active=true },
new SelectedItem("2","反序")
@ -46,7 +46,7 @@ namespace BootstrapBlazor.WebConsole.Pages
/// <summary>
///
/// </summary>
protected readonly IEnumerable<TimelineItem> timelineitems = new TimelineItem[]
private readonly IEnumerable<TimelineItem> 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
/// <summary>
///
/// </summary>
protected readonly IEnumerable<TimelineItem> timelineitemsColor = new TimelineItem[]
private readonly IEnumerable<TimelineItem> 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")},

@ -1,6 +1,8 @@
<Button @onclick="e => Modal?.ToggleAsync()">弹窗</Button>
<Modal @ref="Modal" Title="默认弹窗">
<ModalBody>
<div>我是弹窗内正文</div>
</ModalBody>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<div>我是弹窗内正文</div>
</BodyTemplate>
</ModalDialog>
</Modal>

@ -1,6 +1,8 @@
<Button @onclick="e => BackdropModal?.ToggleAsync()">弹窗</Button>
<Modal @ref="BackdropModal" IsBackdrop="true" Title="点击背景可关闭弹窗">
<ModalBody>
<div>我是弹窗内正文</div>
</ModalBody>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<div>我是弹窗内正文</div>
</BodyTemplate>
</ModalDialog>
</Modal>

@ -1,18 +1,24 @@
<Button @onclick="e => SmailModal?.ToggleAsync()">小弹窗</Button>
<Modal @ref="SmailModal" Size="Size.Small" Title="小弹窗">
<ModalBody>
<div>我是弹窗内正文</div>
</ModalBody>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<div>我是弹窗内正文</div>
</BodyTemplate>
</ModalDialog>
</Modal>
<Button @onclick="e => LargeModal?.ToggleAsync()">大弹窗</Button>
<Modal @ref="LargeModal" Size="Size.Large" Title="大弹窗">
<ModalBody>
<div>我是弹窗内正文</div>
</ModalBody>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<div>我是弹窗内正文</div>
</BodyTemplate>
</ModalDialog>
</Modal>
<Button @onclick="e => ExtraLargeModal?.ToggleAsync()">超大弹窗</Button>
<Modal @ref="ExtraLargeModal" Size="Size.ExtraLarge" Title="超大弹窗">
<ModalBody>
<div>我是弹窗内正文</div>
</ModalBody>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<div>我是弹窗内正文</div>
</BodyTemplate>
</ModalDialog>
</Modal>

@ -1,6 +1,8 @@
<Button @onclick="e => CenterModal?.ToggleAsync()">垂直居中的弹窗</Button>
<Modal @ref="CenterModal" IsCentered="true" Title="垂直居中的弹窗">
<ModalBody>
<div>我是弹窗内正文</div>
</ModalBody>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<div>我是弹窗内正文</div>
</BodyTemplate>
</ModalDialog>
</Modal>

@ -1,47 +1,51 @@
<Button @onclick="e => LongContentModal?.ToggleAsync()">内容超长的弹窗</Button>
<Modal @ref="LongContentModal" IsCentered="true" Title="内容超长的弹窗">
<ModalBody>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
</ModalBody>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
</BodyTemplate>
</ModalDialog>
</Modal>
<Button @onclick="e => ScrollModal?.ToggleAsync()">内置滚动条弹窗</Button>
<Modal @ref="ScrollModal" IsCentered="true" IsScrolling="true" Title="内置滚动条弹窗" >
<ModalBody>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
</ModalBody>
</Modal>
<ModalDialog Title="默认弹窗">
<BodyTemplate>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
<p>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.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<p>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.</p>
</BodyTemplate>
</ModalDialog>
</Modal>

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<Version>3.1.2</Version>
<Version>3.1.3-beta01</Version>
</PropertyGroup>
</Project>

@ -121,7 +121,7 @@
</div>
}
@if (OnSave != null || OnAdd != null)
@if (OnSave != null || OnSaveAsync != null || OnAdd != null || OnAddAsync != null)
{
<Modal @ref="EditModal">
<ModalDialog Title="@EditModalTitleString" Size="@Size.ExtraLarge" IsCentered="true">

@ -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
/// <summary>
/// OnInitialized 方法
/// </summary>
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<string, SortOrder>((sortName, sortOrder) =>

@ -88,9 +88,10 @@ namespace BootstrapBlazor.Components
protected void QueryData()
{
SelectedItems.Clear();
QueryData<TItem>? 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;

@ -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<QueryPageOptions, QueryData<TItem>>? OnQuery { get; set; }
/// <summary>
/// 点击翻页异步回调方法
/// </summary>
[Parameter]
public Func<QueryPageOptions, Task<QueryData<TItem>>>? OnQueryAsync { get; set; }
/// <summary>
/// 获得/设置 数据总条目
/// </summary>
@ -57,12 +64,9 @@ namespace BootstrapBlazor.Components
/// </summary>
protected void OnPageItemsChanged(int pageItems)
{
if (OnQuery != null)
{
PageIndex = 1;
PageItems = pageItems;
Query();
}
PageIndex = 1;
PageItems = pageItems;
Query();
}
}
}

@ -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
/// </summary>
[Parameter] public Action<TItem>? OnResetSearch { get; set; }
/// <summary>
/// 重置搜索按钮异步回调方法
/// </summary>
[Parameter] public Func<TItem, Task>? OnResetSearchAsync { get; set; }
/// <summary>
/// 重置查询方法
/// </summary>
protected void ResetSearchClick()
{
OnResetSearch?.Invoke(SearchModel);
if (OnResetSearch != null) OnResetSearch.Invoke(SearchModel);
else if (OnResetSearchAsync != null) OnResetSearchAsync(SearchModel).GetAwaiter().GetResult();
SearchClick();
}

@ -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<TItem>? OnAdd { get; set; }
/// <summary>
/// 获得/设置 编辑按钮回调方法
/// 获得/设置 新建按钮回调方法
/// </summary>
[Parameter]
public Action<TItem>? OnEdit { get; set; }
public Func<Task<TItem>>? OnAddAsync { get; set; }
/// <summary>
/// 获得/设置 保存按钮回调方法
@ -65,18 +66,33 @@ namespace BootstrapBlazor.Components
[Parameter]
public Func<TItem, bool>? OnSave { get; set; }
/// <summary>
/// 获得/设置 保存按钮异步回调方法
/// </summary>
[Parameter]
public Func<TItem, Task<bool>>? OnSaveAsync { get; set; }
/// <summary>
/// 获得/设置 删除按钮回调方法
/// </summary>
[Parameter]
public Func<IEnumerable<TItem>, bool>? OnDelete { get; set; }
/// <summary>
/// 获得/设置 删除按钮异步回调方法
/// </summary>
[Parameter]
public Func<IEnumerable<TItem>, Task<bool>>? OnDeleteAsync { get; set; }
/// <summary>
/// 新建按钮方法
/// </summary>
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
/// <param name="context"></param>
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
/// </summary>
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 = "删除数据"

Loading…
Cancel
Save