feat: 用户维护增加分配授权按钮逻辑

This commit is contained in:
Argo-Tianyi 2021-12-15 14:59:58 +08:00
parent 31c9c4de7b
commit eaf36fec5e
9 changed files with 95 additions and 69 deletions

View File

@ -1,4 +1,6 @@
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
namespace BootstrapAdmin.DataAccess.Models namespace BootstrapAdmin.DataAccess.Models
{ {
@ -10,6 +12,7 @@ namespace BootstrapAdmin.DataAccess.Models
/// <summary> /// <summary>
/// 获得/设置 系统登录用户名 /// 获得/设置 系统登录用户名
/// </summary> /// </summary>
[Display(Name = "登录名称")]
public string UserName { get; set; } = ""; public string UserName { get; set; } = "";
/// <summary> /// <summary>
@ -40,7 +43,7 @@ namespace BootstrapAdmin.DataAccess.Models
/// <summary> /// <summary>
/// 获取/设置 密码 /// 获取/设置 密码
/// </summary> /// </summary>
[DisplayName("登录密码")] [Display(Name = "登录密码")]
public string Password { get; set; } = ""; public string Password { get; set; } = "";
/// <summary> /// <summary>
@ -56,25 +59,25 @@ namespace BootstrapAdmin.DataAccess.Models
/// <summary> /// <summary>
/// 获得/设置 用户注册时间 /// 获得/设置 用户注册时间
/// </summary> /// </summary>
[DisplayName("注册时间")] [Display(Name = "注册时间")]
public DateTime RegisterTime { get; set; } = DateTime.Now; public DateTime RegisterTime { get; set; } = DateTime.Now;
/// <summary> /// <summary>
/// 获得/设置 用户被批复时间 /// 获得/设置 用户被批复时间
/// </summary> /// </summary>
[DisplayName("授权时间")] [Display(Name = "授权时间")]
public DateTime? ApprovedTime { get; set; } public DateTime? ApprovedTime { get; set; }
/// <summary> /// <summary>
/// 获得/设置 用户批复人 /// 获得/设置 用户批复人
/// </summary> /// </summary>
[DisplayName("授权人")] [Display(Name = "授权人")]
public string? ApprovedBy { get; set; } public string? ApprovedBy { get; set; }
/// <summary> /// <summary>
/// 获得/设置 用户的申请理由 /// 获得/设置 用户的申请理由
/// </summary> /// </summary>
[DisplayName("说明")] [Display(Name = "说明")]
public string Description { get; set; } = ""; public string Description { get; set; } = "";
/// <summary> /// <summary>
@ -90,7 +93,7 @@ namespace BootstrapAdmin.DataAccess.Models
/// <summary> /// <summary>
/// 获得/设置 新密码 /// 获得/设置 新密码
/// </summary> /// </summary>
[DisplayName("确认密码")] [Display(Name = "确认密码")]
public string NewPassword { get; set; } = ""; public string NewPassword { get; set; } = "";
/// <summary> /// <summary>

View File

@ -4,15 +4,18 @@
IsPagination="IsPagination" PageItemsSource="PageItemsSource" IsPagination="IsPagination" PageItemsSource="PageItemsSource"
UseInjectDataService="true" DataService="DataService" OnQueryAsync="OnQueryAsync!" UseInjectDataService="true" DataService="DataService" OnQueryAsync="OnQueryAsync!"
ShowToolbar="true" ShowExtendButtons="true" ShowSearch="true" ShowToolbar="true" ShowExtendButtons="true" ShowSearch="true"
ShowCardView="true" ShowColumnList="true" @bind-SelectedRows="SelectedRows" ShowCardView="true" ShowColumnList="true"
CustomerSearchModel="@TableSearchModel"> CustomerSearchModel="@TableSearchModel">
<TableToolbarTemplate> <TableToolbarTemplate>
@TableToolbarTemplate @TableToolbarTemplate
</TableToolbarTemplate> </TableToolbarTemplate>
<TableColumns> <TableColumns>
@ColumnsTemplete(context) @ColumnsTemplete?.Invoke(context)
</TableColumns> </TableColumns>
<CustomerSearchTemplate> <CustomerSearchTemplate>
@CustomerSearchTemplate(context) @CustomerSearchTemplate?.Invoke(context)
</CustomerSearchTemplate> </CustomerSearchTemplate>
<RowButtonTemplate>
@RowButtonTemplate?.Invoke(context)
</RowButtonTemplate>
</Table> </Table>

View File

@ -22,7 +22,12 @@
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[NotNull] [Parameter]
public RenderFragment<TItem>? RowButtonTemplate { get; set; }
/// <summary>
///
/// </summary>
[Parameter] [Parameter]
public RenderFragment<ITableSearchModel>? CustomerSearchTemplate { get; set; } public RenderFragment<ITableSearchModel>? CustomerSearchTemplate { get; set; }
@ -56,17 +61,5 @@
/// </summary> /// </summary>
[Parameter] [Parameter]
public Func<QueryPageOptions, Task<QueryData<TItem>>>? OnQueryAsync { get; set; } public Func<QueryPageOptions, Task<QueryData<TItem>>>? OnQueryAsync { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public List<TItem> SelectedRows { get; set; } = new List<TItem>();
/// <summary>
///
/// </summary>
[Parameter]
public EventCallback<List<TItem>> SelectedRowsChanged { get; set; }
} }
} }

View File

@ -0,0 +1,5 @@
<h3>UserGroup</h3>
@code {
}

View File

@ -0,0 +1,16 @@
namespace BootstrapAdmin.Web.Components
{
/// <summary>
///
/// </summary>
public partial class UserGroup
{
/// <summary>
///
/// </summary>
[Parameter]
[NotNull]
[EditorRequired]
public string? UserName { get; set; }
}
}

