feat: 重构 AdminTable 内置编辑模板

This commit is contained in:
Argo-Tianyi 2022-01-07 12:56:17 +08:00
parent 88fbd32ee8
commit 97eeba961a
11 changed files with 90 additions and 48 deletions

View File

@ -1,24 +1,16 @@
@typeparam TItem
<Table TItem="TItem" IsBordered="true" IsStriped="true" IsMultipleSelect="true"
<Table TItem="TItem" IsBordered="true" IsStriped="true" IsMultipleSelect="true" @ref="Instance"
IsPagination="IsPagination" PageItemsSource="PageItemsSource" IsFixedHeader="IsFixedHeader"
IsTree="IsTree" OnTreeExpand="OnTreeExpand!" TreeIcon="fa-chevron-circle-right"
ShowDefaultButtons="ShowDefaultButtons" ShowAdvancedSearch="ShowAdvancedSearch"
ShowDefaultButtons="ShowDefaultButtons" ShowAdvancedSearch="ShowAdvancedSearch"
ShowEmpty="true" EmptyText="暂无数据" EmptyImage="images/empty.svg"
UseInjectDataService="true" DataService="DataService" OnQueryAsync="OnQueryAsync!" SortList="SortList"
ShowSkeleton="true" ShowToolbar="true" ShowExtendButtons="ShowExtendButtons" ShowSearch="true"
UseInjectDataService="true" DataService="DataService" SortList="SortList"
OnQueryAsync="OnQueryAsync!" OnDeleteAsync="OnDeleteAsync!" OnSaveAsync="OnSaveAsync!"
ShowSkeleton="true" ShowLoading="true" ShowToolbar="true" ShowExtendButtons="ShowExtendButtons" ShowSearch="true"
ShowCardView="true" ShowColumnList="true" ExtendButtonColumnWidth="@ExtendButtonColumnWidth"
CustomerSearchModel="@TableSearchModel">
<TableToolbarTemplate>
@TableToolbarTemplate
</TableToolbarTemplate>
<TableColumns>
@ColumnsTemplete?.Invoke(context)
</TableColumns>
<CustomerSearchTemplate>
@CustomerSearchTemplate?.Invoke(context)
</CustomerSearchTemplate>
<RowButtonTemplate>
@RowButtonTemplate?.Invoke(context)
</RowButtonTemplate>
CustomerSearchModel="CustomerSearchModel" SelectedRows="SelectedRows"
ShowEditButtonCallback="ShowEditButtonCallback!" ShowDeleteButtonCallback="ShowDeleteButtonCallback!"
TableToolbarTemplate="TableToolbarTemplate" TableColumns="TableColumns" EditTemplate="EditTemplate!"
CustomerSearchTemplate="CustomerSearchTemplate!" RowButtonTemplate="RowButtonTemplate!">
</Table>

View File

@ -1,4 +1,6 @@
namespace BootstrapAdmin.Web.Components
using BootstrapAdmin.Web.Models;
namespace BootstrapAdmin.Web.Components
{
/// <summary>
///
@ -29,7 +31,7 @@
/// </summary>
[NotNull]
[Parameter]
public RenderFragment<TItem>? ColumnsTemplete { get; set; }
public RenderFragment<TItem>? TableColumns { get; set; }
/// <summary>
///
@ -43,6 +45,12 @@
[Parameter]
public RenderFragment<ITableSearchModel>? CustomerSearchTemplate { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public RenderFragment<TItem>? EditTemplate { get; set; }
/// <summary>
///
/// </summary>
@ -90,7 +98,7 @@
///
/// </summary>
[Parameter]
public ITableSearchModel? TableSearchModel { get; set; }
public ITableSearchModel? CustomerSearchModel { get; set; }
/// <summary>
///
@ -109,5 +117,53 @@
/// </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();
}
}

View File

