feat: 增加角色对部门授权功能

This commit is contained in:
Argo-Tianyi 2021-12-21 11:55:49 +08:00
parent 6029e86072
commit f2095cac40
3 changed files with 65 additions and 6 deletions

View File

@ -49,5 +49,37 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
} }
return ret; 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;
}
} }
} }

View File

@ -25,7 +25,22 @@ public interface IGroup
/// ///
/// </summary> /// </summary>
/// <param name="userId"></param> /// <param name="userId"></param>
/// <param name="values"></param> /// <param name="groupIds"></param>
/// <returns></returns> /// <returns></returns>
bool SaveGroupsByUserId(string? userId, IEnumerable<string> groupIds); 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);
} }

View File

@ -1,5 +1,7 @@
using BootstrapAdmin.DataAccess.Models; using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Components; using BootstrapAdmin.Web.Components;
using BootstrapAdmin.Web.Core;
using BootstrapAdmin.Web.Extensions;
namespace BootstrapAdmin.Web.Pages.Admin namespace BootstrapAdmin.Web.Pages.Admin
{ {
@ -9,6 +11,14 @@ namespace BootstrapAdmin.Web.Pages.Admin
[NotNull] [NotNull]
private DialogService? DialogService { get; set; } 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) private async Task OnAssignmentUsers(Role role)
{ {
var option = new DialogOption() var option = new DialogOption()
@ -21,12 +31,14 @@ namespace BootstrapAdmin.Web.Pages.Admin
private async Task OnAssignmentGroups(Role role) private async Task OnAssignmentGroups(Role role)
{ {
var option = new DialogOption() var groups = GroupService.GetAll().ToSelectedItemList();
{ var values = GroupService.GetGroupsByRoleId(role.Id);
Title = $"分配部门 - {role}",
};
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) private async Task OnAssignmentMenus(Role role)