feat(cli,data-source,editor,playground,runtime): 支持自定义数据源
This commit is contained in:
@@ -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: '描述',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user