Skip to content

Commit

Permalink
fix:组件特性动作中执行全局变量修改
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm-lv committed Nov 7, 2023
1 parent a9eafda commit 28b3376
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions packages/amis-core/src/actions/CmptAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down

0 comments on commit 28b3376

Please sign in to comment.