File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
src/BootstrapBlazor/Components/Upload Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -143,8 +143,20 @@ protected override void OnParametersSet()
143143 /// <returns></returns>
144144 protected async Task OnFileChange ( InputFileChangeEventArgs args )
145145 {
146- var fileCount = MaxFileCount ?? 0 ;
147- fileCount = Math . Max ( fileCount , args . FileCount ) ;
146+ var fileCount = args . FileCount ;
147+ if ( MaxFileCount . HasValue )
148+ {
149+ fileCount = MaxFileCount . Value ;
150+ }
151+
152+ // 计算剩余可上传数量
153+ fileCount = fileCount - Files . Count ;
154+ if ( fileCount <= 0 )
155+ {
156+ // 如果剩余可上传数量小于等于 0 则不允许继续上传
157+ return ;
158+ }
159+
148160 var items = args . GetMultipleFiles ( args . FileCount ) . Take ( fileCount ) . Select ( f =>
149161 {
150162 var file = new UploadFile ( )
Original file line number Diff line number Diff line change @@ -190,6 +190,23 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
190190 // 重置后不应该包含新上传的文件
191191 await cut . InvokeAsync ( ( ) => cut . Instance . Reset ( ) ) ;
192192 Assert . DoesNotContain ( "test3.png;test4.png" , cut . Markup ) ;
193+
194+ cut . SetParametersAndRender ( pb =>
195+ {
196+ pb . Add ( a => a . DefaultFileList ,
197+ [
198+ new UploadFile ( ) { FileName = "test5.png" } ,
199+ new UploadFile ( ) { FileName = "test6.png" }
200+ ] ) ;
201+ pb . Add ( a => a . Value ,
202+ [
203+ new MockBrowserFile ( "test5.png" ) ,
204+ new MockBrowserFile ( "test6.png" )
205+ ] ) ;
206+ } ) ;
207+ Assert . Contains ( "test5.png;test6.png" , cut . Markup ) ;
208+ await cut . InvokeAsync ( ( ) => cut . Instance . Reset ( ) ) ;
209+ Assert . DoesNotContain ( "test5.png;test6.png" , cut . Markup ) ;
193210 }
194211
195212 [ Fact ]
@@ -233,7 +250,7 @@ public async Task MaxFileCount_Ok()
233250 var cut = Context . RenderComponent < InputUpload < string > > ( pb =>
234251 {
235252 pb . Add ( a => a . IsMultiple , true ) ;
236- pb . Add ( a => a . MaxFileCount , 4 ) ;
253+ pb . Add ( a => a . MaxFileCount , 2 ) ;
237254 } ) ;
238255
239256 var input = cut . FindComponent < InputFile > ( ) ;
You can’t perform that action at this time.
0 commit comments