Devexpress Blazore项目前端页面基类

using System;

using System.Threading.Tasks;

using Blazored.LocalStorage;

using Blazored.Toast.Services;

using Microsoft.AspNetCore.Components;

using Client.Services;

using Data.Models;

namespace Client.Classes.Impl

{

public class MinimalComponentBase : ComponentBase

{

#region Inject section

[Inject] protected IApiService ApiService { get; set; }

[Inject] protected IUserService UserService { get; set; }

[Inject] protected NavigationManager NavigationManager { get; set; }

[Inject] protected IToastService ToastService { get; set; }

[Inject] protected ILocalStorageService LocalStorageService { get; set; }

#endregion

#region Parameters

[Parameter] public bool ReadOnly { get; set; }

#endregion

#region Protected properties

protected ClaimTypes RequiredClaimType { get; set; }

protected bool IsAdmin { get; set; }

protected bool CanCreate { get; set; }

protected bool CanEdit { get; set; }

protected bool CanDelete { get; set; }

protected bool CanRestore { get; set; }

protected string ApiUrl { get; set; }

protected bool IsValidating { get; set; } = true;

protected bool IsFreeAccess { get; set; }

protected bool IsOnlyAdmin { get; set; }

#endregion

#region Protected methods

protected virtual async Task InitComponent(TgClaimTypes requireClaimType, string apiUrl)

{

ApiUrl = apiUrl;

RequiredClaimType = requireClaimType;

await ValidatePermission();

ApiService.SetBaseUrl(ApiUrl);

}

protected void RedirectToLoginPage()

{

var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);

var url = "/login";

if (string.IsNullOrEmpty(returnUrl) == false) url += $"?returnUrl={returnUrl}";

NavigationManager.NavigateTo(url);

}

protected void RedirectToErrorPage(string errorMessage)

{

NavigationManager.NavigateTo("/error");

}

protected void RedirectToAccessDeniedPage()

{

NavigationManager.NavigateTo("/access-denied");

}

// Must validate permission on initialized

protected async Task ValidatePermission()

{

await UserService.LoadAsync();

// IsAdmin = UserService.IsAdminLevel;

IsAdmin = true;

var permission = await UserService.GetPermissionAsync(RequiredClaimType);

if (ApiService.IsSessionExpired) RedirectToLoginPage();

if (ApiService.IsError) RedirectToErrorPage(ApiService.ErrorMessage);

if (IsOnlyAdmin && IsAdmin == false) RedirectToAccessDeniedPage();

if (IsFreeAccess == false)

{

CanEdit = ((permission?.Value ?? -1) >= TgPermissions.Update.Value || IsAdmin) && ReadOnly == false;

if ((permission?.Value ?? -1) < TgPermissions.View.Value && IsAdmin == false)

RedirectToAccessDeniedPage();

}

IsValidating = false;

}

#endregion

}

}

相关推荐
!chen1 年前
WMS重力式货架库位对应方法
plc wcs系统
!chen1 年前
实现MQTT协议的服务器端和客户端的双向交互
开发语言·交互·plc wcs系统
!chen1 年前
立体库堆垛机控制程序手动功能实现
plc wcs系统
!chen1 年前
立体库堆垛机水平电机输出控制程序功能
plc wcs系统
!chen1 年前
立体库堆垛机提升电机运行动作功能块
plc wcs系统
!chen1 年前
SINAMICS S120变频器电流转矩功率限幅功能
plc wcs系统
!chen1 年前
劳易测扫码条码分段读取实现方法
plc wcs系统
!chen1 年前
DCN无线网络解决方案
plc wcs系统
!chen1 年前
.NetCore开发Jwt认证实现JwtUtil
.netcore·plc wcs系统