209209 </span >
210210 </div >
211211 <el-row :gutter =" 8" v-if =" form.fileList?.length" class =" mt-8" >
212- <template v-for =" (item , index ) in form . fileList " :key =" index " >
212+ <template v-for =" (item , index ) in sortedFileList " :key =" index " >
213213 <el-col :span =" 12" class =" mb-8" >
214214 <el-card
215215 shadow =" never"
242242 <el-button v-if =" item.canRetry" text @click =" uploadFile(item)" >
243243 <AppIcon iconName="app-refresh"></AppIcon >
244244 </el-button >
245- <el-button text @click =" deleteFile(index, item)" >
245+ <el-button text @click =" deleteFile(item)" >
246246 <AppIcon iconName="app-delete"></AppIcon >
247247 </el-button >
248248 </div >
@@ -317,13 +317,30 @@ const uploadingCount = computed(
317317const retryList = computed (() =>
318318 form .value .fileList .filter ((i : any ) => i .status === ' error' && i .canRetry ),
319319)
320+ const getFileStatusOrder = (item : any ) => {
321+ if (item .status === ' error' && item .canRetry ) return 0
322+ if (item .status === ' error' ) return 1
323+ if (item .status === ' uploading' ) return 2
324+ return 3
325+ }
326+ const sortedFileList = computed (() =>
327+ form .value .fileList
328+ .map ((item : any , index : number ) => ({ item , index }))
329+ .sort (
330+ (a : any , b : any ) =>
331+ getFileStatusOrder (a .item ) - getFileStatusOrder (b .item ) || a .index - b .index ,
332+ )
333+ .map (({ item }: any ) => item ),
334+ )
320335const retryAll = () => {
321336 retryList .value .forEach ((i : any ) => uploadFile (i ))
322337}
323-
338+ const filterSuccessFiles = (data : any ): any => {
339+ return data ?.filter ((f : any ) => f .status === ' success' ) || []
340+ }
324341watch (form .value , (value ) => {
325342 knowledge .saveDocumentsType (value .fileType )
326- knowledge .saveDocumentsFile (value .fileList )
343+ knowledge .saveDocumentsFile (filterSuccessFiles ( value .fileList ) )
327344})
328345
329346function downloadTemplate(type : string ) {
@@ -350,14 +367,17 @@ function radioChange() {
350367 form .value .fileList = []
351368}
352369
353- function deleteFile(index : number | string , item ? : any ) {
370+ function deleteFile(item : any ) {
354371 if (item ?.status === ' uploading' && typeof item .abort === ' function' ) {
355372 item .aborted = true
356373 item .abort ()
357374 } else if (item ?.status === ' success' && item ?.file_id ) {
358375 applicationApi .deleteFile (item .file_id )
359376 }
360- form .value .fileList .splice (index , 1 )
377+ const index = form .value .fileList .indexOf (item )
378+ if (index !== - 1 ) {
379+ form .value .fileList .splice (index , 1 )
380+ }
361381}
362382
363383// 上传on-change事件
@@ -370,14 +390,36 @@ const fileHandleChange = (file: any, fileList: UploadFiles) => {
370390 fileList .splice (index , 1 )
371391 }
372392 }
393+ if (form .value .fileList .length >= file_count_limit .value ) {
394+ onExceed ()
395+ removeCurrentFile ()
396+ return false
397+ }
398+ const item = reactive ({
399+ uid: file .uid ,
400+ name: file .name ,
401+ size: file .size ,
402+ file_id: ' ' ,
403+ source_file_id: ' ' ,
404+ percentage: 0 ,
405+ status: ' uploading' as ' uploading' | ' success' | ' error' ,
406+ errMsg: ' ' ,
407+ canRetry: false ,
408+ raw: file .raw ,
409+ abort: null as null | (() => void ),
410+ aborted: false ,
411+ })
373412 // 1、判断文件大小是否合法,文件限制不能大于100M
374413 const isLimit = file ?.size / 1024 / 1024 < file_size_limit .value
375414 if (! isLimit ) {
376- MsgError (t (' views.document.tip.fileLimitSizeTip1' ) + file_size_limit .value + ' MB' )
377- removeCurrentFile () // 移除当前超出大小的文件
415+ item .status = ' error'
416+ item .errMsg = t (' dynamicsForm.UploadInput.errorTip.sizeError' )
417+ // MsgError(t('views.document.tip.fileLimitSizeTip1') + file_size_limit.value + 'MB')
418+ // fileList.splice(-1, 1) //移除当前超出大小的文件
419+ form .value .fileList ?.push (item )
420+ removeCurrentFile ()
378421 return false
379422 }
380-
381423 if (! isRightType (file ?.name , form .value .fileType )) {
382424 if (file ?.name !== ' .DS_Store' ) {
383425 MsgError (t (' views.document.upload.errorMessage2' ))
@@ -391,20 +433,8 @@ const fileHandleChange = (file: any, fileList: UploadFiles) => {
391433 return false
392434 }
393435
394- const item = reactive ({
395- name: file .name ,
396- size: file .size ,
397- file_id: ' ' ,
398- source_file_id: ' ' ,
399- percentage: 0 ,
400- status: ' uploading' as ' uploading' | ' success' | ' error' ,
401- errMsg: ' ' ,
402- canRetry: false ,
403- raw: file .raw ,
404- abort: null as null | (() => void ),
405- aborted: false ,
406- })
407436 form .value .fileList .push (item )
437+ removeCurrentFile ()
408438 uploadFile (item )
409439}
410440
@@ -464,14 +494,6 @@ const handlePreview = (bool: boolean) => {
464494*/
465495function validate() {
466496 if (! FormRef .value ) return
467- if (uploadingCount .value ) {
468- MsgError (t (' dynamicsForm.UploadInput.uploading' ))
469- return false
470- }
471- if (errorCount .value ) {
472- MsgError (t (' dynamicsForm.UploadInput.failedStatus' , { count: errorCount .value }))
473- return false
474- }
475497 return FormRef .value .validate ((valid : any ) => {
476498 return valid
477499 })
0 commit comments