File tree Expand file tree Collapse file tree 9 files changed +32
-17
lines changed
src/BootstrapBlazor/Components/Upload Expand file tree Collapse file tree 9 files changed +32
-17
lines changed Original file line number Diff line number Diff line change 88}
99<div @attributes =" @AdditionalAttributes" class =" @ClassString" id =" @Id" >
1010 <div class =" upload-body is-avatar" >
11- @if (IsUploadButtonAtFirst && CheckCanUpload ())
11+ @if (IsUploadButtonAtFirst && ShowAddButton ())
1212 {
1313 @RenderAdd
1414 }
3939 }
4040 </div >
4141 }
42- @if (! IsUploadButtonAtFirst && CheckCanUpload ())
42+ @if (! IsUploadButtonAtFirst && ShowAddButton ())
4343 {
4444 @RenderAdd
4545 }
Original file line number Diff line number Diff line change @@ -96,7 +96,12 @@ public partial class AvatarUpload<TValue>
9696 return null ;
9797 }
9898
99- var state = item ? . IsValid ?? IsValid ;
99+ if ( item == null )
100+ {
101+ return null ;
102+ }
103+
104+ var state = item . IsValid ?? IsValid ;
100105 if ( state == null )
101106 {
102107 return null ;
Original file line number Diff line number Diff line change 77 <BootstrapLabel required =" @Required" ShowLabelTooltip =" ShowLabelTooltip" Value =" @DisplayText" />
88}
99<div @attributes =" @AdditionalAttributes" class =" @ClassString" id =" @Id" >
10- <Button class =" @BrowserButtonClassString" IsDisabled =" @(!CheckCanUpload() )" Size =" Size" Icon =" @BrowserButtonIcon" Text =" @BrowserButtonText" Color =" @BrowserButtonColor" >
10+ <Button class =" @BrowserButtonClassString" IsDisabled =" @CheckStatus( )" Size =" Size" Icon =" @BrowserButtonIcon" Text =" @BrowserButtonText" Color =" @BrowserButtonColor" >
1111 @ChildContent
1212 </Button >
1313 @if (ShowUploadFileList )
Original file line number Diff line number Diff line change @@ -208,4 +208,6 @@ protected override void OnParametersSet()
208208 BrowserButtonText ??= Localizer [ nameof ( BrowserButtonText ) ] ;
209209 BrowserButtonIcon ??= IconTheme . GetIconByKey ( ComponentIcons . ButtonUploadBrowserButtonIcon ) ;
210210 }
211+
212+ private bool CheckStatus ( ) => IsDisabled || CanUpload ( ) == false ;
211213}
Original file line number Diff line number Diff line change 88}
99<div @attributes =" @AdditionalAttributes" class =" @ClassString" id =" @Id" data-bb-previewer-id =" @PreviewerId" >
1010 <div class =" @BodyClassString" >
11- @if (IsUploadButtonAtFirst && CheckCanUpload ())
11+ @if (IsUploadButtonAtFirst && ShowAddButton ())
1212 {
1313 @RenderAdd
1414 }
7070 </span >
7171 </div >
7272 }
73- @if (! IsUploadButtonAtFirst && CheckCanUpload ())
73+ @if (! IsUploadButtonAtFirst && ShowAddButton ())
7474 {
7575 @RenderAdd
7676 }
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public partial class CardUpload<TValue>
1919 . AddClass ( "is-invalid" , item . Code != 0 )
2020 . Build ( ) ;
2121 private string ? ItemClassString => CssBuilder . Default ( "upload-item" )
22- . AddClass ( "disabled" , CheckCanUpload ( ) == false )
22+ . AddClass ( "disabled" , CanUpload ( ) == false )
2323 . Build ( ) ;
2424
2525 private string ? BodyClassString => CssBuilder . Default ( "upload-body is-card" )
Original file line number Diff line number Diff line change @@ -204,16 +204,16 @@ public partial class DropUpload
204204 private IStringLocalizer < UploadBase < string > > ? Localizer { get ; set ; }
205205
206206 private string ? ClassString => CssBuilder . Default ( "upload is-drop" )
207- . AddClass ( "disabled" , CheckCanUpload ( ) == false )
207+ . AddClass ( "disabled" , CanUpload ( ) == false )
208208 . AddClassFromAttributes ( AdditionalAttributes )
209209 . Build ( ) ;
210210
211211 private string ? BodyClassString => CssBuilder . Default ( "upload-drop-body" )
212- . AddClass ( "btn-browser" , CheckCanUpload ( ) )
212+ . AddClass ( "btn-browser" , CanUpload ( ) )
213213 . Build ( ) ;
214214
215215 private string ? TextClassString => CssBuilder . Default ( "upload-drop-text" )
216- . AddClass ( "text-muted" , CheckCanUpload ( ) == false )
216+ . AddClass ( "text-muted" , CanUpload ( ) == false )
217217 . Build ( ) ;
218218
219219 /// <summary>
Original file line number Diff line number Diff line change @@ -260,13 +260,8 @@ protected List<UploadFile> GetUploadFiles()
260260 /// <para>Check whether can upload file.</para>
261261 /// </summary>
262262 /// <returns></returns>
263- protected bool CheckCanUpload ( )
263+ protected bool CanUpload ( )
264264 {
265- if ( IsDisabled )
266- {
267- return false ;
268- }
269-
270265 // 允许多上传
271266 if ( IsMultiple )
272267 {
@@ -277,6 +272,20 @@ protected bool CheckCanUpload()
277272 return Files . Count == 0 ;
278273 }
279274
275+ /// <summary>
276+ /// 判断是否显示新建按钮
277+ /// </summary>
278+ /// <returns></returns>
279+ protected bool ShowAddButton ( )
280+ {
281+ if ( IsDisabled )
282+ {
283+ return Files . Count == 0 ;
284+ }
285+
286+ return CanUpload ( ) ;
287+ }
288+
280289 /// <summary>
281290 /// 清空上传列表方法
282291 /// <para>Clear the upload files collection.</para>
Original file line number Diff line number Diff line change 44// Maintainer: Argo Zhang([email protected] ) Website: https://www.blazor.zone 55
66using Microsoft . AspNetCore . Components . Forms ;
7- using System . ComponentModel . DataAnnotations ;
87
98namespace UnitTest . Components ;
109
You can’t perform that action at this time.
0 commit comments