From 9f95fcdd0e3877fe875631a66067247a5d167a8b Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 9 Apr 2022 10:06:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?test:=20=E7=A7=BB=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=20ClosableDialogBase=20=E5=9F=BA?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Dialog/ClosableDialogBase.cs | 27 ------------------- .../Components/FAIcons/IconDialog.razor | 2 +- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 src/BootstrapBlazor/Components/Dialog/ClosableDialogBase.cs diff --git a/src/BootstrapBlazor/Components/Dialog/ClosableDialogBase.cs b/src/BootstrapBlazor/Components/Dialog/ClosableDialogBase.cs deleted file mode 100644 index 21bf4dfc7..000000000 --- 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 070438215..4a6296f43 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
-- Gitee From d1d5f7bc64af3d948dfce9e8bbdab381e55b40a5 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 9 Apr 2022 10:39:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=E5=BE=AE=E8=B0=83=20Captcha=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Samples/Captchas.razor.cs | 180 +++++++++--------- .../Components/Captcha/Captcha.razor.cs | 30 ++- 2 files changed, 110 insertions(+), 100 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Samples/Captchas.razor.cs b/src/BootstrapBlazor.Shared/Samples/Captchas.razor.cs index ce5f3c146..cb8693772 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 4c1103636..876c67833 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); } } -- Gitee From f78824907cd679740ddebe0e3bedfcfa52ff6c4d Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 9 Apr 2022 10:45:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=E8=A1=A5=E5=85=85=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/CaptchaTest.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/UnitTest/Components/CaptchaTest.cs b/test/UnitTest/Components/CaptchaTest.cs index 6793a38ea..c2725a46d 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); + } } -- Gitee