mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-03 00:12:30 +08:00
feat(editor,data-source): 支持数据源方法配置执行时机
This commit is contained in:
parent
e3b2594c57
commit
07c49bee4e
@ -81,8 +81,24 @@ class DataSourceManager extends EventEmitter {
|
|||||||
|
|
||||||
this.data[ds.id] = ds.data;
|
this.data[ds.id] = ds.data;
|
||||||
|
|
||||||
|
ds.getMethods().forEach((method) => {
|
||||||
|
if (method.timing === 'beforeInit') {
|
||||||
|
if (typeof method.content === 'function') {
|
||||||
|
method.content({ params: {}, dataSource: ds });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ds.init().then(() => {
|
ds.init().then(() => {
|
||||||
this.data[ds.id] = ds.data;
|
this.data[ds.id] = ds.data;
|
||||||
|
|
||||||
|
ds.getMethods().forEach((method) => {
|
||||||
|
if (method.timing === 'afterInit') {
|
||||||
|
if (typeof method.content === 'function') {
|
||||||
|
method.content({ params: {}, dataSource: ds });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ds.on('change', () => {
|
ds.on('change', () => {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<MFormDrawer
|
<MFormDrawer
|
||||||
|
class="m-editor-code-block-editor"
|
||||||
ref="fomDrawer"
|
ref="fomDrawer"
|
||||||
label-width="80px"
|
label-width="80px"
|
||||||
:close-on-press-escape="false"
|
:close-on-press-escape="false"
|
||||||
@ -28,9 +29,10 @@ defineOptions({
|
|||||||
name: 'MEditorCodeBlockEditor',
|
name: 'MEditorCodeBlockEditor',
|
||||||
});
|
});
|
||||||
|
|
||||||
defineProps<{
|
const props = defineProps<{
|
||||||
content: CodeBlockContent;
|
content: CodeBlockContent;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
isDataSource?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@ -40,7 +42,9 @@ const emit = defineEmits<{
|
|||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
|
|
||||||
const columnWidth = computed(() => services?.uiService.get('columnWidth'));
|
const columnWidth = computed(() => services?.uiService.get('columnWidth'));
|
||||||
const size = computed(() => (columnWidth.value ? columnWidth.value.center + columnWidth.value.right : 600));
|
const size = computed(() =>
|
||||||
|
columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600,
|
||||||
|
);
|
||||||
|
|
||||||
const codeEditorHeight = ref('600px');
|
const codeEditorHeight = ref('600px');
|
||||||
|
|
||||||
@ -80,16 +84,26 @@ const functionConfig = computed(() => [
|
|||||||
name: 'name',
|
name: 'name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '注释',
|
text: '描述',
|
||||||
name: 'desc',
|
name: 'desc',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: '执行时机',
|
||||||
|
name: 'timing',
|
||||||
|
type: 'select',
|
||||||
|
options: [
|
||||||
|
{ text: '初始化前', value: 'beforeInit' },
|
||||||
|
{ text: '初始化后', value: 'afterInit' },
|
||||||
|
],
|
||||||
|
display: () => props.isDataSource,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'table',
|
type: 'table',
|
||||||
border: true,
|
border: true,
|
||||||
text: '参数',
|
text: '参数',
|
||||||
enableFullscreen: false,
|
enableFullscreen: false,
|
||||||
|
enableToggleMode: false,
|
||||||
name: 'params',
|
name: 'params',
|
||||||
maxHeight: '300px',
|
|
||||||
dropSort: false,
|
dropSort: false,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
@ -99,7 +113,7 @@ const functionConfig = computed(() => [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
label: '注释',
|
label: '描述',
|
||||||
name: 'extra',
|
name: 'extra',
|
||||||
},
|
},
|
||||||
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
|
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
|
||||||
@ -138,7 +152,7 @@ const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
|
|||||||
const openHandler = () => {
|
const openHandler = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (fomDrawer.value) {
|
if (fomDrawer.value) {
|
||||||
const height = fomDrawer.value?.bodyHeight - 468;
|
const height = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
|
||||||
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,15 +6,16 @@
|
|||||||
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
|
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<MFormDialog
|
<MFormDrawer
|
||||||
ref="addDialog"
|
ref="addDialog"
|
||||||
|
label-width="80px"
|
||||||
:title="filedTitle"
|
:title="filedTitle"
|
||||||
:config="dataSourceFieldsConfig"
|
:config="dataSourceFieldsConfig"
|
||||||
:values="fieldValues"
|
:values="fieldValues"
|
||||||
:parentValues="model[name]"
|
:parentValues="model[name]"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
@submit="fieldChange"
|
@submit="fieldChange"
|
||||||
></MFormDialog>
|
></MFormDrawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -22,7 +23,7 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
|
import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
|
||||||
import { FieldProps, FormConfig, FormState, MFormDialog } from '@tmagic/form';
|
import { FieldProps, FormConfig, FormState, MFormDrawer } from '@tmagic/form';
|
||||||
import { MagicTable } from '@tmagic/table';
|
import { MagicTable } from '@tmagic/table';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -42,7 +43,7 @@ const props = withDefaults(
|
|||||||
|
|
||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
const addDialog = ref<InstanceType<typeof MFormDialog>>();
|
const addDialog = ref<InstanceType<typeof MFormDrawer>>();
|
||||||
const fieldValues = ref<Record<string, any>>({});
|
const fieldValues = ref<Record<string, any>>({});
|
||||||
const filedTitle = ref('');
|
const filedTitle = ref('');
|
||||||
|
|
||||||
@ -77,6 +78,10 @@ const fieldColumns = [
|
|||||||
label: '属性描述',
|
label: '属性描述',
|
||||||
prop: 'desc',
|
prop: 'desc',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: '默认值',
|
||||||
|
prop: 'defaultValue',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: '操作',
|
label: '操作',
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
@ -154,6 +159,7 @@ const dataSourceFieldsConfig: FormConfig = [
|
|||||||
{
|
{
|
||||||
name: 'description',
|
name: 'description',
|
||||||
text: '描述',
|
text: '描述',
|
||||||
|
type: 'textarea',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'defaultValue',
|
name: 'defaultValue',
|
||||||
|
@ -9,10 +9,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CodeBlockEditor
|
<CodeBlockEditor
|
||||||
ref="codeBlockEditor"
|
|
||||||
v-if="codeConfig"
|
v-if="codeConfig"
|
||||||
|
ref="codeBlockEditor"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:content="codeConfig"
|
:content="codeConfig"
|
||||||
|
:is-data-source="true"
|
||||||
@submit="submitCodeHandler"
|
@submit="submitCodeHandler"
|
||||||
></CodeBlockEditor>
|
></CodeBlockEditor>
|
||||||
</div>
|
</div>
|
||||||
@ -53,9 +54,13 @@ const methodColumns = [
|
|||||||
prop: 'name',
|
prop: 'name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '注释',
|
label: '描述',
|
||||||
prop: 'desc',
|
prop: 'desc',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: '执行时机',
|
||||||
|
prop: 'timing',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: '参数',
|
label: '参数',
|
||||||
prop: 'params',
|
prop: 'params',
|
||||||
|
@ -24,3 +24,13 @@
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.m-editor-code-block-editor {
|
||||||
|
.tmagic-design-table {
|
||||||
|
height: 180px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-drawer__body {
|
||||||
|
padding: 10px 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="mTable" class="m-fields-table" :class="{ 'm-fields-table-item-extra': config.itemExtra }">
|
<div ref="mTable" class="m-fields-table" :class="{ 'm-fields-table-item-extra': config.itemExtra }">
|
||||||
<span v-if="config.extra" style="color: rgba(0, 0, 0, 0.45)" v-html="config.extra"></span>
|
<span v-if="config.extra" style="color: rgba(0, 0, 0, 0.45)" v-html="config.extra"></span>
|
||||||
<div class="el-form-item__content">
|
|
||||||
<TMagicTooltip content="拖拽可排序" placement="left-start" :disabled="config.dropSort !== true">
|
<TMagicTooltip content="拖拽可排序" placement="left-start" :disabled="config.dropSort !== true">
|
||||||
<TMagicTable
|
<TMagicTable
|
||||||
v-if="model[modelName]"
|
v-if="model[modelName]"
|
||||||
@ -130,7 +129,7 @@
|
|||||||
size="small"
|
size="small"
|
||||||
type="primary"
|
type="primary"
|
||||||
@click="toggleMode"
|
@click="toggleMode"
|
||||||
v-if="enableToggleMode && !isFullscreen"
|
v-if="enableToggleMode && config.enableToggleMode !== false && !isFullscreen"
|
||||||
>展开配置</TMagicButton
|
>展开配置</TMagicButton
|
||||||
>
|
>
|
||||||
<TMagicButton
|
<TMagicButton
|
||||||
@ -156,7 +155,6 @@
|
|||||||
<TMagicButton v-if="importable" size="small" type="warning" :disabled="disabled" plain @click="clearHandler()"
|
<TMagicButton v-if="importable" size="small" type="warning" :disabled="disabled" plain @click="clearHandler()"
|
||||||
>清空</TMagicButton
|
>清空</TMagicButton
|
||||||
>
|
>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="bottom" style="text-align: right" v-if="config.pagination">
|
<div class="bottom" style="text-align: right" v-if="config.pagination">
|
||||||
<TMagicPagination
|
<TMagicPagination
|
||||||
|
Loading…
x
Reference in New Issue
Block a user