mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
fix(editor): 在组件属性配置表单中编辑数据源方法无法保存问题
This commit is contained in:
parent
92049cf251
commit
b1e79c1e05
@ -110,6 +110,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
import { provide } from 'vue';
|
import { provide } from 'vue';
|
||||||
|
|
||||||
import type { MApp } from '@tmagic/schema';
|
import type { MApp } from '@tmagic/schema';
|
||||||
@ -134,7 +136,7 @@ import uiService from './services/ui';
|
|||||||
import keybindingConfig from './utils/keybinding-config';
|
import keybindingConfig from './utils/keybinding-config';
|
||||||
import { defaultEditorProps, EditorProps } from './editorProps';
|
import { defaultEditorProps, EditorProps } from './editorProps';
|
||||||
import { initServiceEvents, initServiceState } from './initService';
|
import { initServiceEvents, initServiceState } from './initService';
|
||||||
import type { FrameworkSlots, PropsPanelSlots, Services, SidebarSlots, WorkspaceSlots } from './type';
|
import type { EventBus, FrameworkSlots, PropsPanelSlots, Services, SidebarSlots, WorkspaceSlots } from './type';
|
||||||
|
|
||||||
defineSlots<
|
defineSlots<
|
||||||
FrameworkSlots &
|
FrameworkSlots &
|
||||||
@ -203,5 +205,7 @@ provide('services', services);
|
|||||||
provide('codeOptions', props.codeOptions);
|
provide('codeOptions', props.codeOptions);
|
||||||
provide('stageOptions', stageOptions);
|
provide('stageOptions', stageOptions);
|
||||||
|
|
||||||
|
provide<EventBus>('eventBus', new EventEmitter());
|
||||||
|
|
||||||
defineExpose(services);
|
defineExpose(services);
|
||||||
</script>
|
</script>
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
<div class="m-fields-code-select-col">
|
<div class="m-fields-code-select-col">
|
||||||
<div class="code-select-container">
|
<div class="code-select-container">
|
||||||
<!-- 代码块下拉框 -->
|
<!-- 代码块下拉框 -->
|
||||||
<m-form-container
|
<MContainer
|
||||||
class="select"
|
class="select"
|
||||||
:config="selectConfig"
|
:config="selectConfig"
|
||||||
:model="model"
|
:model="model"
|
||||||
:size="size"
|
:size="size"
|
||||||
@change="onParamsChangeHandler"
|
@change="onParamsChangeHandler"
|
||||||
></m-form-container>
|
></MContainer>
|
||||||
<!-- 查看/编辑按钮 -->
|
<!-- 查看/编辑按钮 -->
|
||||||
<Icon v-if="model[name]" class="icon" :icon="!notEditable ? Edit : View" @click="editCode(model[name])"></Icon>
|
<Icon v-if="model[name]" class="icon" :icon="!notEditable ? Edit : View" @click="editCode(model[name])"></Icon>
|
||||||
</div>
|
</div>
|
||||||
@ -23,14 +23,6 @@
|
|||||||
:params-config="paramsConfig"
|
:params-config="paramsConfig"
|
||||||
@change="onParamsChangeHandler"
|
@change="onParamsChangeHandler"
|
||||||
></CodeParams>
|
></CodeParams>
|
||||||
|
|
||||||
<CodeBlockEditor
|
|
||||||
ref="codeBlockEditor"
|
|
||||||
v-if="codeConfig"
|
|
||||||
:disabled="notEditable"
|
|
||||||
:content="codeConfig"
|
|
||||||
@submit="submitCodeBlockHandler"
|
|
||||||
></CodeBlockEditor>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -39,14 +31,12 @@ import { computed, inject, ref, watch } from 'vue';
|
|||||||
import { Edit, View } from '@element-plus/icons-vue';
|
import { Edit, View } from '@element-plus/icons-vue';
|
||||||
import { isEmpty, map } from 'lodash-es';
|
import { isEmpty, map } from 'lodash-es';
|
||||||
|
|
||||||
import { createValues, type FieldProps, filterFunction, type FormState } from '@tmagic/form';
|
import { createValues, type FieldProps, filterFunction, type FormState, MContainer } from '@tmagic/form';
|
||||||
import type { Id } from '@tmagic/schema';
|
import type { Id } from '@tmagic/schema';
|
||||||
|
|
||||||
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
||||||
import CodeParams from '@editor/components/CodeParams.vue';
|
import CodeParams from '@editor/components/CodeParams.vue';
|
||||||
import Icon from '@editor/components/Icon.vue';
|
import Icon from '@editor/components/Icon.vue';
|
||||||
import { useCodeBlockEdit } from '@editor/hooks/use-code-block-edit';
|
import type { CodeParamStatement, CodeSelectColConfig, EventBus, Services } from '@editor/type';
|
||||||
import type { CodeParamStatement, CodeSelectColConfig, Services } from '@editor/type';
|
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'MFieldsCodeSelectCol',
|
name: 'MFieldsCodeSelectCol',
|
||||||
@ -54,6 +44,7 @@ defineOptions({
|
|||||||
|
|
||||||
const mForm = inject<FormState | undefined>('mForm');
|
const mForm = inject<FormState | undefined>('mForm');
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
|
const eventBus = inject<EventBus>('eventBus');
|
||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
||||||
@ -127,5 +118,7 @@ const onParamsChangeHandler = (value: any) => {
|
|||||||
emit('change', props.model);
|
emit('change', props.model);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { codeBlockEditor, codeConfig, editCode, submitCodeBlockHandler } = useCodeBlockEdit(services?.codeBlockService);
|
const editCode = (id: string) => {
|
||||||
|
eventBus?.emit('edit-code', id);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -29,14 +29,6 @@
|
|||||||
@click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
|
@click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
|
||||||
><MIcon :icon="Coin"></MIcon
|
><MIcon :icon="Coin"></MIcon
|
||||||
></TMagicButton>
|
></TMagicButton>
|
||||||
|
|
||||||
<DataSourceConfigPanel
|
|
||||||
ref="editDialog"
|
|
||||||
:disabled="!editable"
|
|
||||||
:values="dataSourceValues"
|
|
||||||
:title="dialogTitle"
|
|
||||||
@submit="submitDataSourceHandler"
|
|
||||||
></DataSourceConfigPanel>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -51,15 +43,14 @@ import type { DataSchema, DataSourceFieldType } from '@tmagic/schema';
|
|||||||
import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
|
import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
|
||||||
|
|
||||||
import MIcon from '@editor/components/Icon.vue';
|
import MIcon from '@editor/components/Icon.vue';
|
||||||
import { useDataSourceEdit } from '@editor/hooks/use-data-source-edit';
|
import type { DataSourceFieldSelectConfig, EventBus, Services } from '@editor/type';
|
||||||
import DataSourceConfigPanel from '@editor/layouts/sidebar/data-source/DataSourceConfigPanel.vue';
|
|
||||||
import type { DataSourceFieldSelectConfig, Services } from '@editor/type';
|
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'MFieldsDataSourceFieldSelect',
|
name: 'MFieldsDataSourceFieldSelect',
|
||||||
});
|
});
|
||||||
|
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
|
const eventBus = inject<EventBus>('eventBus');
|
||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(), {
|
const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(), {
|
||||||
@ -181,7 +172,7 @@ const onChangeHandler = (value: any) => {
|
|||||||
emit('change', value);
|
emit('change', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } = useDataSourceEdit(
|
const editHandler = (id: string) => {
|
||||||
services?.dataSourceService,
|
eventBus?.emit('edit-data-source', id);
|
||||||
);
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="m-fields-data-source-method-select">
|
<div class="m-fields-data-source-method-select">
|
||||||
<div class="data-source-method-select-container">
|
<div class="data-source-method-select-container">
|
||||||
<m-form-container
|
<MContainer
|
||||||
class="select"
|
class="select"
|
||||||
:config="cascaderConfig"
|
:config="cascaderConfig"
|
||||||
:model="model"
|
:model="model"
|
||||||
|
:size="size"
|
||||||
@change="onChangeHandler"
|
@change="onChangeHandler"
|
||||||
></m-form-container>
|
></MContainer>
|
||||||
<Icon
|
<Icon
|
||||||
v-if="model[name] && isCustomMethod"
|
v-if="model[name] && isCustomMethod"
|
||||||
class="icon"
|
class="icon"
|
||||||
@ -24,14 +25,6 @@
|
|||||||
:params-config="paramsConfig"
|
:params-config="paramsConfig"
|
||||||
@change="onChangeHandler"
|
@change="onChangeHandler"
|
||||||
></CodeParams>
|
></CodeParams>
|
||||||
|
|
||||||
<CodeBlockEditor
|
|
||||||
ref="codeBlockEditor"
|
|
||||||
v-if="codeConfig"
|
|
||||||
:disabled="notEditable"
|
|
||||||
:content="codeConfig"
|
|
||||||
@submit="submitCodeBlockHandler"
|
|
||||||
></CodeBlockEditor>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -39,14 +32,12 @@
|
|||||||
import { computed, inject, ref } from 'vue';
|
import { computed, inject, ref } from 'vue';
|
||||||
import { Edit, View } from '@element-plus/icons-vue';
|
import { Edit, View } from '@element-plus/icons-vue';
|
||||||
|
|
||||||
import { createValues, type FieldProps, filterFunction, type FormState } from '@tmagic/form';
|
import { createValues, type FieldProps, filterFunction, type FormState, MContainer } from '@tmagic/form';
|
||||||
import type { CodeBlockContent, Id } from '@tmagic/schema';
|
import type { Id } from '@tmagic/schema';
|
||||||
|
|
||||||
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
||||||
import CodeParams from '@editor/components/CodeParams.vue';
|
import CodeParams from '@editor/components/CodeParams.vue';
|
||||||
import Icon from '@editor/components/Icon.vue';
|
import Icon from '@editor/components/Icon.vue';
|
||||||
import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
import type { CodeParamStatement, DataSourceMethodSelectConfig, EventBus, Services } from '@editor/type';
|
||||||
import type { CodeParamStatement, DataSourceMethodSelectConfig, Services } from '@editor/type';
|
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'MFieldsDataSourceMethodSelect',
|
name: 'MFieldsDataSourceMethodSelect',
|
||||||
@ -54,6 +45,8 @@ defineOptions({
|
|||||||
|
|
||||||
const mForm = inject<FormState | undefined>('mForm');
|
const mForm = inject<FormState | undefined>('mForm');
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
|
const eventBus = inject<EventBus>('eventBus');
|
||||||
|
|
||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
const dataSourceService = services?.dataSourceService;
|
const dataSourceService = services?.dataSourceService;
|
||||||
@ -139,21 +132,13 @@ const onChangeHandler = (value: any) => {
|
|||||||
emit('change', props.model);
|
emit('change', props.model);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { codeBlockEditor, codeConfig, editCode, submitCode } = useDataSourceMethod();
|
|
||||||
|
|
||||||
const editCodeHandler = () => {
|
const editCodeHandler = () => {
|
||||||
const [id, name] = props.model[props.name];
|
const [id] = props.model[props.name];
|
||||||
|
|
||||||
const dataSource = dataSourceService?.getDataSourceById(id);
|
const dataSource = dataSourceService?.getDataSourceById(id);
|
||||||
|
|
||||||
if (!dataSource) return;
|
if (!dataSource) return;
|
||||||
|
|
||||||
editCode(dataSource, name);
|
eventBus?.emit('edit-data-source', id);
|
||||||
|
|
||||||
setParamsConfig([id, name]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const submitCodeBlockHandler = (value: CodeBlockContent) => {
|
|
||||||
submitCode(value);
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<TMagicButton class="create-button" type="primary" :size="size" :disabled="disabled" @click="addEvent()"
|
<TMagicButton class="create-button" type="primary" :size="size" :disabled="disabled" @click="addEvent()"
|
||||||
>添加事件</TMagicButton
|
>添加事件</TMagicButton
|
||||||
>
|
>
|
||||||
<m-form-panel
|
<MPanel
|
||||||
v-for="(cardItem, index) in model[name]"
|
v-for="(cardItem, index) in model[name]"
|
||||||
:key="index"
|
:key="index"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
@ -26,14 +26,14 @@
|
|||||||
@change="onChangeHandler"
|
@change="onChangeHandler"
|
||||||
>
|
>
|
||||||
<template #header>
|
<template #header>
|
||||||
<m-form-container
|
<MContainer
|
||||||
class="fullWidth"
|
class="fullWidth"
|
||||||
:config="eventNameConfig"
|
:config="eventNameConfig"
|
||||||
:model="cardItem"
|
:model="cardItem"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:size="size"
|
:size="size"
|
||||||
@change="onChangeHandler"
|
@change="onChangeHandler"
|
||||||
></m-form-container>
|
></MContainer>
|
||||||
<TMagicButton
|
<TMagicButton
|
||||||
style="color: #f56c6c"
|
style="color: #f56c6c"
|
||||||
link
|
link
|
||||||
@ -43,7 +43,7 @@
|
|||||||
@click="removeEvent(index)"
|
@click="removeEvent(index)"
|
||||||
></TMagicButton>
|
></TMagicButton>
|
||||||
</template>
|
</template>
|
||||||
</m-form-panel>
|
</MPanel>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -55,7 +55,8 @@ import { has } from 'lodash-es';
|
|||||||
|
|
||||||
import type { EventOption } from '@tmagic/core';
|
import type { EventOption } from '@tmagic/core';
|
||||||
import { TMagicButton } from '@tmagic/design';
|
import { TMagicButton } from '@tmagic/design';
|
||||||
import type { FieldProps, FormState } from '@tmagic/form';
|
import type { FieldProps, FormState, PanelConfig } from '@tmagic/form';
|
||||||
|
import { MContainer, MPanel } from '@tmagic/form';
|
||||||
import { ActionType } from '@tmagic/schema';
|
import { ActionType } from '@tmagic/schema';
|
||||||
|
|
||||||
import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
|
import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
|
||||||
@ -227,7 +228,8 @@ const tableConfig = computed(() => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// 组件动作组表单配置
|
// 组件动作组表单配置
|
||||||
const actionsConfig = computed(() => ({
|
const actionsConfig = computed<PanelConfig>(() => ({
|
||||||
|
type: 'panel',
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'group-list',
|
type: 'group-list',
|
||||||
|
@ -36,7 +36,7 @@ import type { Id } from '@tmagic/schema';
|
|||||||
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
||||||
import SearchInput from '@editor/components/SearchInput.vue';
|
import SearchInput from '@editor/components/SearchInput.vue';
|
||||||
import { useCodeBlockEdit } from '@editor/hooks/use-code-block-edit';
|
import { useCodeBlockEdit } from '@editor/hooks/use-code-block-edit';
|
||||||
import type { CodeBlockListPanelSlots, CodeDeleteErrorType, Services } from '@editor/type';
|
import type { CodeBlockListPanelSlots, CodeDeleteErrorType, EventBus, Services } from '@editor/type';
|
||||||
|
|
||||||
import CodeBlockList from './CodeBlockList.vue';
|
import CodeBlockList from './CodeBlockList.vue';
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ defineProps<{
|
|||||||
customError?: (id: Id, errorType: CodeDeleteErrorType) => any;
|
customError?: (id: Id, errorType: CodeDeleteErrorType) => any;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const eventBus = inject<EventBus>('eventBus');
|
||||||
const { codeBlockService } = inject<Services>('services') || {};
|
const { codeBlockService } = inject<Services>('services') || {};
|
||||||
|
|
||||||
const editable = computed(() => codeBlockService?.getEditStatus());
|
const editable = computed(() => codeBlockService?.getEditStatus());
|
||||||
@ -62,4 +63,8 @@ const codeBlockList = ref<InstanceType<typeof CodeBlockList>>();
|
|||||||
const filterTextChangeHandler = (val: string) => {
|
const filterTextChangeHandler = (val: string) => {
|
||||||
codeBlockList.value?.filter(val);
|
codeBlockList.value?.filter(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
eventBus?.on('edit-code', (id: string) => {
|
||||||
|
editCode(id);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -46,7 +46,7 @@ import { TMagicButton, TMagicPopover, TMagicScrollbar } from '@tmagic/design';
|
|||||||
import SearchInput from '@editor/components/SearchInput.vue';
|
import SearchInput from '@editor/components/SearchInput.vue';
|
||||||
import ToolButton from '@editor/components/ToolButton.vue';
|
import ToolButton from '@editor/components/ToolButton.vue';
|
||||||
import { useDataSourceEdit } from '@editor/hooks/use-data-source-edit';
|
import { useDataSourceEdit } from '@editor/hooks/use-data-source-edit';
|
||||||
import type { DataSourceListSlots, Services } from '@editor/type';
|
import type { DataSourceListSlots, EventBus, Services } from '@editor/type';
|
||||||
|
|
||||||
import DataSourceConfigPanel from './DataSourceConfigPanel.vue';
|
import DataSourceConfigPanel from './DataSourceConfigPanel.vue';
|
||||||
import DataSourceList from './DataSourceList.vue';
|
import DataSourceList from './DataSourceList.vue';
|
||||||
@ -57,6 +57,7 @@ defineOptions({
|
|||||||
name: 'MEditorDataSourceListPanel',
|
name: 'MEditorDataSourceListPanel',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const eventBus = inject<EventBus>('eventBus');
|
||||||
const { dataSourceService } = inject<Services>('services') || {};
|
const { dataSourceService } = inject<Services>('services') || {};
|
||||||
|
|
||||||
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
|
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
|
||||||
@ -98,4 +99,8 @@ const dataSourceList = ref<InstanceType<typeof DataSourceList>>();
|
|||||||
const filterTextChangeHandler = (val: string) => {
|
const filterTextChangeHandler = (val: string) => {
|
||||||
dataSourceList.value?.filter(val);
|
dataSourceList.value?.filter(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
eventBus?.on('edit-data-source', (id: string) => {
|
||||||
|
editHandler(id);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Component } from 'vue';
|
import type { Component } from 'vue';
|
||||||
|
import type EventEmitter from 'events';
|
||||||
import type { PascalCasedProperties } from 'type-fest';
|
import type { PascalCasedProperties } from 'type-fest';
|
||||||
|
|
||||||
import type { ChildConfig, ColumnConfig, FilterFunction, FormConfig, FormItem, Input } from '@tmagic/form';
|
import type { ChildConfig, ColumnConfig, FilterFunction, FormConfig, FormItem, Input } from '@tmagic/form';
|
||||||
@ -714,3 +715,16 @@ export type SyncHookPlugin<
|
|||||||
C extends Record<T[number], (...args: any) => any>,
|
C extends Record<T[number], (...args: any) => any>,
|
||||||
> = AddPrefixToObject<PascalCasedProperties<SyncBeforeHook<T, C>>, 'before'> &
|
> = AddPrefixToObject<PascalCasedProperties<SyncBeforeHook<T, C>>, 'before'> &
|
||||||
AddPrefixToObject<PascalCasedProperties<SyncAfterHook<T, C>>, 'after'>;
|
AddPrefixToObject<PascalCasedProperties<SyncAfterHook<T, C>>, 'after'>;
|
||||||
|
|
||||||
|
export interface EventBusEvent {
|
||||||
|
'edit-data-source': [id: string];
|
||||||
|
'edit-code': [id: string];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EventBus extends EventEmitter {
|
||||||
|
on<Name extends keyof EventBusEvent, Param extends EventBusEvent[Name]>(
|
||||||
|
eventName: Name,
|
||||||
|
listener: (...args: Param) => void,
|
||||||
|
): this;
|
||||||
|
emit<Name extends keyof EventBusEvent, Param extends EventBusEvent[Name]>(eventName: Name, ...args: Param): boolean;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user