From f93d002c2809065d227ffd8010bc29dd579b171f Mon Sep 17 00:00:00 2001 From: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Date: Wed, 17 Aug 2022 17:05:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Form=E5=BC=80=E5=90=AFtrimValues?= =?UTF-8?q?=E6=97=B6=E4=BC=9A=E5=B0=86File=E5=AD=97=E6=AE=B5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=BD=AC=E6=8D=A2=E9=97=AE=E9=A2=98=20(#5162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/utils/helper.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/amis-core/src/utils/helper.ts b/packages/amis-core/src/utils/helper.ts index ad18af94a..a42069cd4 100644 --- a/packages/amis-core/src/utils/helper.ts +++ b/packages/amis-core/src/utils/helper.ts @@ -1350,10 +1350,32 @@ export function chainEvents(props: any, schema: any) { return ret; } -export function mapObject(value: any, fn: Function): any { +export function mapObject( + value: any, + fn: Function, + skipFn?: (value: any) => boolean +): any { + // 如果value值满足skipFn条件则不做map操作 + skipFn = + skipFn && typeof skipFn === 'function' + ? skipFn + : (value: any): boolean => { + // File类型处理之后会变成plain object + if (value instanceof File) { + return true; + } + + return false; + }; + + if (!!skipFn(value)) { + return value; + } + if (Array.isArray(value)) { return value.map(item => mapObject(item, fn)); } + if (isObject(value)) { let tmpValue = {...value}; Object.keys(tmpValue).forEach(key => {