From 1297e3c0e5f13a50bdd6e79ce5da37a8272e1ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Wed, 9 Jun 2021 14:57:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20valueChange=20?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E5=9B=A0=E4=B8=BA=E5=AD=90=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E8=80=8C=E9=80=9A=E7=9F=A5=E7=88=B6=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC,=20=E8=80=83?= =?UTF-8?q?=E8=99=91=E5=88=B0=E5=90=8E=E7=BB=AD=E6=8E=A8=E8=8D=90=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E4=BD=BF=E7=94=A8=20setValue,=20=E4=B9=9F=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E4=BA=86=20valueChange=20=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/designer/setting/setting-field.ts | 12 ++++++--- .../designer/setting/setting-prop-entry.ts | 25 ++++++++++--------- packages/designer/src/types/index.ts | 19 +++++++++++++- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/packages/designer/src/designer/setting/setting-field.ts b/packages/designer/src/designer/setting/setting-field.ts index 0bedf77c3..6f2a935d8 100644 --- a/packages/designer/src/designer/setting/setting-field.ts +++ b/packages/designer/src/designer/setting/setting-field.ts @@ -4,6 +4,7 @@ import { SettingPropEntry } from './setting-prop-entry'; import { SettingEntry } from './setting-entry'; import { computed, obx } from '@ali/lowcode-editor-core'; import { cloneDeep } from '@ali/lowcode-utils'; +import { ISetValueOptions } from '../../types'; function getSettingFieldCollectorKey(parent: SettingEntry, config: FieldConfig) { let cur = parent; @@ -140,7 +141,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { private hotValue: any; - setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: any) { + setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: ISetValueOptions) { if (isHotValue) { this.setHotValue(val, extraOptions); return; @@ -172,9 +173,14 @@ export class SettingField extends SettingPropEntry implements SettingEntry { this.valueChange(); } - setHotValue(data: any, options?: any) { + setHotValue(data: any, options?: ISetValueOptions) { this.hotValue = data; const value = this.transducer.toNative(data); + if (options) { + options.fromSetHotValue = true; + } else { + options = { fromSetHotValue: true }; + } if (this.isUseVariable()) { const oldValue = this.getValue(); this.setValue({ @@ -191,7 +197,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry { return; } - this.valueChange(); + this.valueChange(options); } onEffect(action: () => void): () => void { diff --git a/packages/designer/src/designer/setting/setting-prop-entry.ts b/packages/designer/src/designer/setting/setting-prop-entry.ts index 3ec65bd4e..351af3cfe 100644 --- a/packages/designer/src/designer/setting/setting-prop-entry.ts +++ b/packages/designer/src/designer/setting/setting-prop-entry.ts @@ -6,6 +6,8 @@ import { Node } from '../../document'; import { ComponentMeta } from '../../component-meta'; import { Designer } from '../designer'; import { EventEmitter } from 'events'; +import { ISetValueOptions } from '../../types'; +import { isSettingField } from './setting-field'; export class SettingPropEntry implements SettingEntry { // === static properties === @@ -162,7 +164,7 @@ export class SettingPropEntry implements SettingEntry { /** * 设置当前属性值 */ - setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: any) { + setValue(val: any, isHotValue?: boolean, force?: boolean, extraOptions?: ISetValueOptions) { const oldValue = this.getValue(); if (this.type === 'field') { this.parent.setPropValue(this.name, val); @@ -178,6 +180,10 @@ export class SettingPropEntry implements SettingEntry { } } this.notifyValueChange(oldValue, val); + // 如果 fromSetHotValue,那么在 setHotValue 中已经调用过 valueChange 了 + if (!extraOptions?.fromSetHotValue) { + this.valueChange(extraOptions); + } } /** @@ -272,8 +278,12 @@ export class SettingPropEntry implements SettingEntry { /** * @deprecated */ - valueChange() { - this.emitter.emit('valuechange'); + valueChange(options: ISetValueOptions = {}) { + this.emitter.emit('valuechange', options); + + if (this.parent && isSettingField(this.parent)) { + this.parent.valueChange(options); + } } notifyValueChange(oldValue: any, newValue:any) { @@ -288,15 +298,6 @@ export class SettingPropEntry implements SettingEntry { return false; } - /* - getConfig(configName?: K): IPropConfig[K] | IPropConfig { - if (configName) { - return this.config[configName]; - } - - return this.config; - } - */ getVariableValue() { const v = this.getValue(); if (isJSExpression(v)) { diff --git a/packages/designer/src/types/index.ts b/packages/designer/src/types/index.ts index e079964b0..97cf60c6a 100644 --- a/packages/designer/src/types/index.ts +++ b/packages/designer/src/types/index.ts @@ -18,4 +18,21 @@ const utils = { compatibleLegaoSchema, getNodeSchemaById, }; -export type Utils = typeof utils; \ No newline at end of file +export type Utils = typeof utils; + +export enum PROP_VALUE_CHANGED_TYPE { + /** + * normal set value + */ + SET_VALUE = 'SET_VALUE', + /** + * value changed caused by sub-prop value change + */ + SUB_VALUE_CHANGE = 'SUB_VALUE_CHANGE', +} + +export interface ISetValueOptions { + disableMutator?: boolean; + type?: PROP_VALUE_CHANGED_TYPE; + fromSetHotValue?: boolean; +} \ No newline at end of file