feat: 增加角色对部门授权功能
This commit is contained in:
parent
6029e86072
commit
f2095cac40
|
@ -49,5 +49,37 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> GetGroupsByRoleId(string? roleId) => Database.Fetch<string>("select GroupID from RoleGroup where RoleGroup = @0", roleId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="groupIds"></param>
|
||||
/// <returns></returns>
|
||||
public bool SaveGroupsByRoleId(string? roleId, IEnumerable<string> groupIds)
|
||||
{
|
||||
var ret = false;
|
||||
try
|
||||
{
|
||||
Database.BeginTransaction();
|
||||
Database.Execute("delete from RoleGroup where RoleGroup = @0", roleId);
|
||||
Database.InsertBatch("RoleGroup", groupIds.Select(g => new { GroupID = g, RoleID = roleId }));
|
||||
Database.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Database.AbortTransaction();
|
||||
throw;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,22 @@ public interface IGroup
|
|||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="values"></param>
|
||||
/// <param name="groupIds"></param>
|
||||
/// <returns></returns>
|
||||
bool SaveGroupsByUserId(string? userId, IEnumerable<string> groupIds);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
List<string> GetGroupsByRoleId(string? roleId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="groupIds"></param>
|
||||
/// <returns></returns>
|
||||
bool SaveGroupsByRoleId(string? roleId, IEnumerable<string> groupIds);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Components;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
|
||||
namespace BootstrapAdmin.Web.Pages.Admin
|
||||
{
|
||||
|
@ -9,6 +11,14 @@ namespace BootstrapAdmin.Web.Pages.Admin
|
|||
[NotNull]
|
||||
private DialogService? DialogService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private ToastService? ToastService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IGroup? GroupService { get; set; }
|
||||
|
||||
private async Task OnAssignmentUsers(Role role)
|
||||
{
|
||||
var option = new DialogOption()
|
||||
|
@ -21,12 +31,14 @@ namespace BootstrapAdmin.Web.Pages.Admin
|
|||
|
||||
private async Task OnAssignmentGroups(Role role)
|
||||
{
|
||||
var option = new DialogOption()
|
||||
{
|
||||
Title = $"分配部门 - {role}",
|
||||
};
|
||||
var groups = GroupService.GetAll().ToSelectedItemList();
|
||||
var values = GroupService.GetGroupsByRoleId(role.Id);
|
||||
|
||||
await DialogService.Show(option);
|
||||
await DialogService.ShowAssignmentDialog($"分配部门 - {role.RoleName}", groups, values, () =>
|
||||
{
|
||||
var ret = GroupService.SaveGroupsByRoleId(role.Id, values);
|
||||
return Task.FromResult(ret);
|
||||
}, ToastService);
|
||||
}
|
||||
|
||||
private async Task OnAssignmentMenus(Role role)
|
||||
|
|
Loading…
Reference in New Issue