diff --git a/packages/editor/src/services/dataSource.ts b/packages/editor/src/services/dataSource.ts index c7b7720f..e4bd55bc 100644 --- a/packages/editor/src/services/dataSource.ts +++ b/packages/editor/src/services/dataSource.ts @@ -5,7 +5,7 @@ import { Writable } from 'type-fest'; import type { EventOption } from '@tmagic/core'; import type { FormConfig } from '@tmagic/form'; import type { DataSourceSchema } from '@tmagic/schema'; -import { guid } from '@tmagic/utils'; +import { guid, toLine } from '@tmagic/utils'; import type { DatasourceTypeOption, SyncHookPlugin } from '@editor/type'; import { getFormConfig, getFormValue } from '@editor/utils/data-source'; @@ -68,35 +68,35 @@ class DataSource extends BaseService { } public getFormConfig(type = 'base') { - return getFormConfig(type, this.get('configs')); + return getFormConfig(toLine(type), this.get('configs')); } public setFormConfig(type: string, config: FormConfig) { - this.get('configs')[type] = config; + this.get('configs')[toLine(type)] = config; } public getFormValue(type = 'base') { - return getFormValue(type, this.get('values')[type]); + return getFormValue(toLine(type), this.get('values')[type]); } public setFormValue(type: string, value: Partial) { - this.get('values')[type] = value; + this.get('values')[toLine(type)] = value; } public getFormEvent(type = 'base') { - return this.get('events')[type] || []; + return this.get('events')[toLine(type)] || []; } public setFormEvent(type: string, value: EventOption[] = []) { - this.get('events')[type] = value; + this.get('events')[toLine(type)] = value; } public getFormMethod(type = 'base') { - return this.get('methods')[type] || []; + return this.get('methods')[toLine(type)] || []; } public setFormMethod(type: string, value: EventOption[] = []) { - this.get('methods')[type] = value; + this.get('methods')[toLine(type)] = value; } public add(config: DataSourceSchema) { diff --git a/packages/editor/src/services/events.ts b/packages/editor/src/services/events.ts index d149d7d6..d24b6ea2 100644 --- a/packages/editor/src/services/events.ts +++ b/packages/editor/src/services/events.ts @@ -55,11 +55,11 @@ class Events extends BaseService { } public setEvent(type: string, events: EventOption[]) { - eventMap[type] = [...DEFAULT_EVENTS, ...events]; + eventMap[toLine(type)] = [...DEFAULT_EVENTS, ...events]; } public getEvent(type: string): EventOption[] { - return cloneDeep(eventMap[type] || DEFAULT_EVENTS); + return cloneDeep(eventMap[toLine(type)] || DEFAULT_EVENTS); } public setMethods(methods: Record) { @@ -69,11 +69,11 @@ class Events extends BaseService { } public setMethod(type: string, method: EventOption[]) { - methodMap[type] = [...DEFAULT_METHODS, ...method]; + methodMap[toLine(type)] = [...DEFAULT_METHODS, ...method]; } public getMethod(type: string) { - return cloneDeep(methodMap[type] || DEFAULT_METHODS); + return cloneDeep(methodMap[toLine(type)] || DEFAULT_METHODS); } public resetState() { diff --git a/packages/editor/src/services/props.ts b/packages/editor/src/services/props.ts index 26646450..455d5299 100644 --- a/packages/editor/src/services/props.ts +++ b/packages/editor/src/services/props.ts @@ -73,7 +73,7 @@ class Props extends BaseService { } public async setPropsConfig(type: string, config: FormConfig) { - this.state.propsConfigMap[type] = await this.fillConfig(Array.isArray(config) ? config : [config]); + this.state.propsConfigMap[toLine(type)] = await this.fillConfig(Array.isArray(config) ? config : [config]); } /** @@ -86,7 +86,7 @@ class Props extends BaseService { return await this.getPropsConfig('button'); } - return cloneDeep(this.state.propsConfigMap[type] || (await this.fillConfig([]))); + return cloneDeep(this.state.propsConfigMap[toLine(type)] || (await this.fillConfig([]))); } public setPropsValues(values: Record>) { @@ -101,7 +101,7 @@ class Props extends BaseService { * @param value 组件初始值 */ public async setPropsValue(type: string, value: Partial) { - this.state.propsValueMap[type] = value; + this.state.propsValueMap[toLine(type)] = value; } /** @@ -109,7 +109,9 @@ class Props extends BaseService { * @param type 组件类型 * @returns 组件初始值 */ - public async getPropsValue(type: string, { inputEvent, ...defaultValue }: Record = {}) { + public async getPropsValue(componentType: string, { inputEvent, ...defaultValue }: Record = {}) { + const type = toLine(componentType); + if (type === 'area') { const value = (await this.getPropsValue('button')) as MComponent; value.className = 'action-area';