2023-08-07 15:09:53 +08:00
|
|
|
|
#region copyright
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
|
|
|
|
|
|
// 此代码版权(除特别声明外的代码)归作者本人Diego所有
|
|
|
|
|
|
// 源代码使用协议遵循本仓库的开源协议及附加协议
|
|
|
|
|
|
// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
|
|
|
|
|
|
// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
|
|
|
|
|
|
// 使用文档:https://diego2098.gitee.io/thingsgateway-docs/
|
|
|
|
|
|
// QQ群:605534569
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
using Masa.Blazor;
|
|
|
|
|
|
using Masa.Blazor.Presets;
|
|
|
|
|
|
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
2023-09-30 23:05:53 +08:00
|
|
|
|
|
2023-08-07 15:09:53 +08:00
|
|
|
|
|
|
|
|
|
|
namespace ThingsGateway.Admin.Blazor;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 角色页面
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class Role
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly RolePageInput search = new();
|
|
|
|
|
|
private IAppDataTable _datatable;
|
|
|
|
|
|
private List<UserSelectorOutput> AllUsers;
|
|
|
|
|
|
long ChoiceRoleId;
|
|
|
|
|
|
bool IsShowResuorces;
|
|
|
|
|
|
bool IsShowUsers;
|
|
|
|
|
|
List<RoleGrantResourceMenu> ResTreeSelectors = new();
|
|
|
|
|
|
List<RelationRoleResuorce> RoleHasResuorces = new();
|
|
|
|
|
|
private List<UserSelectorOutput> UsersChoice;
|
|
|
|
|
|
|
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
|
MainLayout MainLayout { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-02 19:13:57 +08:00
|
|
|
|
private string SearchKey { get; set; }
|
2023-08-07 15:09:53 +08:00
|
|
|
|
|
|
|
|
|
|
private Task AddCallAsync(RoleAddInput input)
|
|
|
|
|
|
{
|
2023-09-02 19:13:57 +08:00
|
|
|
|
return App.GetService<RoleService>().AddAsync(input);
|
2023-08-07 15:09:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
private async Task DeleteCallAsync(IEnumerable<SysRole> sysRoles)
|
|
|
|
|
|
{
|
2023-09-02 19:13:57 +08:00
|
|
|
|
await App.GetService<RoleService>().DeleteAsync(sysRoles.Select(a => a.Id).ToArray());
|
2023-08-07 15:09:53 +08:00
|
|
|
|
await MainLayout.StateHasChangedAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task EditCallAsync(RoleEditInput input)
|
|
|
|
|
|
{
|
2023-09-02 19:13:57 +08:00
|
|
|
|
await App.GetService<RoleService>().EditAsync(input);
|
2023-08-07 15:09:53 +08:00
|
|
|
|
await MainLayout.StateHasChangedAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
private async Task OnRoleHasResuorcesSaveAsync(ModalActionEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
GrantResourceInput userGrantRoleInput = new();
|
|
|
|
|
|
var data = new List<SysResource>();
|
|
|
|
|
|
userGrantRoleInput.Id = ChoiceRoleId;
|
|
|
|
|
|
userGrantRoleInput.GrantInfoList = RoleHasResuorces;
|
2023-09-02 19:13:57 +08:00
|
|
|
|
await App.GetService<RoleService>().GrantResourceAsync(userGrantRoleInput);
|
2023-08-07 15:09:53 +08:00
|
|
|
|
IsShowResuorces = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
args.Cancel();
|
|
|
|
|
|
await PopupService.EnqueueSnackbarAsync(ex, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
await MainLayout.StateHasChangedAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
private async Task OnUsersSaveAsync(ModalActionEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
GrantUserInput userGrantRoleInput = new();
|
|
|
|
|
|
userGrantRoleInput.Id = ChoiceRoleId;
|
|
|
|
|
|
userGrantRoleInput.GrantInfoList = UsersChoice.Select(it => it.Id).ToList();
|
2023-09-02 19:13:57 +08:00
|
|
|
|
await App.GetService<RoleService>().GrantUserAsync(userGrantRoleInput);
|
2023-08-07 15:09:53 +08:00
|
|
|
|
IsShowUsers = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
args.Cancel();
|
|
|
|
|
|
await PopupService.EnqueueSnackbarAsync(ex, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
await MainLayout.StateHasChangedAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-30 23:05:53 +08:00
|
|
|
|
private Task<ISqlSugarPagedList<SysRole>> QueryCallAsync(RolePageInput input)
|
2023-08-07 15:09:53 +08:00
|
|
|
|
{
|
2023-09-02 19:13:57 +08:00
|
|
|
|
return App.GetService<RoleService>().PageAsync(input);
|
2023-08-07 15:09:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task ResuorceInitAsync()
|
|
|
|
|
|
{
|
2023-09-02 19:13:57 +08:00
|
|
|
|
ResTreeSelectors = (await App.GetService<ResourceService>().GetRoleGrantResourceMenusAsync());
|
|
|
|
|
|
RoleHasResuorces = (await App.GetService<RoleService>().OwnResourceAsync(ChoiceRoleId))?.GrantInfoList;
|
2023-08-07 15:09:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<UserSelectorOutput>> UserInitAsync()
|
|
|
|
|
|
{
|
2023-09-02 19:13:57 +08:00
|
|
|
|
AllUsers = await App.GetService<SysUserService>().UserSelectorAsync(SearchKey);
|
|
|
|
|
|
var data = await App.GetService<RoleService>().OwnUserAsync(ChoiceRoleId);
|
2023-08-07 15:09:53 +08:00
|
|
|
|
UsersChoice = AllUsers.Where(a => data.Contains(a.Id)).ToList();
|
|
|
|
|
|
return AllUsers;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|