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