From a03053334d2900d092ab3bd16c0ed3d63bbb925a Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 16 Dec 2021 14:04:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs b/src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs index 1e40c0394..f1601f819 100644 --- a/src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs +++ b/src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs @@ -68,16 +68,16 @@ namespace BootstrapBlazor.Components private bool IsBoolean { get; set; } /// - /// 获得/设置 按钮颜色 + /// 获得/设置 按钮颜色 默认为 None 未设置 /// [Parameter] public Color Color { get; set; } /// - /// 获得/设置 Size 大小 + /// 获得/设置 Size 大小 默认为 None /// [Parameter] - public Size Size { get; set; } = Size.None; + public Size Size { get; set; } /// /// 获得/设置 是否显示 Checkbox 后置 label 文字 默认为 false -- Gitee From 12a638938361e82def4b31a2396f2a0b8c87d90c Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 16 Dec 2021 19:59:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20Layout=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E8=AE=A4=E8=AF=81=E5=9B=9E=E8=B0=83=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E9=85=8D=E5=90=88=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Layout/LayoutBase.cs | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Layout/LayoutBase.cs b/src/BootstrapBlazor/Components/Layout/LayoutBase.cs index 514da0f6f..56ec11f21 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.Routing; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -14,7 +15,7 @@ namespace BootstrapBlazor.Components /// /// Layout 组件基类 /// - public abstract class LayoutBase : BootstrapComponentBase + public abstract class LayoutBase : BootstrapComponentBase, IDisposable { /// /// @@ -167,6 +168,45 @@ namespace BootstrapBlazor.Components [Parameter] public string TabDefaultUrl { get; set; } = ""; + /// + /// 获得/设置 授权回调方法多用于权限控制 + /// + [Parameter] + public Func>? OnAuthorizing { get; set; } + + /// + /// 获得/设置 未授权导航地址 默认为 "/Account/Login" Cookie 模式登录页 + /// + [Parameter] + public string NotAuthorizeUrl { get; set; } = "/Account/Login"; + + [Inject] + [NotNull] + private NavigationManager? Navigation { get; set; } + + /// + /// OnInitializedAsync 方法 + /// + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + if (OnAuthorizing != null) + { + Navigation.LocationChanged += Navigation_LocationChanged; + } + } + + private async void Navigation_LocationChanged(object? sender, LocationChangedEventArgs e) + { + var auth = await OnAuthorizing!(e.Location); + if (!auth) + { + Navigation.NavigateTo(NotAuthorizeUrl, true); + } + } + /// /// 点击 收缩展开按钮时回调此方法 /// @@ -202,5 +242,29 @@ namespace BootstrapBlazor.Components await OnClickMenu(item); } }; + + /// + /// + /// + /// + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + if (OnAuthorizing != null) + { + Navigation.LocationChanged -= Navigation_LocationChanged; + } + } + } + + /// + /// + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } } } -- Gitee