-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/NetCorePal.D3Shop.Web.Admin.Client/Components/EditRolePermissions.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@using NetCorePal.D3Shop.Web.Admin.Client.Services | ||
<a @onclick="ShowModal">配置权限</a> | ||
<Modal Title="@("配置权限")" | ||
Visible="@_modalVisible" | ||
OnOk="Modal_HandleOk" | ||
OnCancel="() => _modalVisible = false" | ||
ConfirmLoading="@_modalConfirmLoading"> | ||
|
||
<Tree TItem="string" | ||
Checkable | ||
DefaultCheckedKeys="Row.PermissionCodes.ToArray()" | ||
@bind-CheckedKeys="_treeCheckedKeys" | ||
OnCheck="Tree_OnCheck"> | ||
@foreach (var group in _allPermissions.GroupBy(p => p.GroupName)) | ||
{ | ||
<TreeNode Title="@group.Key" Key="@group.Key"> | ||
@foreach (var permission in group) | ||
{ | ||
<TreeNode Title="@permission.Remark" Key="@permission.Code"/> | ||
} | ||
</TreeNode> | ||
} | ||
</Tree> | ||
</Modal> | ||
|
||
@code { | ||
[CascadingParameter] public RoleResponse Row { get; set; } = default!; | ||
[Inject] private IRolesService RolesService { get; set; } = default!; | ||
[Inject] private IPermissionsService PermissionsService { get; set; } = default!; | ||
|
||
[Inject] private MessageService Message { get; set; } = default!; | ||
private string[] _treeCheckedKeys = []; | ||
private List<Permission> _allPermissions = []; | ||
private List<string> _checkedPermission = []; | ||
|
||
private bool _modalVisible; | ||
private bool _modalConfirmLoading; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
_checkedPermission = Row.PermissionCodes.ToList(); | ||
} | ||
|
||
private async Task ShowModal() | ||
{ | ||
_modalVisible = true; | ||
_allPermissions = await GetAllPermissions(); | ||
} | ||
|
||
private async Task<List<Permission>> GetAllPermissions() | ||
{ | ||
var response = await PermissionsService.GetAll(); | ||
if (response.Success) return response.Data.ToList(); | ||
_ = Message.Error(response.Message); | ||
return []; | ||
} | ||
|
||
private void Tree_OnCheck(TreeEventArgs<string> e) | ||
{ | ||
_checkedPermission = _allPermissions | ||
.Where(p => _treeCheckedKeys.Contains(p.Code)) | ||
.Select(p => p.Code).ToList(); | ||
} | ||
|
||
private async Task Modal_HandleOk() | ||
{ | ||
_modalConfirmLoading = true; | ||
StateHasChanged(); | ||
var response = await RolesService.UpdateRolePermissions(Row.Id, _checkedPermission); | ||
_modalConfirmLoading = false; | ||
if (response.Success) | ||
{ | ||
_modalVisible = false; | ||
_ = Message.Success("更新成功!"); | ||
Row.PermissionCodes = _checkedPermission; | ||
} | ||
else | ||
{ | ||
_ = Message.Error(response.Message); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters