mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-02 12:59:47 +08:00
parent
16e45cb45d
commit
8e18336fa3
@ -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<DataSourceSchema>) {
|
||||
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) {
|
||||
|
@ -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<string, EventOption[]>) {
|
||||
@ -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() {
|
||||
|
@ -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<string, Partial<MNode>>) {
|
||||
@ -101,7 +101,7 @@ class Props extends BaseService {
|
||||
* @param value 组件初始值
|
||||
*/
|
||||
public async setPropsValue(type: string, value: Partial<MNode>) {
|
||||
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<string, any> = {}) {
|
||||
public async getPropsValue(componentType: string, { inputEvent, ...defaultValue }: Record<string, any> = {}) {
|
||||
const type = toLine(componentType);
|
||||
|
||||
if (type === 'area') {
|
||||
const value = (await this.getPropsValue('button')) as MComponent;
|
||||
value.className = 'action-area';
|
||||
|
Loading…
x
Reference in New Issue
Block a user