Skip to content

Commit 3256af8

Browse files
committed
refactor: 重构代码精简代码
1 parent f8c51e1 commit 3256af8

File tree

9 files changed

+16
-28
lines changed

9 files changed

+16
-28
lines changed

src/BootstrapBlazor/Components/Button/Button.razor

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
@inherits ButtonBase
33

44
<button @attributes="@AdditionalAttributes" type="@ButtonType.ToDescriptionString()" @onclick="@OnClickButton" id="@Id" class="@ClassName" disabled="@Disabled" role="button" data-bs-placement="@PlacementString" data-bs-trigger="@TriggerString" aria-disabled="@DisabledString" tabindex="@Tab" @onclick:stopPropagation="@StopPropagation" @ref="ButtonElement">
5-
@if (!string.IsNullOrEmpty(ButtonIcon))
5+
@if(IsAsyncLoading)
66
{
7-
<i class="@ButtonIcon"></i>
7+
<i class="@LoadingIcon"></i>
8+
}
9+
else if (!string.IsNullOrEmpty(Icon))
10+
{
11+
<i class="@Icon"></i>
812
}
913
@if (!string.IsNullOrEmpty(Text))
1014
{

src/BootstrapBlazor/Components/Button/Button.razor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ protected virtual async Task OnClickButton()
4949
if (IsAsync && ButtonType == ButtonType.Button)
5050
{
5151
IsAsyncLoading = true;
52-
ButtonIcon = LoadingIcon;
5352
IsDisabled = true;
5453
}
5554

@@ -65,7 +64,6 @@ protected virtual async Task OnClickButton()
6564
// 恢复按钮
6665
if (IsAsync && ButtonType == ButtonType.Button)
6766
{
68-
ButtonIcon = Icon;
6967
IsDisabled = IsKeepDisabled;
7068
IsAsyncLoading = false;
7169
}

src/BootstrapBlazor/Components/Button/ButtonBase.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public abstract class ButtonBase : TooltipWrapperBase
4242
/// </summary>
4343
protected string? Tab => IsDisabled ? "-1" : null;
4444

45-
/// <summary>
46-
/// 获得/设置 实际按钮渲染图标
47-
/// </summary>
48-
protected string? ButtonIcon { get; set; }
49-
5045
/// <summary>
5146
/// 获得/设置 按钮风格枚举
5247
/// </summary>
@@ -173,8 +168,6 @@ protected override void OnInitialized()
173168
{
174169
base.OnInitialized();
175170

176-
ButtonIcon = Icon;
177-
178171
if (IsAsync && ValidateForm != null)
179172
{
180173
// 开启异步操作时与 ValidateForm 联动
@@ -191,11 +184,6 @@ protected override void OnParametersSet()
191184

192185
LoadingIcon ??= IconTheme.GetIconByKey(ComponentIcons.ButtonLoadingIcon);
193186

194-
if (!IsAsyncLoading)
195-
{
196-
ButtonIcon = Icon;
197-
}
198-
199187
if (Tooltip != null && !string.IsNullOrEmpty(TooltipText))
200188
{
201189
Tooltip.SetParameters(TooltipText, TooltipPlacement, TooltipTrigger);
@@ -260,7 +248,6 @@ public void SetDisable(bool disable)
260248
internal void TriggerAsync(bool loading)
261249
{
262250
IsAsyncLoading = loading;
263-
ButtonIcon = loading ? LoadingIcon : Icon;
264251
SetDisable(loading);
265252
}
266253

src/BootstrapBlazor/Components/Button/CountButton.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ public class CountButton : Button
3434
protected override async Task OnClickButton()
3535
{
3636
IsAsyncLoading = true;
37-
ButtonIcon = LoadingIcon;
3837
IsDisabled = true;
3938

4039
await Task.Run(() => InvokeAsync(HandlerClick));
4140
await UpdateCount();
4241

4342
IsDisabled = false;
44-
ButtonIcon = Icon;
4543
IsAsyncLoading = false;
4644
}
4745

@@ -65,7 +63,6 @@ private async Task UpdateCount()
6563
{
6664
var count = Count;
6765
var text = Text;
68-
ButtonIcon = null;
6966
while (count > 0)
7067
{
7168
Text = GetCountText(count--, text);

src/BootstrapBlazor/Components/Button/ExportPdfButton.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ protected override void OnParametersSet()
8383
base.OnParametersSet();
8484

8585
Icon ??= IconTheme.GetIconByKey(ComponentIcons.TableExportPdfIcon);
86-
ButtonIcon = Icon;
8786
}
8887

8988
/// <summary>

src/BootstrapBlazor/Components/Button/PopConfirmButton.razor

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ else
1717
@<DynamicElement TagName="@TagName" OnClick="Show" id="@Id"
1818
class="@ClassString" role="dialog" tabindex="@Tab" data-bb-confirm="@ConfirmString"
1919
data-bs-custom-class="@CustomClassString" data-bs-trigger="@TriggerString" data-bs-placement="@PlacementString">
20-
@if (!string.IsNullOrEmpty(ButtonIcon))
20+
@if(IsAsyncLoading)
2121
{
22-
<i class="@ButtonIcon"></i>
22+
<i class="@LoadingIcon"></i>
23+
}
24+
else if (!string.IsNullOrEmpty(Icon))
25+
{
26+
<i class="@Icon"></i>
2327
}
2428
@if (!string.IsNullOrEmpty(Text))
2529
{

src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private async Task OnClickConfirm()
9595
if (IsAsync)
9696
{
9797
IsDisabled = true;
98-
ButtonIcon = LoadingIcon;
98+
IsAsyncLoading = true;
9999
StateHasChanged();
100100
await Task.Run(() => InvokeAsync(OnConfirm));
101101

@@ -106,7 +106,7 @@ private async Task OnClickConfirm()
106106
else
107107
{
108108
IsDisabled = false;
109-
ButtonIcon = Icon;
109+
IsAsyncLoading = false;
110110
StateHasChanged();
111111
}
112112
}

src/BootstrapBlazor/Components/Print/PrintButton.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
@attribute [BootstrapModuleAutoLoader("Print/PrintButton.razor.js")]
44

55
<a @attributes="@AdditionalAttributes" id="@Id" href="@PreviewUrl" class="@ClassName" disabled="@Disabled" role="button" aria-disabled="@DisabledString" tabindex="@Tab">
6-
@if (!string.IsNullOrEmpty(ButtonIcon))
6+
@if (!string.IsNullOrEmpty(Icon))
77
{
8-
<i class="@ButtonIcon"></i>
8+
<i class="@Icon"></i>
99
}
1010
@if (!string.IsNullOrEmpty(Text))
1111
{

src/BootstrapBlazor/Components/Print/PrintButton.razor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ protected override void OnParametersSet()
4040
base.OnParametersSet();
4141

4242
Icon ??= IconTheme.GetIconByKey(ComponentIcons.PrintButtonIcon);
43-
ButtonIcon = Icon;
4443
}
4544
}

0 commit comments

Comments
 (0)