From dd861c61a94963a95214d50e3b7475e1b84e6caf Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 20 May 2021 12:14:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Layout=20=E7=BB=84=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9D=83=E9=99=90=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Layout/Layout.razor | 71 ++++++++++--------- .../Components/Layout/Layout.razor.cs | 21 ++++++ .../Components/Layout/LayoutBase.cs | 7 ++ 3 files changed, 67 insertions(+), 32 deletions(-) diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor b/src/BootstrapBlazor/Components/Layout/Layout.razor index 85ea8ffed..107a9d4d3 100644 --- a/src/BootstrapBlazor/Components/Layout/Layout.razor +++ b/src/BootstrapBlazor/Components/Layout/Layout.razor @@ -2,38 +2,20 @@ @inherits LayoutBase -
- @if (Side == null) - { - @RenderHeader.Invoke(false) - @RenderMain - @if (ShowFooter) + @if (IsAuthenticated) + { +
+ @if (Side == null) { - @RenderFooter - } - } - else if (IsFullSide) - { - -
- @RenderHeader.Invoke(ShowCollapseBar) + @RenderHeader.Invoke(false) @RenderMain @if (ShowFooter) { @RenderFooter } -
- } - else - { - @RenderHeader.Invoke(ShowCollapseBar); -
+ } + else if (IsFullSide) + { - @RenderMain -
- @if (ShowFooter) +
+ @RenderHeader.Invoke(ShowCollapseBar) + @RenderMain + @if (ShowFooter) + { + @RenderFooter + } +
+ } + else { - @RenderFooter + @RenderHeader.Invoke(ShowCollapseBar); +
+ + @RenderMain +
+ @if (ShowFooter) + { + @RenderFooter + } } - } -
+
+ } + else + { + @Main + }
@code { diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs index 293224085..a0a49bcd4 100644 --- a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs +++ b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs @@ -18,6 +18,8 @@ namespace BootstrapBlazor.Components { private JSInterop? Interop { get; set; } + private bool IsAuthenticated { get; set; } + /// /// 获得 组件样式 /// @@ -93,6 +95,25 @@ namespace BootstrapBlazor.Components TooltipText ??= Localizer[nameof(TooltipText)]; } + /// + /// + /// + /// + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + + if (AuthenticationStateTask != null) + { + var state = await AuthenticationStateTask; + IsAuthenticated = state.User.Identity?.IsAuthenticated ?? false; + } + else + { + IsAuthenticated = true; + } + } + /// /// OnAfterRenderAsync 方法 /// diff --git a/src/BootstrapBlazor/Components/Layout/LayoutBase.cs b/src/BootstrapBlazor/Components/Layout/LayoutBase.cs index ddbf81a5f..f857356a3 100644 --- a/src/BootstrapBlazor/Components/Layout/LayoutBase.cs +++ b/src/BootstrapBlazor/Components/Layout/LayoutBase.cs @@ -3,6 +3,7 @@ // Website: https://www.blazor.zone or https://argozhang.github.io/ using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -148,6 +149,12 @@ namespace BootstrapBlazor.Components [Parameter] public Func? OnCollapsed { get; set; } + /// + /// 获得 登录授权信息 + /// + [CascadingParameter] + protected Task? AuthenticationStateTask { get; set; } + /// /// 点击 收缩展开按钮时回调此方法 /// -- Gitee