From 35fc9546a193fdf02a6c4e7391603b075830a2a1 Mon Sep 17 00:00:00 2001 From: sheepluo Date: Sun, 5 Nov 2023 20:11:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(Upload):=20=E6=96=87=E4=BB=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=AF=E6=8C=81=E6=98=BE=E7=A4=BA=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/upload/main.ts | 19 +++++++++++++++---- js/upload/types.ts | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/js/upload/main.ts b/js/upload/main.ts index 6983920a47..c0730ba233 100644 --- a/js/upload/main.ts +++ b/js/upload/main.ts @@ -15,6 +15,7 @@ import { handleSuccessParams, UploadTriggerUploadText, ErrorContext, + ResponseType, } from './types'; export interface BeforeUploadExtra { @@ -67,13 +68,15 @@ export interface OnErrorParams extends ErrorContext { export function handleError(options: OnErrorParams) { const { event, files, response, XMLHttpRequest, formatResponse } = options; - files.forEach((file) => { - file.status = 'fail'; - }); let res = response; if (isFunction(formatResponse)) { res = formatResponse(response, { file: files[0], currentFiles: files }); } + files.forEach((file) => { + file.status = 'fail'; + file.response = res; + }); + return { response: res, event, files, XMLHttpRequest }; } @@ -146,7 +149,15 @@ export function uploadOneRequest(params: HandleUploadParams): Promise; +export type ResponseType = { error?: string; url?: string; status?: 'fail' | 'success'; files?: UploadFile[] } & Record export interface HandleUploadParams { /** 已经上传过的文件 */ From 56f3acdc7c44c2a1dde6c74deb68f6b952de1a7d Mon Sep 17 00:00:00 2001 From: sheepluo Date: Sun, 5 Nov 2023 20:28:21 +0800 Subject: [PATCH 2/2] fix: lint error --- js/upload/main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/upload/main.ts b/js/upload/main.ts index c0730ba233..7b2688cf38 100644 --- a/js/upload/main.ts +++ b/js/upload/main.ts @@ -76,7 +76,6 @@ export function handleError(options: OnErrorParams) { file.status = 'fail'; file.response = res; }); - return { response: res, event, files, XMLHttpRequest }; } @@ -149,7 +148,7 @@ export function uploadOneRequest(params: HandleUploadParams): Promise