feat: Client 增加 Table 自定义组件

This commit is contained in:
Argo-Lenovo 2022-06-01 17:23:49 +08:00
parent 4995899c4c
commit 134d0ee8a8
2 changed files with 233 additions and 0 deletions

View File

@ -0,0 +1,17 @@
@typeparam TItem
<Table TItem="TItem" IsBordered="true" IsStriped="true" IsMultipleSelect="IsMultipleSelect" @ref="Instance"
IsPagination="IsPagination" PageItemsSource="PageItemsSource" IsFixedHeader="IsFixedHeader"
IsTree="IsTree" OnTreeExpand="OnTreeExpand!" TreeIcon="fa-chevron-circle-right"
ShowDefaultButtons="ShowDefaultButtons" ShowAdvancedSearch="ShowAdvancedSearch"
ShowEmpty="ShowEmpty" EmptyText="暂无数据" EmptyImage="images/empty.svg" SortString="@SortString"
OnQueryAsync="OnQueryAsync!" OnDeleteAsync="OnDeleteAsync!" OnSaveAsync="OnSaveAsync!"
ShowSkeleton="true" ShowLoading="ShowLoading" ShowSearch="ShowSearch"
ShowToolbar="ShowToolbar" ShowExtendButtons="ShowExtendButtons" ShowAddButton="@AuthorizeButton("add")"
ShowDeleteButton="@AuthorizeButton("del")" ShowEditButton="@AuthorizeButton("edit")"
ShowCardView="true" ShowColumnList="true" ExtendButtonColumnWidth="@ExtendButtonColumnWidth"
CustomerSearchModel="CustomerSearchModel" SelectedRows="SelectedRows"
ShowEditButtonCallback="ShowEditButtonCallback!" ShowDeleteButtonCallback="ShowDeleteButtonCallback!"
TableToolbarTemplate="TableToolbarTemplate" TableColumns="TableColumns" EditTemplate="EditTemplate!"
CustomerSearchTemplate="CustomerSearchTemplate!" RowButtonTemplate="RowButtonTemplate!">
</Table>

View File

@ -0,0 +1,216 @@
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
// Website: https://admin.blazor.zone
using Bootstrap.Security.Blazor;
using BootstrapClient.Web.Shared.Services;
namespace BootstrapClient.Web.Shared.Components
{
/// <summary>
///
/// </summary>
[CascadingTypeParameter(nameof(TItem))]
public partial class AdminTable<TItem> where TItem : class, new()
{
/// <summary>
///
/// </summary>
[Parameter]
public IEnumerable<int>? PageItemsSource { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public int ExtendButtonColumnWidth { get; set; } = 130;
/// <summary>
///
/// </summary>
[Parameter]
public string? SortString { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
[Parameter]
public RenderFragment<TItem>? TableColumns { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public RenderFragment<TItem>? RowButtonTemplate { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public RenderFragment<ITableSearchModel>? CustomerSearchTemplate { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public RenderFragment<TItem>? EditTemplate { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
[Parameter]
public RenderFragment? TableToolbarTemplate { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public bool IsPagination { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public bool IsMultipleSelect { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public bool IsFixedHeader { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public bool IsTree { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public bool ShowToolbar { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public bool ShowEmpty { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public bool ShowLoading { get; set; } = false;
/// <summary>
///
/// </summary>
[Parameter]
public bool ShowSearch { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public bool ShowAdvancedSearch { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public bool ShowDefaultButtons { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public bool ShowExtendButtons { get; set; } = true;
/// <summary>
///
/// </summary>
[Parameter]
public ITableSearchModel? CustomerSearchModel { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public Func<QueryPageOptions, Task<QueryData<TItem>>>? OnQueryAsync { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public Func<TItem, Task<IEnumerable<TItem>>>? OnTreeExpand { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public Func<TItem, ItemChangedType, Task<bool>>? OnSaveAsync { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public Func<IEnumerable<TItem>, Task<bool>>? OnDeleteAsync { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public List<TItem>? SelectedRows { get; set; } = new List<TItem>();
/// <summary>
///
/// </summary>
[Parameter]
public Func<TItem, bool>? ShowEditButtonCallback { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public Func<TItem, bool>? ShowDeleteButtonCallback { get; set; }
[NotNull]
private Table<TItem>? Instance { get; set; }
/// <summary>
///
/// </summary>
/// <param name="v"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public ValueTask ToggleLoading(bool v) => Instance.ToggleLoading(v);
/// <summary>
///
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task QueryAsync() => Instance.QueryAsync();
[Inject]
[NotNull]
private IBootstrapAdminService? AdminService { get; set; }
[Inject]
[NotNull]
private NavigationManager? NavigationManager { get; set; }
[Inject]
[NotNull]
private BootstrapAppContext? AppContext { get; set; }
private bool AuthorizeButton(string operate)
{
var url = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
return AdminService.AuhorizingBlock(AppContext.UserName, url, operate);
}
}
}