From efa4320f70bb07bc45f2eee6916dce009a715c0a Mon Sep 17 00:00:00 2001 From: capdiem Date: Tue, 2 Jul 2024 09:39:42 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=95=20feat(PermissionView):=20add=20Fa?= =?UTF-8?q?llbackContent=20to=20PermissionView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/PermissionView/PermissionView.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Masa.Blazor/Components/PermissionView/PermissionView.cs b/src/Masa.Blazor/Components/PermissionView/PermissionView.cs index 85c91b1d12..0f7b341710 100644 --- a/src/Masa.Blazor/Components/PermissionView/PermissionView.cs +++ b/src/Masa.Blazor/Components/PermissionView/PermissionView.cs @@ -14,6 +14,9 @@ public class PermissionView : ComponentBase [Parameter] public RenderFragment? ChildContent { get; set; } + [Parameter] + public RenderFragment? FallbackContent { get; set; } + [Parameter, EditorRequired] public string Code { get; set; } = null!; @@ -37,13 +40,11 @@ protected override async Task OnInitializedAsync() protected override void BuildRenderTree(RenderTreeBuilder builder) { - if (User == null || Validator == null) + if (User == null || Validator == null || !Validator.Validate(Code, User)) { - return; + builder.AddContent(0, FallbackContent); } - - var valid = Validator.Validate(Code, User); - if (valid) + else { builder.AddContent(0, ChildContent); }