feat: 增加授权检查控件与条件输出控件
This commit is contained in:
parent
ee8842c13a
commit
f0fb88d86f
|
@ -0,0 +1,70 @@
|
|||
using Bootstrap.Admin.Extensions;
|
||||
using Bootstrap.Security.Authorization;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// 授权组件
|
||||
/// </summary>
|
||||
public class AuthorizateComponent : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 授权键值
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Key { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
protected IButtonAuthorization? AuthorizationServices { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
protected AuthenticationStateProvider? AuthenticationStateProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
protected NavigationManager? NavigationManager { get; set; }
|
||||
|
||||
private bool authorizated;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
if (AuthenticationStateProvider != null)
|
||||
{
|
||||
var user = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var url = new UriBuilder(NavigationManager?.Uri ?? "").Path;
|
||||
authorizated = AuthorizationServices != null && AuthorizationServices.Authorizate(user.User, url.ToMvcMenuUrl(), Key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
if (authorizated) builder.AddContent(0, ChildContent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using Bootstrap.Admin.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件输出组件
|
||||
/// </summary>
|
||||
public class ConditionComponent : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 是否显示 默认 true 显示
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool Inverse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout? RootLayout { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
var render = RootLayout?.Model.IsDemo ?? true;
|
||||
if (Inverse) render = !render;
|
||||
if (render) builder.AddContent(0, ChildContent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +1,63 @@
|
|||
<div class="card" asp-auth="saveDisplayName">
|
||||
<div class="card-header">基本资料</div>
|
||||
<div class="card-body" data-toggle="LgbValidate" data-valid-button="#btnSaveDisplayName">
|
||||
@if (IsDemo)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<span>演示系统禁止更改管理员显示名称</span>
|
||||
</div>
|
||||
}
|
||||
<form class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="userName">登录名称</label>
|
||||
<input type="text" class="form-control ignore" value="@Model?.UserName" readonly />
|
||||
<AuthorizateComponent Key="saveDisplayName">
|
||||
<div class="card">
|
||||
<div class="card-header">基本资料</div>
|
||||
<div class="card-body">
|
||||
<ConditionComponent>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<span>演示系统禁止更改管理员显示名称</span>
|
||||
</div>
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="DisplayName">显示名称</label>
|
||||
<input type="text" class="form-control" @bind="@DisplayName" placeholder="不可为空,20字以内" maxlength="20" data-valid="true" />
|
||||
</ConditionComponent>
|
||||
<form class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="userName">登录名称</label>
|
||||
<input type="text" class="form-control ignore" value="@Model?.UserName" readonly />
|
||||
</div>
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="DisplayName">显示名称</label>
|
||||
<input type="text" class="form-control" @bind="@DisplayName" placeholder="不可为空,20字以内" maxlength="20" data-valid="true" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@if (!IsDemo)
|
||||
{
|
||||
<div class="modal-footer">
|
||||
<button id="btnSaveDisplayName" data-method="user" class="btn btn-secondary" type="button" @onclick="SaveDisplayName"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
<ConditionComponent Inverse="true">
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" type="button" @onclick="SaveDisplayName"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
</div>
|
||||
</ConditionComponent>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthorizateComponent>
|
||||
<div class="card" asp-auth="savePassword" asp-condition="!@Model?.External">
|
||||
<div class="card-header">修改密码</div>
|
||||
<div class="card-body" data-toggle="LgbValidate" data-valid-button="#btnSavePassword">
|
||||
@if (IsDemo)
|
||||
{
|
||||
<div class="card-body">
|
||||
<ConditionComponent>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<span>演示系统禁止更改管理员密码</span>
|
||||
</div>
|
||||
}
|
||||
</ConditionComponent>
|
||||
<form class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="currentPassword">原密码: </label>
|
||||
<input type="password" class="form-control" id="currentPassword" autocomplete="off" placeholder="原密码" maxlength="16" data-valid="true" />
|
||||
<input type="password" class="form-control" autocomplete="off" placeholder="原密码" maxlength="16" data-valid="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="newPassword">新密码: </label>
|
||||
<input type="password" class="form-control" id="newPassword" autocomplete="off" placeholder="新密码" maxlength="16" data-valid="true" />
|
||||
<input type="password" class="form-control" autocomplete="off" placeholder="新密码" maxlength="16" data-valid="true" />
|
||||
</div>
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="confirmPassword">确认密码: </label>
|
||||
<input type="password" class="form-control" id="confirmPassword" autocomplete="off" placeholder="与新密码一致" maxlength="16" equalTo="#newPassword" data-valid="true" />
|
||||
<input type="password" class="form-control" autocomplete="off" placeholder="与新密码一致" maxlength="16" data-valid="true" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@if (!IsDemo)
|
||||
{
|
||||
<ConditionComponent Inverse="true">
|
||||
<div class="modal-footer">
|
||||
<button id="btnSavePassword" data-method="password" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
<button class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
</div>
|
||||
}
|
||||
</ConditionComponent>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" asp-auth="saveApp">
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
查询结果
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ConditionComponent>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<span>演示系统禁止修改系统使用字典配置项</span>
|
||||
</div>
|
||||
</ConditionComponent>
|
||||
<Table @ref="Table" Id="@Id" TItem="TItem" OnQuery="QueryData" OnAdd="OnAdd" OnDelete="OnDelete" OnSave="OnSave">
|
||||
<TableHeader>
|
||||
@TableHeader?.Invoke(context)
|
||||
|
|
Loading…
Reference in New Issue