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

View File

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

View File

@ -22,7 +22,12 @@
/// <summary>
///
/// </summary>
[NotNull]
[Parameter]
public RenderFragment<TItem>? RowButtonTemplate { get; set; }
/// <summary>
///
/// </summary>
[Parameter]
public RenderFragment<ITableSearchModel>? CustomerSearchTemplate { get; set; }
@ -56,17 +61,5 @@
/// </summary>
[Parameter]
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"
<BlazorTable TItem="DataAccess.Models.User" @bind-SelectedRows="SelectedRows">
<BlazorTable TItem="DataAccess.Models.User">
<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" IsDisabled="SelectedRows.Count() != 1" Color="Color.Warning" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="OnAssignmentRoles" />
<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" IsEnableWhenSelectedOneRow="true" Color="Color.Info" Icon="fa fa-sitemap" Text="分配角色" OnClickCallback="users => OnAssignmentRoles(users.First())" />
</TableToolbarTemplate>
<ColumnsTemplete>
<TableColumn @bind-Field="@context.UserName" Text="登录名称" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
<TableColumn @bind-Field="@context.DisplayName" Text="显示名称" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
<TableColumn @bind-Field="@context.RegisterTime" Text="注册时间" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.ApprovedTime" Text="授权时间" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.ApprovedBy" Text="授权人" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.Description" Text="说明" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.UserName" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
<TableColumn @bind-Field="@context.DisplayName" Sortable="true" Filterable="true" Searchable="true"></TableColumn>
<TableColumn @bind-Field="@context.RegisterTime" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.ApprovedTime" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.ApprovedBy" Sortable="true" Filterable="true"></TableColumn>
<TableColumn @bind-Field="@context.Description" Sortable="true" Filterable="true"></TableColumn>
</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>

View File

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