feat: 用户页面添加按钮权限

This commit is contained in:
zhangpeihang 2022-01-20 00:20:03 +08:00
parent 503c1a4a2b
commit d77d4786aa
2 changed files with 22 additions and 1 deletions

View File

@ -1,7 +1,7 @@
@page "/Admin/Users"
<Table TItem="DataAccess.Models.User" IsBordered="true" IsStriped="true" IsMultipleSelect="true"
ExtendButtonColumnWidth="270"
ExtendButtonColumnWidth="270" ShowAddButton="@AuthorizeButton("add")" ShowDeleteButton="@AuthorizeButton("del")" ShowEditButton="@AuthorizeButton("edit")"
ShowToolbar="true" ShowExtendButtons="true" ShowSearch="true"
UseInjectDataService="true" OnSaveAsync="@OnSaveAsync">
<TableToolbarTemplate>

View File

@ -1,6 +1,7 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Core;
using BootstrapAdmin.Web.Extensions;
using BootstrapAdmin.Web.Services;
using BootstrapAdmin.Web.Validators;
namespace BootstrapAdmin.Web.Pages.Admin;
@ -30,6 +31,19 @@ public partial class Users
[NotNull]
private IUser? UserService { get; set; }
[Inject]
[NotNull]
private INavigation? NavigationService { get; set; }
[Inject]
[NotNull]
private NavigationManager? NavigationManager { get; set; }
[Inject]
[NotNull]
private BootstrapAppContext? AppContext { get; set; }
private static bool GetDisabled(string? id) => !string.IsNullOrEmpty(id);
private List<IValidator> UserRules { get; } = new List<IValidator>();
@ -71,4 +85,11 @@ public partial class Users
{
return Task.FromResult(UserService.SaveUser(user.UserName, user.DisplayName, user.NewPassword));
}
private bool AuthorizeButton(string operate)
{
var url = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
return NavigationService.AuthorizationBlock(url, AppContext.UserName, operate);
}
}