feat: 增加未认证时不渲染页面逻辑
This commit is contained in:
parent
8b3ac481e9
commit
05cfdeefb3
|
@ -22,6 +22,9 @@
|
|||
Navigation.NavigateTo($"/Admin/Index", true);
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Navigation.NavigateTo($"/Admin/Index", true);
|
||||
|
|
|
@ -1,37 +1,40 @@
|
|||
@inherits LayoutComponentBase
|
||||
|
||||
<Layout SideWidth="0" IsPage="true" IsFullSide="true" IsFixedHeader="true" IsFixedFooter="false"
|
||||
@if (Login)
|
||||
{
|
||||
<Layout SideWidth="0" IsPage="true" IsFullSide="true" IsFixedHeader="true" IsFixedFooter="false"
|
||||
ShowFooter="true" ShowGotoTop="true" ShowCollapseBar="true" Menus="@MenuItems"
|
||||
OnAuthorizing = "@OnAuthorizing"
|
||||
OnAuthorizing="@OnAuthorizing"
|
||||
UseTabSet="true" TabDefaultUrl="/Admin/Index">
|
||||
<Header>
|
||||
<span class="ms-3 flex-fill">Bootstrap of Blazor</span>
|
||||
<img src="/images/Argo.png" class="layout-avatar-right" />
|
||||
<span class="mx-3 d-none d-sm-block">@DisplayName</span>
|
||||
<div class="layout-drawer"><i class="fa fa-gears"></i></div>
|
||||
</Header>
|
||||
<Side>
|
||||
<div class="layout-banner">
|
||||
<img class="layout-logo" src="/images/brand.png" />
|
||||
<div class="layout-title">
|
||||
<span>@Title</span>
|
||||
<Header>
|
||||
<span class="ms-3 flex-fill">Bootstrap of Blazor</span>
|
||||
<img src="/images/Argo.png" class="layout-avatar-right" />
|
||||
<span class="mx-3 d-none d-sm-block">@DisplayName</span>
|
||||
<div class="layout-drawer"><i class="fa fa-gears"></i></div>
|
||||
</Header>
|
||||
<Side>
|
||||
<div class="layout-banner">
|
||||
<img class="layout-logo" src="/images/brand.png" />
|
||||
<div class="layout-title">
|
||||
<span>@Title</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-user">
|
||||
<img class="layout-avatar" src="/images/Argo-C.png">
|
||||
<div class="layout-title">
|
||||
<span>@DisplayName</span>
|
||||
<div class="layout-user">
|
||||
<img class="layout-avatar" src="/images/Argo-C.png">
|
||||
<div class="layout-title">
|
||||
<span>@DisplayName</span>
|
||||
</div>
|
||||
<div class="layout-user-state"></div>
|
||||
</div>
|
||||
<div class="layout-user-state"></div>
|
||||
</div>
|
||||
</Side>
|
||||
<Main>
|
||||
@Body
|
||||
</Main>
|
||||
<Footer>
|
||||
<div class="flex-fill text-center text-dark">@Footer</div>
|
||||
</Footer>
|
||||
<NotAuthorized>
|
||||
<RedirectToLogin />
|
||||
</NotAuthorized>
|
||||
</Layout>
|
||||
</Side>
|
||||
<Main>
|
||||
@Body
|
||||
</Main>
|
||||
<Footer>
|
||||
<div class="flex-fill text-center text-dark">@Footer</div>
|
||||
</Footer>
|
||||
<NotAuthorized>
|
||||
<Redirect />
|
||||
</NotAuthorized>
|
||||
</Layout>
|
||||
}
|
|
@ -33,10 +33,6 @@ namespace BootstrapAdmin.Web.Shared
|
|||
[NotNull]
|
||||
private BootstrapAppContext? Context { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private NavigationManager? Navigation { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IBootstrapAdminService? SecurityService { get; set; }
|
||||
|
@ -47,30 +43,30 @@ namespace BootstrapAdmin.Web.Shared
|
|||
|
||||
private string? DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
MenuItems = NavigationsService.GetAllMenus("Admin").ToAdminMenus();
|
||||
|
||||
Title = DictsService.GetWebTitle();
|
||||
Footer = DictsService.GetWebFooter();
|
||||
}
|
||||
private bool Login { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// OnInitializedAsync 方法
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var userName = state.User.Identity?.Name;
|
||||
DisplayName = UsersService.GetDisplayName(userName);
|
||||
Context.UserName = userName;
|
||||
Context.DisplayName = DisplayName;
|
||||
|
||||
if (!string.IsNullOrEmpty(userName))
|
||||
{
|
||||
DisplayName = UsersService.GetDisplayName(userName);
|
||||
Context.UserName = userName;
|
||||
Context.DisplayName = DisplayName;
|
||||
|
||||
MenuItems = NavigationsService.GetAllMenus("Admin").ToAdminMenus();
|
||||
}
|
||||
|
||||
Title = DictsService.GetWebTitle();
|
||||
Footer = DictsService.GetWebFooter();
|
||||
|
||||
Login = true;
|
||||
}
|
||||
|
||||
private Task<bool> OnAuthorizing(string url) => SecurityService.AuhorizingNavigation(Context.UserName, url);
|
||||
|
|
Loading…
Reference in New Issue