1
0
mirror of synced 2026-04-05 07:48:35 +08:00

feat(cli,data-source,editor,playground,runtime): 支持自定义数据源

This commit is contained in:
roymondchen
2023-08-21 16:57:18 +08:00
parent 60e14fe53e
commit 573f1a2c17
28 changed files with 528 additions and 269 deletions

View File

@@ -2,25 +2,30 @@ import { reactive } from 'vue';
import { cloneDeep } from 'lodash-es';
import type { FormConfig } from '@tmagic/form';
import { DataSourceSchema } from '@tmagic/schema';
import type { DataSourceSchema } from '@tmagic/schema';
import { guid } from '@tmagic/utils';
import type { DatasourceTypeOption } from '@editor/type';
import { getFormConfig } from '@editor/utils/data-source';
import BaseService from './BaseService';
interface State {
datasourceTypeList: DatasourceTypeOption[];
dataSources: DataSourceSchema[];
editable: boolean;
configs: Record<string, FormConfig>;
values: Record<string, Partial<DataSourceSchema>>;
}
type StateKey = keyof State;
class DataSource extends BaseService {
private state = reactive<State>({
datasourceTypeList: [],
dataSources: [],
editable: true,
configs: {},
values: {},
});
public set<K extends StateKey, T extends State[K]>(name: K, value: T) {
@@ -32,13 +37,21 @@ class DataSource extends BaseService {
}
public getFormConfig(type = 'base') {
return getFormConfig(type, this.get('configs'));
return getFormConfig(type, this.get('datasourceTypeList'), this.get('configs'));
}
public setFormConfig(type: string, config: FormConfig) {
this.get('configs')[type] = config;
}
public getFormValue(type = 'base') {
return this.get('values')[type];
}
public setFormValue(type: string, value: Partial<DataSourceSchema>) {
this.get('values')[type] = value;
}
public add(config: DataSourceSchema) {
const newConfig = {
...config,

View File

@@ -80,7 +80,7 @@ class Props extends BaseService {
return cloneDeep(this.state.propsConfigMap[type] || (await this.fillConfig([])));
}
public setPropsValues(values: Record<string, MNode>) {
public setPropsValues(values: Record<string, Partial<MNode>>) {
Object.keys(values).forEach((type: string) => {
this.setPropsValue(toLine(type), values[type]);
});
@@ -91,7 +91,7 @@ class Props extends BaseService {
* @param type 组件类型
* @param value 组件初始值
*/
public async setPropsValue(type: string, value: MNode) {
public async setPropsValue(type: string, value: Partial<MNode>) {
this.state.propsValueMap[type] = value;
}