mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-15 16:39:45 +08:00
feat(editor,util): 完善数据源配置
This commit is contained in:
parent
28b3d2e4b3
commit
5840ee537f
@ -50,7 +50,7 @@
|
|||||||
import { computed, inject, onUnmounted, ref } from 'vue';
|
import { computed, inject, onUnmounted, ref } from 'vue';
|
||||||
|
|
||||||
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
||||||
import { ColumnConfig, FormState, MFormDrawer } from '@tmagic/form';
|
import { ColumnConfig, FormConfig, FormState, MFormDrawer } from '@tmagic/form';
|
||||||
import type { CodeBlockContent } from '@tmagic/schema';
|
import type { CodeBlockContent } from '@tmagic/schema';
|
||||||
|
|
||||||
import CodeEditor from '@editor/layouts/CodeEditor.vue';
|
import CodeEditor from '@editor/layouts/CodeEditor.vue';
|
||||||
@ -65,6 +65,7 @@ const props = defineProps<{
|
|||||||
content: CodeBlockContent;
|
content: CodeBlockContent;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
isDataSource?: boolean;
|
isDataSource?: boolean;
|
||||||
|
dataSourceType?: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@ -135,10 +136,11 @@ const defaultParamColConfig: ColumnConfig = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const functionConfig = computed(() => [
|
const functionConfig = computed<FormConfig>(() => [
|
||||||
{
|
{
|
||||||
text: '名称',
|
text: '名称',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
|
rules: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '描述',
|
text: '描述',
|
||||||
@ -148,10 +150,17 @@ const functionConfig = computed(() => [
|
|||||||
text: '执行时机',
|
text: '执行时机',
|
||||||
name: 'timing',
|
name: 'timing',
|
||||||
type: 'select',
|
type: 'select',
|
||||||
options: [
|
options: () => {
|
||||||
{ text: '初始化前', value: 'beforeInit' },
|
const options = [
|
||||||
{ text: '初始化后', value: 'afterInit' },
|
{ text: '初始化前', value: 'beforeInit' },
|
||||||
],
|
{ text: '初始化后', value: 'afterInit' },
|
||||||
|
];
|
||||||
|
if (props.dataSourceType !== 'base') {
|
||||||
|
options.push({ text: '请求前', value: 'beforeRequest' });
|
||||||
|
options.push({ text: '请求后', value: 'afterRequest' });
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
},
|
||||||
display: () => props.isDataSource,
|
display: () => props.isDataSource,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -171,6 +171,16 @@ const dataSourceFieldsConfig: FormConfig = [
|
|||||||
{
|
{
|
||||||
name: 'defaultValue',
|
name: 'defaultValue',
|
||||||
text: '默认值',
|
text: '默认值',
|
||||||
|
type: (mForm: FormState | undefined, { model }: any) => {
|
||||||
|
if (model.type === 'number') return 'number';
|
||||||
|
if (model.type === 'boolean') return 'select';
|
||||||
|
|
||||||
|
return 'string';
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{ text: 'true', value: true },
|
||||||
|
{ text: 'false', value: false },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'enable',
|
name: 'enable',
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:content="codeConfig"
|
:content="codeConfig"
|
||||||
:is-data-source="true"
|
:is-data-source="true"
|
||||||
|
:data-source-type="model.type"
|
||||||
@submit="submitCodeHandler"
|
@submit="submitCodeHandler"
|
||||||
></CodeBlockEditor>
|
></CodeBlockEditor>
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,6 +7,15 @@ export default [
|
|||||||
type: 'switch',
|
type: 'switch',
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'responseOptions',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
name: 'dataPath',
|
||||||
|
text: '数据路径',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'fieldset',
|
type: 'fieldset',
|
||||||
name: 'options',
|
name: 'options',
|
||||||
|
@ -248,7 +248,7 @@ export const displayTabConfig: TabPaneConfig = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'select',
|
type: 'select',
|
||||||
options: (mForm: FormState | undefined, { model }: any) => {
|
options: (mForm, { model }) => {
|
||||||
const [id, field] = model.field;
|
const [id, field] = model.field;
|
||||||
|
|
||||||
const ds = dataSourceService.getDataSourceById(id);
|
const ds = dataSourceService.getDataSourceById(id);
|
||||||
@ -284,23 +284,33 @@ export const displayTabConfig: TabPaneConfig = {
|
|||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
name: 'value',
|
name: 'value',
|
||||||
display: (vm: FormState, { model }: any) =>
|
type: (mForm, { model }) => {
|
||||||
!['between', 'not_between', 'is', 'not'].includes(model.op),
|
const [id, field] = model.field;
|
||||||
},
|
|
||||||
{
|
const ds = dataSourceService.getDataSourceById(id);
|
||||||
name: 'value',
|
|
||||||
type: 'select',
|
const type = ds?.fields.find((f) => f.name === field)?.type;
|
||||||
|
|
||||||
|
if (type === 'number') {
|
||||||
|
return 'number';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'boolean') {
|
||||||
|
return 'select';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'text';
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{ text: 'true', value: true },
|
{ text: 'true', value: true },
|
||||||
{ text: 'false', value: false },
|
{ text: 'false', value: false },
|
||||||
],
|
],
|
||||||
display: (vm: FormState, { model }: any) => ['is', 'not'].includes(model.op),
|
display: (vm, { model }) => !['between', 'not_between'].includes(model.op),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'range',
|
name: 'range',
|
||||||
type: 'number-range',
|
type: 'number-range',
|
||||||
display: (vm: FormState, { model }: any) =>
|
display: (vm, { model }) => ['between', 'not_between'].includes(model.op),
|
||||||
['between', 'not_between'].includes(model.op) && !['is', 'not'].includes(model.op),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user