diff --git a/src/BootstrapBlazor.Server/appsettings.json b/src/BootstrapBlazor.Server/appsettings.json index 11a74c75313..9d1a22194c2 100644 --- a/src/BootstrapBlazor.Server/appsettings.json +++ b/src/BootstrapBlazor.Server/appsettings.json @@ -30,7 +30,15 @@ "TableSettings": { "CheckboxColumnWidth": 36 }, - "IgnoreLocalizerMissing": true + "IgnoreLocalizerMissing": true, + "StepSettings": { + "Short": 1, + "Int": 1, + "Long": 1, + "Float": "0.1", + "Double": "0.01", + "Decimal": "0.01" + } }, "Cache-Control": { "Files": [ ".png", ".gif", ".jpg", ".jpeg", ".svg" ], diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index a424b1e94ed..7c195ff428f 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 7.11.1-beta06 + 7.11.1-beta07 diff --git a/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs b/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs index 63051f65504..597010a993f 100644 --- a/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs +++ b/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs @@ -2,6 +2,7 @@ // 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 BootstrapBlazor.Extensions; using Microsoft.Extensions.Localization; using System.Globalization; @@ -90,6 +91,10 @@ public partial class BootstrapInputNumber [NotNull] private IIconTheme? IconTheme { get; set; } + [Inject] + [NotNull] + private IOptions? StepOption { get; set; } + /// /// /// @@ -155,6 +160,8 @@ private void SetStep() StepString = Step; break; } + + StepString ??= StepOption.Value.GetStep(); } /// diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs new file mode 100644 index 00000000000..96be7275442 --- /dev/null +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs @@ -0,0 +1,31 @@ +// 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/ + +namespace BootstrapBlazor.Extensions; + +/// +/// BootstrapBlazorOptions 配置类扩展方法 +/// +public static class BootstrapBlazorOptionsExtensions +{ + /// + /// 获取步长泛型方法 + /// + /// + /// + /// + public static string? GetStep(this BootstrapBlazorOptions options) => options.GetStep(typeof(TType)); + + /// + /// 获取步长方法 + /// + /// 配置实体类实例 + /// 数据类型 + /// + public static string? GetStep(this BootstrapBlazorOptions options, Type type) + { + var t = Nullable.GetUnderlyingType(type) ?? type; + return options.StepSettings.GetStep(t); + } +} diff --git a/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs b/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs index 16d6c139d78..a3046226f70 100644 --- a/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs +++ b/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs @@ -69,6 +69,11 @@ public class BootstrapBlazorOptions /// public TableSettings TableSettings { get; set; } = new(); + /// + /// 获得/设置 Step 配置实例 + /// + public StepSettings StepSettings { get; set; } = new(); + /// /// 获得/设置 是否禁用表单内回车自动提交功能 默认 null 未设置 /// diff --git a/src/BootstrapBlazor/Options/StepSettings.cs b/src/BootstrapBlazor/Options/StepSettings.cs new file mode 100644 index 00000000000..5e15a91645e --- /dev/null +++ b/src/BootstrapBlazor/Options/StepSettings.cs @@ -0,0 +1,76 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// StepSettings 配置类 +/// +public class StepSettings +{ + /// + /// 获得/设置 int 数据类型步长 默认 null 未设置 + /// + public int? Int { get; set; } + + /// + /// 获得/设置 long 数据类型步长 默认 null 未设置 + /// + public int? Long { get; set; } + + /// + /// 获得/设置 short 数据类型步长 默认 null 未设置 + /// + public int? Short { get; set; } + + /// + /// 获得/设置 float 数据类型步长 默认 null 未设置 + /// + public float? Float { get; set; } + + /// + /// 获得/设置 double 数据类型步长 默认 null 未设置 + /// + public double? Double { get; set; } + + /// + /// 获得/设置 decimal 数据类型步长 默认 null 未设置 + /// + public decimal? Decimal { get; set; } + + /// + /// 获得步长字符串 + /// + /// + /// + public string? GetStep(Type type) + { + string? ret = null; + if (type == typeof(int)) + { + ret = Int?.ToString(); + } + if (type == typeof(long)) + { + ret = Long?.ToString(); + } + if (type == typeof(short)) + { + ret = Short?.ToString(); + } + if (type == typeof(float)) + { + ret = Float?.ToString(); + } + if (type == typeof(double)) + { + ret = Double?.ToString(); + } + if (type == typeof(decimal)) + { + ret = Decimal?.ToString(); + } + return ret; + } +} diff --git a/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs b/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs index c2e25177bd6..4d16821166f 100644 --- a/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs +++ b/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs @@ -2,6 +2,8 @@ // 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 BootstrapBlazor.Extensions; + namespace UnitTest.Options; public class BootstrapBlazorOptionsTest @@ -39,4 +41,35 @@ public void Options_IgnoreLocalizerMissing_Null() options.IgnoreLocalizerMissing = true; Assert.True(options.IgnoreLocalizerMissing.Value); } + + [Fact] + public void Options_StepSettings() + { + var options = new BootstrapBlazorOptions(); + Assert.NotNull(options.StepSettings); + + options.StepSettings = new(); + + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + + options.StepSettings.Short = 1; + options.StepSettings.Int = 2; + options.StepSettings.Long = 3; + options.StepSettings.Float = 0.1f; + options.StepSettings.Double = 0.01d; + options.StepSettings.Decimal = 0.001M; + + Assert.Equal("1", options.GetStep()); + Assert.Equal("2", options.GetStep()); + Assert.Equal("3", options.GetStep(typeof(long?))); + + Assert.Equal("0.1", options.GetStep()); + Assert.Equal("0.01", options.GetStep()); + Assert.Equal("0.001", options.GetStep()); + } }