From 7603a2d44d31c00070d03e661432d6dba77fa72d Mon Sep 17 00:00:00 2001 From: Argo-Cloud Date: Thu, 1 Apr 2021 10:57:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Step=20=E5=A2=9E=E5=8A=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InputNumber/BootstrapInputNumber.razor.cs | 106 +++++++++--------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs b/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs index febee26be..6fd2b7a04 100644 --- a/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs +++ b/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs @@ -7,7 +7,6 @@ using Microsoft.Extensions.Localization; using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; using System.Threading.Tasks; namespace BootstrapBlazor.Components @@ -100,7 +99,6 @@ namespace BootstrapBlazor.Components base.OnInitialized(); ParsingErrorMessage = Localizer[nameof(ParsingErrorMessage)]!; - Step ??= "1"; } /// @@ -133,7 +131,7 @@ namespace BootstrapBlazor.Components protected override string? FormatValueAsString(TValue? value) => Formatter != null ? Formatter.Invoke(value) : (!string.IsNullOrEmpty(FormatString) && value != null - ? Utility.Format((object)value, FormatString) + ? Utility.Format(value, FormatString) : value switch { null => null, @@ -152,32 +150,35 @@ namespace BootstrapBlazor.Components /// private void OnClickDec() { - if (!string.IsNullOrEmpty(Step)) + var val = CurrentValue; + switch (val) { - TValue val = CurrentValue; - switch (val) - { - case int @int: - val = (TValue)(object)(@int - int.Parse(Step)); - break; - case long @long: - val = (TValue)(object)(@long - long.Parse(Step)); - break; - case short @short: - val = (TValue)(object)(short)(@short - short.Parse(Step)); - break; - case float @float: - val = (TValue)(object)(@float - float.Parse(Step)); - break; - case double @double: - val = (TValue)(object)(@double - double.Parse(Step)); - break; - case decimal @decimal: - val = (TValue)(object)(@decimal - decimal.Parse(Step)); - break; - } - CurrentValue = SetMax(SetMin(val)); + case int @int: + Step ??= "1"; + val = (TValue)(object)(@int - int.Parse(Step)); + break; + case long @long: + Step ??= "1"; + val = (TValue)(object)(@long - long.Parse(Step)); + break; + case short @short: + Step ??= "1"; + val = (TValue)(object)(short)(@short - short.Parse(Step)); + break; + case float @float: + Step ??= "0.01"; + val = (TValue)(object)(@float - float.Parse(Step)); + break; + case double @double: + Step ??= "0.01"; + val = (TValue)(object)(@double - double.Parse(Step)); + break; + case decimal @decimal: + Step ??= "0.01"; + val = (TValue)(object)(@decimal - decimal.Parse(Step)); + break; } + CurrentValue = SetMax(SetMin(val)); } /// @@ -186,32 +187,35 @@ namespace BootstrapBlazor.Components /// private void OnClickInc() { - if (!string.IsNullOrEmpty(Step)) + var val = CurrentValue; + switch (val) { - TValue val = CurrentValue; - switch (val) - { - case int @int: - val = (TValue)(object)(@int + int.Parse(Step)); - break; - case long @long: - val = (TValue)(object)(@long + long.Parse(Step)); - break; - case short @short: - val = (TValue)(object)(short)(@short + short.Parse(Step)); - break; - case float @float: - val = (TValue)(object)(@float + float.Parse(Step)); - break; - case double @double: - val = (TValue)(object)(@double + double.Parse(Step)); - break; - case decimal @decimal: - val = (TValue)(object)(@decimal + decimal.Parse(Step)); - break; - } - CurrentValue = SetMax(SetMin(val)); + case int @int: + Step ??= "1"; + val = (TValue)(object)(@int + int.Parse(Step)); + break; + case long @long: + Step ??= "1"; + val = (TValue)(object)(@long + long.Parse(Step)); + break; + case short @short: + Step ??= "1"; + val = (TValue)(object)(short)(@short + short.Parse(Step)); + break; + case float @float: + Step ??= "0.01"; + val = (TValue)(object)(@float + float.Parse(Step)); + break; + case double @double: + Step ??= "0.01"; + val = (TValue)(object)(@double + double.Parse(Step)); + break; + case decimal @decimal: + Step ??= "0.01"; + val = (TValue)(object)(@decimal + decimal.Parse(Step)); + break; } + CurrentValue = SetMax(SetMin(val)); } /// -- Gitee