From 28b3376a654c5af4a1e8528d67db6999da0dcfa7 Mon Sep 17 00:00:00 2001 From: lvxiaojiao Date: Tue, 7 Nov 2023 15:25:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=BB=84=E4=BB=B6=E7=89=B9=E6=80=A7?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C=E4=B8=AD=E6=89=A7=E8=A1=8C=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/actions/CmptAction.ts | 30 +++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/amis-core/src/actions/CmptAction.ts b/packages/amis-core/src/actions/CmptAction.ts index 92877ab42b7..6e526e5a4c5 100644 --- a/packages/amis-core/src/actions/CmptAction.ts +++ b/packages/amis-core/src/actions/CmptAction.ts @@ -36,6 +36,19 @@ export class CmptAction implements RendererAction { */ const key = action.componentId || action.componentName; const dataMergeMode = action.dataMergeMode || 'merge'; + const path = action.args?.path; + + /** 如果args中携带path参数, 则认为是全局变量赋值, 否则认为是组件变量赋值 */ + if (action.actionType === 'setValue' && path && typeof path === 'string') { + const beforeSetData = renderer?.props?.env?.beforeSetData; + if (beforeSetData && typeof beforeSetData === 'function') { + const res = await beforeSetData(renderer, action, event); + + if (res === false) { + return; + } + } + } if (!key) { console.warn('请提供目标组件的componentId或componentName'); @@ -59,23 +72,6 @@ export class CmptAction implements RendererAction { } if (action.actionType === 'setValue') { - const beforeSetData = renderer?.props?.env?.beforeSetData; - const path = action.args?.path; - - /** 如果args中携带path参数, 则认为是全局变量赋值, 否则认为是组件变量赋值 */ - if ( - path && - typeof path === 'string' && - beforeSetData && - typeof beforeSetData === 'function' - ) { - const res = await beforeSetData(renderer, action, event); - - if (res === false) { - return; - } - } - if (component?.setData) { return component?.setData( action.args?.value,