1
0
mirror of synced 2026-04-05 16:08:37 +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

@@ -1,32 +1,37 @@
import type { FormConfig } from '@tmagic/form';
export default [
{
name: 'id',
type: 'hidden',
},
{
name: 'type',
text: '类型',
type: 'select',
options: [
{ text: '基础', value: 'base' },
{ text: 'HTTP', value: 'http' },
],
defaultValue: 'base',
},
{
name: 'title',
text: '名称',
rules: [
{
required: true,
message: '请输入名称',
},
],
},
{
name: 'description',
text: '描述',
},
] as FormConfig;
import type { DatasourceTypeOption } from '@editor/type';
export default function (datasourceTypeList: DatasourceTypeOption[] = []): FormConfig {
return [
{
name: 'id',
type: 'hidden',
},
{
name: 'type',
text: '类型',
type: 'select',
options: [
{ text: '基础', value: 'base' },
{ text: 'HTTP', value: 'http' },
...datasourceTypeList.map((item) => ({ text: item.text, value: item.type })),
],
defaultValue: 'base',
},
{
name: 'title',
text: '名称',
rules: [
{
required: true,
message: '请输入名称',
},
],
},
{
name: 'description',
text: '描述',
},
];
}

View File

@@ -1,10 +1,12 @@
import { FormConfig } from '@tmagic/form';
import { DatasourceTypeOption } from '@editor/type';
import BaseFormConfig from './formConfigs/base';
import HttpFormConfig from './formConfigs/http';
const fillConfig = (config: FormConfig): FormConfig => [
...BaseFormConfig,
const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption[]): FormConfig => [
...BaseFormConfig(datasourceTypeList),
...config,
{
type: 'panel',
@@ -30,13 +32,17 @@ const fillConfig = (config: FormConfig): FormConfig => [
},
];
export const getFormConfig = (type: string, configs: Record<string, FormConfig>): FormConfig => {
export const getFormConfig = (
type: string,
datasourceTypeList: DatasourceTypeOption[],
configs: Record<string, FormConfig>,
): FormConfig => {
switch (type) {
case 'base':
return fillConfig([]);
return fillConfig([], datasourceTypeList);
case 'http':
return fillConfig(HttpFormConfig);
return fillConfig(HttpFormConfig, datasourceTypeList);
default:
return fillConfig(configs[type] || []);
return fillConfig(configs[type] || [], datasourceTypeList);
}
};