Skip to content

Commit 01ce5c9

Browse files
committed
refactor: 精简代码
1 parent 3a302ae commit 01ce5c9

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/BootstrapBlazor/Components/Upload/AvatarUpload.razor.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,6 @@ public partial class AvatarUpload<TValue>
8585
.AddClass(GetValidStatus(item))
8686
.Build();
8787

88-
private string? GetValidStatus(UploadFile? item = null)
89-
{
90-
if(item == null || IsDisabled || ValidateForm == null)
91-
{
92-
return null;
93-
}
94-
95-
var state = item.IsValid;
96-
return state.HasValue
97-
? state.Value ? "is-valid" : "is-invalid"
98-
: null;
99-
}
100-
10188
/// <summary>
10289
/// 获得/设置 预览框 Style 属性
10390
/// </summary>
@@ -136,7 +123,6 @@ protected override void OnParametersSet()
136123
// 头像上传时如果用户没有设置 OnChanged 回调,需要使用内置方法将文件头像转化未 Base64 格式用于预览
137124
OnChange ??= async item =>
138125
{
139-
item.ValidateId = $"{Id}_{item.GetHashCode()}";
140126
await item.RequestBase64ImageFileAsync();
141127
};
142128
}
@@ -151,4 +137,17 @@ protected override void OnParametersSet()
151137
}
152138

153139
private string? AddId => Files.Count == 0 ? $"{Id}_new" : null;
140+
141+
private string? GetValidStatus(UploadFile? item = null)
142+
{
143+
if (item == null || IsDisabled || ValidateForm == null)
144+
{
145+
return null;
146+
}
147+
148+
var state = item.IsValid;
149+
return state.HasValue
150+
? state.Value ? "is-valid" : "is-invalid"
151+
: null;
152+
}
154153
}

0 commit comments

Comments
 (0)