1
0
Эх сурвалжийг харах

chore: upload customRequest event optional

pointhalo 2 жил өмнө
parent
commit
6c97302ae2

+ 8 - 8
packages/semi-foundation/upload/foundation.ts

@@ -322,7 +322,7 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
 
     // 插入多个文件到指定位置
     // Insert files to the specified location
-    insertFileToList(files: Array<CustomFile>, index:number): void {
+    insertFileToList(files: Array<CustomFile>, index: number): void {
         const { limit, transformFile, accept, uploadTrigger } = this.getProps();
         const { fileList } = this.getStates();
 
@@ -533,9 +533,9 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
                 data,
                 file,
                 fileInstance,
-                onProgress: (e: ProgressEvent) => this.handleProgress({ e, fileInstance }),
-                onError: (userXhr: XMLHttpRequest, e: ProgressEvent) => this.handleError({ e, xhr: userXhr, fileInstance }),
-                onSuccess: (response: any, e: ProgressEvent) => this.handleSuccess({ response, fileInstance, e, isCustomRequest: true }),
+                onProgress: (e?: ProgressEvent) => this.handleProgress({ e, fileInstance }),
+                onError: (userXhr: XMLHttpRequest, e?: ProgressEvent) => this.handleError({ e, xhr: userXhr, fileInstance }),
+                onSuccess: (response: any, e?: ProgressEvent) => this.handleSuccess({ response, fileInstance, e, isCustomRequest: true }),
                 withCredentials: option.withCredentials,
                 action: option.action,
             });
@@ -572,7 +572,7 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
         xhr.send(formData);
     }
 
-    handleProgress({ e, fileInstance }: { e: ProgressEvent; fileInstance: File }): void {
+    handleProgress({ e, fileInstance }: { e?: ProgressEvent; fileInstance: File }): void {
         const { fileList } = this.getStates();
         const newFileList = fileList.slice();
         let percent = 0;
@@ -591,7 +591,7 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
         this._adapter.notifyChange({ fileList: newFileList, currentFile: newFileList[index] });
     }
 
-    handleOnLoad({ e, xhr, fileInstance }: { e: ProgressEvent; xhr: XMLHttpRequest; fileInstance: File }): void {
+    handleOnLoad({ e, xhr, fileInstance }: { e?: ProgressEvent; xhr: XMLHttpRequest; fileInstance: File }): void {
         const { fileList } = this.getStates();
         const index = this._getFileIndex(fileInstance, fileList);
         if (index < 0) {
@@ -604,7 +604,7 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
         }
     }
 
-    handleSuccess({ e, fileInstance, isCustomRequest = false, xhr, response }: { e: ProgressEvent; fileInstance: CustomFile; isCustomRequest?: boolean; xhr?: XMLHttpRequest; response?: any }): void {
+    handleSuccess({ e, fileInstance, isCustomRequest = false, xhr, response }: { e?: ProgressEvent; fileInstance: CustomFile; isCustomRequest?: boolean; xhr?: XMLHttpRequest; response?: any }): void {
         const { fileList } = this.getStates();
         let body: any = null;
         const index = this._getFileIndex(fileInstance, fileList);
@@ -673,7 +673,7 @@ class UploadFoundation<P = Record<string, any>, S = Record<string, any>> extends
         });
     }
 
-    handleError({ e, xhr, fileInstance }: { e: ProgressEvent;xhr: XMLHttpRequest;fileInstance: CustomFile }): void {
+    handleError({ e, xhr, fileInstance }: { e?: ProgressEvent;xhr: XMLHttpRequest;fileInstance: CustomFile }): void {
         const { fileList } = this.getStates();
         const index = this._getFileIndex(fileInstance, fileList);
         if (index < 0) {

+ 4 - 4
packages/semi-ui/upload/interface.ts

@@ -27,11 +27,11 @@ export interface customRequestArgs {
     data: Record<string, any>; // User-set props.data
     file: FileItem;
     fileInstance: File; // Original File Object which extends to the blob, the file object actually acquired by the browser (https://developer.mozilla.org/zh-CN/docs/Web/API/File)
-    onProgress: (event: { total: number; loaded: number }) => any; // The function that should be called during the upload process, the event needs to contain the total and loaded attributes
-    onError: (userXhr: { status?: number }, e: Event) => any; // Functions to call in case of upload error
-    onSuccess: (response: any, e: Event) => any; // The function that should be called after the upload is successful, the response is the request result after the upload is successful
+    onProgress: (e?: { total: number; loaded: number }) => any; // The function that should be called during the upload process, the event needs to contain the total and loaded attributes
+    onError: (userXhr: { status?: number }, e?: Event) => any; // Functions to call in case of upload error
+    onSuccess: (response: any, e?: Event) => any; // The function that should be called after the upload is successful, the response is the request result after the upload is successful
     withCredentials: boolean; // User-set props.with Credentials
-    action: string; // User-set props.action
+    action: string // User-set props.action
 }
 
 export interface CustomError extends Error {