diff --git a/src/BootstrapBlazor.Shared/Samples/Captchas.razor.cs b/src/BootstrapBlazor.Shared/Samples/Captchas.razor.cs index ce5f3c146d920847c4fad8d48e28dced488abe03..cb8693772759b2e37ee04907219ee04144900d4d 100644 --- a/src/BootstrapBlazor.Shared/Samples/Captchas.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Captchas.razor.cs @@ -23,9 +23,7 @@ public sealed partial class Captchas /// public string ImagesName { get; set; } = "Pic.jpg"; - /// - /// - /// + [NotNull] private Captcha? Captcha { get; set; } /// @@ -42,7 +40,7 @@ public sealed partial class Captchas Task.Run(async () => { await Task.Delay(1000); - Captcha?.Reset(); + await Captcha.Reset(); }); } } @@ -68,78 +66,78 @@ public sealed partial class Captchas /// private IEnumerable GetAttributes() => new[] { - // TODO: 移动到数据库中 - new AttributeItem() { - Name = "ImagesPath", - Description = Localizer["ImagesPath"], - Type = "string", - ValueList = " — ", - DefaultValue = "images" - }, - new AttributeItem() { - Name = "ImagesName", - Description = Localizer["ImagesName"], - Type = "string", - ValueList = " — ", - DefaultValue = "Pic.jpg" - }, - new AttributeItem() { - Name = "HeaderText", - Description = Localizer["HeaderText"], - Type = "string", - ValueList = " — ", - DefaultValue = Localizer["HeaderTextDefaultValue"] - }, - new AttributeItem() { - Name = "BarText", - Description = Localizer["BarText"], - Type = "string", - ValueList = " — ", - DefaultValue = Localizer["BarTextDefaultValue"] - }, - new AttributeItem() { - Name = "FailedText", - Description = Localizer["FailedText"], - Type = "string", - ValueList = " — ", - DefaultValue = Localizer["FailedTextDefaultValue"] - }, - new AttributeItem() { - Name = "LoadText", - Description = Localizer["LoadText"], - Type = "string", - ValueList = " — ", - DefaultValue = Localizer["LoadTextDefaultValue"] - }, - new AttributeItem() { - Name = "TryText", - Description = Localizer["TryText"], - Type = "string", - ValueList = " — ", - DefaultValue = Localizer["TryTextDefaultValue"] - }, - new AttributeItem() { - Name = "Offset", - Description = Localizer["Offset"], - Type = "int", - ValueList = " — ", - DefaultValue = "5" - }, - new AttributeItem() { - Name = "Width", - Description = Localizer["Width"], - Type = "int", - ValueList = " — ", - DefaultValue = "280" - }, - new AttributeItem() { - Name = "Height", - Description = Localizer["Height"], - Type = "int", - ValueList = " — ", - DefaultValue = "155" - } - }; + // TODO: 移动到数据库中 + new AttributeItem() { + Name = "ImagesPath", + Description = Localizer["ImagesPath"], + Type = "string", + ValueList = " — ", + DefaultValue = "images" + }, + new AttributeItem() { + Name = "ImagesName", + Description = Localizer["ImagesName"], + Type = "string", + ValueList = " — ", + DefaultValue = "Pic.jpg" + }, + new AttributeItem() { + Name = "HeaderText", + Description = Localizer["HeaderText"], + Type = "string", + ValueList = " — ", + DefaultValue = Localizer["HeaderTextDefaultValue"] + }, + new AttributeItem() { + Name = "BarText", + Description = Localizer["BarText"], + Type = "string", + ValueList = " — ", + DefaultValue = Localizer["BarTextDefaultValue"] + }, + new AttributeItem() { + Name = "FailedText", + Description = Localizer["FailedText"], + Type = "string", + ValueList = " — ", + DefaultValue = Localizer["FailedTextDefaultValue"] + }, + new AttributeItem() { + Name = "LoadText", + Description = Localizer["LoadText"], + Type = "string", + ValueList = " — ", + DefaultValue = Localizer["LoadTextDefaultValue"] + }, + new AttributeItem() { + Name = "TryText", + Description = Localizer["TryText"], + Type = "string", + ValueList = " — ", + DefaultValue = Localizer["TryTextDefaultValue"] + }, + new AttributeItem() { + Name = "Offset", + Description = Localizer["Offset"], + Type = "int", + ValueList = " — ", + DefaultValue = "5" + }, + new AttributeItem() { + Name = "Width", + Description = Localizer["Width"], + Type = "int", + ValueList = " — ", + DefaultValue = "280" + }, + new AttributeItem() { + Name = "Height", + Description = Localizer["Height"], + Type = "int", + ValueList = " — ", + DefaultValue = "155" + } + }; /// /// 获得事件方法 @@ -147,13 +145,13 @@ public sealed partial class Captchas /// private IEnumerable GetEvents() => new[] { - new EventItem() - { - Name = "OnValid", - Description = Localizer["OnValid"], - Type ="Action" - } - }; + new EventItem() + { + Name = "OnValid", + Description = Localizer["OnValid"], + Type ="Action" + } + }; /// /// 获得事件方法 @@ -161,12 +159,12 @@ public sealed partial class Captchas /// private IEnumerable GetMethods() => new[] { - new MethodItem() - { - Name = "GetImageName", - Description = Localizer["GetImageName"], - Parameters =" — ", - ReturnValue = "string" - } - }; + new MethodItem() + { + Name = "GetImageName", + Description = Localizer["GetImageName"], + Parameters =" — ", + ReturnValue = "string" + } + }; } diff --git a/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs b/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs index 4c11036366e4e25ef8d90617436b88b7f29ac119..876c678336d7595c79470231d92f945654c1f771 100644 --- a/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs +++ b/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs @@ -109,6 +109,18 @@ public partial class Captcha : IDisposable [Parameter] public int Width { get; set; } = 280; + /// + /// 获得/设置 拼图边长 + /// + [Parameter] + public int SideLength { get; set; } = 42; + + /// + /// 获得/设置 拼图直径 + /// + [Parameter] + public int Diameter { get; set; } = 9; + /// /// 获得/设置 图片高度 /// @@ -134,23 +146,21 @@ public partial class Captcha : IDisposable } /// - /// OnAfterRender 方法 + /// OnAfterRenderAsync 方法 /// /// - protected override void OnAfterRender(bool firstRender) + protected override async Task OnAfterRenderAsync(bool firstRender) { - base.OnAfterRender(firstRender); - if (firstRender) { - Reset(); + await Reset(); } } /// /// 点击刷新按钮时回调此方法 /// - protected void OnClickRefresh() => Reset(); + protected Task OnClickRefresh() => Reset(); /// /// 验证方差方法 @@ -172,7 +182,9 @@ public partial class Captcha : IDisposable var option = new CaptchaOption() { Width = Width, - Height = Height + Height = Height, + SideLength = SideLength, + Diameter = Diameter }; option.BarWidth = option.SideLength + option.Diameter * 2 + 6; // 滑块实际边长 var start = option.BarWidth + 10; @@ -240,7 +252,7 @@ public partial class Captcha : IDisposable /// /// 重置组件方法 /// - public void Reset() + public async Task Reset() { var option = GetCaptchaOption(); if (Interop == null) @@ -248,6 +260,6 @@ public partial class Captcha : IDisposable Interop = new JSInterop(JSRuntime); } - _ = Interop.InvokeVoidAsync(this, CaptchaElement, "captcha", nameof(Verify), option); + await Interop.InvokeVoidAsync(this, CaptchaElement, "captcha", nameof(Verify), option); } } diff --git a/src/BootstrapBlazor/Components/Dialog/ClosableDialogBase.cs b/src/BootstrapBlazor/Components/Dialog/ClosableDialogBase.cs deleted file mode 100644 index 21bf4dfc78bb75f4a04702346d9f7561c7157528..0000000000000000000000000000000000000000 --- a/src/BootstrapBlazor/Components/Dialog/ClosableDialogBase.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -// Website: https://www.blazor.zone or https://argozhang.github.io/ - -using Microsoft.AspNetCore.Components; - -namespace BootstrapBlazor.Components; - -/// -/// 可关闭弹窗基类 -/// -public class ClosableDialogBase : BootstrapComponentBase -{ - /// - /// 关闭弹窗回调委托 - /// - [Parameter] - [NotNull] - public Func? OnClose { get; set; } - - /// - /// 保存按钮回调委托 - /// - [Parameter] - [NotNull] - public Func? OnSave { get; set; } -} diff --git a/src/BootstrapBlazor/Components/FAIcons/IconDialog.razor b/src/BootstrapBlazor/Components/FAIcons/IconDialog.razor index 0704382156351bbf861275a07bf3ad8e342847f1..4a6296f439f2cf2ef559c5e019d7180a0bcdfc54 100644 --- a/src/BootstrapBlazor/Components/FAIcons/IconDialog.razor +++ b/src/BootstrapBlazor/Components/FAIcons/IconDialog.razor @@ -1,5 +1,5 @@ @namespace BootstrapBlazor.Components -@inherits ClosableDialogBase +@inherits BootstrapComponentBase
diff --git a/test/UnitTest/Components/CaptchaTest.cs b/test/UnitTest/Components/CaptchaTest.cs index 6793a38eaa68a63fb01ff0cc3a5b1afb085f9a47..c2725a46d98d461ce031ddca997c7e71b281bdeb 100644 --- a/test/UnitTest/Components/CaptchaTest.cs +++ b/test/UnitTest/Components/CaptchaTest.cs @@ -11,6 +11,8 @@ public class CaptchaTest : BootstrapBlazorTestBase var verify = false; var cut = Context.RenderComponent(pb => { + pb.Add(a => a.SideLength, 42); + pb.Add(a => a.Diameter, 9); pb.Add(a => a.Width, 280); pb.Add(a => a.Height, 150); pb.Add(a => a.Offset, 1000); @@ -44,4 +46,16 @@ public class CaptchaTest : BootstrapBlazorTestBase }); await cut.InvokeAsync(() => cut.Find(".captcha-refresh").Click()); } + + [Fact] + public void Option_Ok() + { + var option = new CaptchaOption() + { + OffsetY = 100, + ImageUrl = "test.jpg" + }; + Assert.Equal(100, option.OffsetY); + Assert.Equal("test.jpg", option.ImageUrl); + } }