@ -1,12 +1,12 @@
@page "/Admin/Dicts"
<AdminTable TItem="DataAccess.Models.Dict" TableSearchModel="DictsSearchModel" SortList="SortList">
<ColumnsTemplete>
<AdminTable TItem="DataAccess.Models.Dict" CustomerSearchModel="DictsSearchModel" SortList="SortList">
<TableColumns>
<TableColumn @bind-Field="context.Category" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.Name" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.Code" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.Define" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
</ColumnsTemplete>
</TableColumns>
<CustomerSearchTemplate>
@if (context is DictsSearchModel searchModel)
{

View File

@ -2,9 +2,9 @@
<AdminTable TItem="DataAccess.Models.Error"
IsPagination="true" PageItemsSource="PageItemsSource" IsFixedHeader="false"
ShowDefaultButtons="false" ShowExtendButtons="false" TableSearchModel="ErrorSearchModel"
ShowDefaultButtons="false" ShowExtendButtons="false" CustomerSearchModel="ErrorSearchModel"
OnQueryAsync="OnQueryAsync">
<ColumnsTemplete>
<TableColumns>
<TableColumn @bind-Field="context.LogTime" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.ErrorPage" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.UserId" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
@ -12,7 +12,7 @@
<TableColumn @bind-Field="context.ExceptionType" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
<TableColumn @bind-Field="context.Message" Filterable="true" Searchable="true" Sortable="true" TextWrap="true"></TableColumn>
<TableColumn @bind-Field="context.Category" Lookup="CategroyLookup" Filterable="true" Searchable="true" Sortable="true"></TableColumn>
</ColumnsTemplete>
</TableColumns>
<CustomerSearchTemplate>
@if (context is ErrorSearchModel searchModel)
{

View File

@ -5,11 +5,11 @@
<TableToolbarButton TItem="DataAccess.Models.Group" IsEnableWhenSelectedOneRow="true" Color="Color.Warning" Icon="fa fa-user" Text="分配用户" OnClickCallback="groups => OnAssignmentUsers(groups.First())" />
<TableToolbarButton TItem="DataAccess.Models.Group" IsEnableWhenSelectedOneRow="true" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="groups => OnAssignmentRoles(groups.First())" />
</TableToolbarTemplate>
<ColumnsTemplete>
<TableColumns>
<TableColumn @bind-Field="@context.GroupName" Sortable="true" Filterable="true" Searchable="true" Width="180"></TableColumn>
<TableColumn @bind-Field="@context.GroupCode" Sortable="true" Filterable="true" Searchable="true" Width="180"></TableColumn>
<TableColumn @bind-Field="@context.Description" Sortable="true" Filterable="true"></TableColumn>
</ColumnsTemplete>
</TableColumns>
<RowButtonTemplate>
<TableCellButton Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa fa-user" Text="分配用户" OnClick="() => OnAssignmentUsers(context)" />
<TableCellButton Size="Size.ExtraSmall" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClick="() => OnAssignmentRoles(context)" />

View File

@ -11,8 +11,7 @@
</div>
</CardHeader>
<CardBody>
<Table TItem="HealthCheckReportItem" IsBordered="true" IsStriped="true" @ref="HealthTable"
OnQueryAsync="OnQueryAsync" ShowSkeleton="true" ShowLoading="true" ShowExtendButtons="true">
<AdminTable TItem="HealthCheckReportItem" OnQueryAsync="OnQueryAsync" @ref="HealthTable">
<TableColumns>
<TableColumn @bind-Field="@context.Name" Lookup="@GetNameLookup()" Text="检查项"></TableColumn>
<TableColumn @bind-Field="@context.Description" Text="描述"></TableColumn>
@ -27,6 +26,6 @@
<RowButtonTemplate>
<TableCellButton Color="Color.Primary" Icon="fa fa-info-circle" Text="明细" OnClick="@(() => OnRowButtonClick(context))" />
</RowButtonTemplate>
</Table>
</AdminTable>
</CardBody>
</Card>

View File

@ -24,7 +24,7 @@ public partial class Healths
private HealthStatus Status { get; set; }
[NotNull]
private Table<HealthCheckReportItem>? HealthTable { get; set; }
private AdminTable<HealthCheckReportItem>? HealthTable { get; set; }
[Inject]
[NotNull]

View File

@ -1,9 +1,8 @@
@page "/Admin/Menus"
<Table TItem="DataAccess.Models.Navigation" IsBordered="true" IsStriped="true" IsMultipleSelect="true"
IsFixedHeader="true" IsTree="true" OnTreeExpand="OnTreeExpand" ExtendButtonColumnWidth="200"
ShowToolbar="true" ShowExtendButtons="true" ShowSearch="true" CustomerSearchModel="SearchModel"
UseInjectDataService="true" OnQueryAsync="OnQueryAsync">
<AdminTable TItem="DataAccess.Models.Navigation"
IsTree="true" OnTreeExpand="OnTreeExpand" ExtendButtonColumnWidth="200"
CustomerSearchModel="SearchModel" OnQueryAsync="OnQueryAsync">
<TableToolbarTemplate>
<TableToolbarButton TItem="DataAccess.Models.Navigation" IsEnableWhenSelectedOneRow="true" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="menus => OnAssignmentRoles(menus.First())" />
</TableToolbarTemplate>
@ -61,4 +60,4 @@
<MenusSearch @bind-Value="searchModel"></MenusSearch>
}
</CustomerSearchTemplate>
</Table>
</AdminTable>

View File

@ -7,10 +7,10 @@
<TableToolbarButton TItem="DataAccess.Models.Role" IsEnableWhenSelectedOneRow="true" Color="Color.Success" Icon="fa fa-dashboard" Text="菜单" OnClickCallback="roles => OnAssignmentMenus(roles.First())" />
<TableToolbarButton TItem="DataAccess.Models.Role" IsEnableWhenSelectedOneRow="true" Color="Color.Secondary" Icon="fa fa-cubes" Text="应用" OnClickCallback="roles => OnAssignmentApps(roles.First())" />
</TableToolbarTemplate>
<ColumnsTemplete>
<TableColumns>
<TableColumn @bind-Field="@context.RoleName" Sortable="true" Filterable="true" Searchable="true" Width="120"></TableColumn>
<TableColumn @bind-Field="@context.Description" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
</ColumnsTemplete>
</TableColumns>
<RowButtonTemplate>
<TableCellButton Size="Size.ExtraSmall" Color="Color.Info" Icon="fa fa-user" Text="用户" OnClick="() => OnAssignmentUsers(context)" />
<TableCellButton Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa fa-bank" Text="部门" OnClick="() => OnAssignmentGroups(context)" />

View File

@ -31,9 +31,8 @@
<AdminAlert Text="演示系统禁止修改内置后台任务" IsShow="IsDemo" />
<Table TItem="TasksModel" ExtendButtonColumnWidth="270" IsBordered="true" IsStriped="true"
IsMultipleSelect="true" IsFixedHeader="false" SortList="SortList"
ShowToolbar="true" ShowExtendButtons="true" SelectedRows="SelectedRows"
<AdminTable TItem="TasksModel" ExtendButtonColumnWidth="270" IsFixedHeader="false" SortList="SortList"
SelectedRows="SelectedRows"
ShowEditButtonCallback="OnShowButtonCallback" ShowDeleteButtonCallback="OnShowButtonCallback"
OnQueryAsync="OnQueryAsync" OnDeleteAsync="OnDeleteAsync" OnSaveAsync="OnSaveAsync">
<TableColumns>
@ -61,5 +60,5 @@
<TableCellButton Size="Size.ExtraSmall" Color="Color.Success" Icon="fa fa-play-circle" Text="运行" OnClick="() => OnRun(context)" IsShow="OnCheckTaskStatus(context)" AutoRenderTableWhenClick="true" />
<TableCellButton Size="Size.ExtraSmall" Color="Color.Info" Icon="fa fa-info-circle" Text="日志" OnClick="() => OnLog(context)" IsShow="OnCheckTaskStatus(context)" AutoRenderTableWhenClick="true" />
</RowButtonTemplate>
</Table>
</AdminTable>
</div>

View File

@ -1,9 +1,6 @@
@page "/Admin/Users"
<Table TItem="DataAccess.Models.User" IsBordered="true" IsStriped="true" IsMultipleSelect="true"
ExtendButtonColumnWidth="270"
ShowToolbar="true" ShowExtendButtons="true" ShowSearch="true"
UseInjectDataService="true">
<AdminTable TItem="DataAccess.Models.User" ExtendButtonColumnWidth="270">
<TableToolbarTemplate>
<TableToolbarButton TItem="DataAccess.Models.User" IsEnableWhenSelectedOneRow="true" Color="Color.Warning" Icon="fa fa-bank" Text="分配部门" OnClickCallback="users => OnAssignmentGroups(users.First())" />
<TableToolbarButton TItem="DataAccess.Models.User" IsEnableWhenSelectedOneRow="true" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="users => OnAssignmentRoles(users.First())" />
@ -36,4 +33,4 @@
<TableCellButton Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa fa-bank" Text="分配部门" OnClick="() => OnAssignmentGroups(context)" />
<TableCellButton Size="Size.ExtraSmall" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClick="() => OnAssignmentRoles(context)" />
</RowButtonTemplate>
</Table>
</AdminTable>