View File

@ -0,0 +1,5 @@
<h3>UserRole</h3>
@code {
}

View File

@ -0,0 +1,16 @@
namespace BootstrapAdmin.Web.Components
{
/// <summary>
///
/// </summary>
public partial class UserRole
{
/// <summary>
///
/// </summary>
[Parameter]
[NotNull]
[EditorRequired]
public string? UserName { get; set; }
}
}

View File

@ -1,16 +1,20 @@
@page "/Admin/Users" @page "/Admin/Users"
<BlazorTable TItem="DataAccess.Models.User" @bind-SelectedRows="SelectedRows"> <BlazorTable TItem="DataAccess.Models.User">
<TableToolbarTemplate> <TableToolbarTemplate>
<TableToolbarButton TItem="DataAccess.Models.User" IsDisabled="SelectedRows.Count() != 1" Color="Color.Info" Icon="fa fa-bank" Text="分配部门" OnClickCallback="OnAssignmentDept" /> <TableToolbarButton TItem="DataAccess.Models.User" IsEnableWhenSelectedOneRow="true" Color="Color.Warning" Icon="fa fa-bank" Text="分配部门" OnClickCallback="users => OnAssignmentDept(users.First())" />
<TableToolbarButton TItem="DataAccess.Models.User" IsDisabled="SelectedRows.Count() != 1" Color="Color.Warning" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="OnAssignmentRoles" /> <TableToolbarButton TItem="DataAccess.Models.User" IsEnableWhenSelectedOneRow="true" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="users => OnAssignmentRoles(users.First())" />
</TableToolbarTemplate> </TableToolbarTemplate>
<ColumnsTemplete> <ColumnsTemplete>
<TableColumn @bind-Field="@context.UserName" Text="登录名称" Sortable="true" Filterable="true" Searchable="true"></TableColumn> <TableColumn @bind-Field="@context.UserName" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
<TableColumn @bind-Field="@context.DisplayName" Text="显示名称" Sortable="true" Filterable="true" Searchable="true"></TableColumn> <TableColumn @bind-Field="@context.DisplayName" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
<TableColumn @bind-Field="@context.RegisterTime" Text="注册时间" Sortable="true" Filterable="true"></TableColumn> <TableColumn @bind-Field="@context.RegisterTime" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.ApprovedTime" Text="授权时间" Sortable="true" Filterable="true"></TableColumn> <TableColumn @bind-Field="@context.ApprovedTime" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.ApprovedBy" Text="授权人" Sortable="true" Filterable="true"></TableColumn> <TableColumn @bind-Field="@context.ApprovedBy" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.Description" Text="说明" Sortable="true" Filterable="true"></TableColumn> <TableColumn @bind-Field="@context.Description" Sortable="true" Filterable="true"></TableColumn>
</ColumnsTemplete> </ColumnsTemplete>
<RowButtonTemplate>
<TableCellButton Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa fa-bank" Text="分配部门" OnClickCallback="() => OnAssignmentDept(context)" />
<TableCellButton Size="Size.ExtraSmall" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="() => OnAssignmentRoles(context)" />
</RowButtonTemplate>
</BlazorTable> </BlazorTable>

View File

@ -1,4 +1,5 @@
using BootstrapAdmin.DataAccess.Models; using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Components;
namespace BootstrapAdmin.Web.Pages.Admin namespace BootstrapAdmin.Web.Pages.Admin
{ {
@ -11,52 +12,32 @@ namespace BootstrapAdmin.Web.Pages.Admin
[NotNull] [NotNull]
private DialogService? DialogService { get; set; } private DialogService? DialogService { get; set; }
[Inject] private async Task OnAssignmentDept(User user)
[NotNull]
private ToastService? ToastService { get; set; }
private List<User> SelectedRows { get; set; } = new List<User>();
private async Task OnAssignmentDept(IEnumerable<User> users)
{ {
if (users.Count() == 1) var option = new DialogOption()
{ {
//var option = new DialogOption() Title = $"分配部门 - {user.ToString()}",
//{ Component = BootstrapDynamicComponent.CreateComponent<UserGroup>(new Dictionary<string, object>
// Title = "部门授权", {
// BodyTemplate = BootstrapDynamicComponent.CreateComponent<CheckboxList<string>>(new Dictionary<string, object> [nameof(UserGroup.UserName)] = user.UserName
// { })
// [nameof(CheckboxList<string>.Items)] = GroupHelper.Retrieves().Select(s => new SelectedItem(s.GroupCode, s.GroupName)) };
// }).Render()
//};
//await DialogService.Show(option); await DialogService.Show(option);
}
else
{
await ToastService.Warning("部门授权", "请选择一个用户");
}
} }
private async Task OnAssignmentRoles(IEnumerable<User> users) private async Task OnAssignmentRoles(User user)
{ {
if (users.Count() != 0) var option = new DialogOption()
{ {
//var option = new DialogOption() Title = $"分配角色 - {user.ToString()}",
//{ Component = BootstrapDynamicComponent.CreateComponent<UserRole>(new Dictionary<string, object>
// Title = "分配角色", {
// BodyTemplate = BootstrapDynamicComponent.CreateComponent<CheckboxList<string>>(new Dictionary<string, object> [nameof(UserGroup.UserName)] = user.UserName
// { })
// [nameof(CheckboxList<string>.Items)] = RoleHelper.Retrieves().Select(s => new SelectedItem(s.Id!, s.RoleName) { Active = s.Checked == "" ? false : true }) };
// }).Render()
//};
//await DialogService.Show(option); await DialogService.Show(option);
}
else
{
await ToastService.Warning("分配角色", "请选择一个用户");
}
} }
} }
} }