diff --git a/packages/designer/src/components/composition/events-editor-utils.ts b/packages/designer/src/components/composition/events-editor-utils.ts index ecfda42e44fdeb8085c887a6d7135a3b85c8ae09..a05730086b74258414dd60aff9eee7a0d856dcd0 100644 --- a/packages/designer/src/components/composition/events-editor-utils.ts +++ b/packages/designer/src/components/composition/events-editor-utils.ts @@ -152,7 +152,7 @@ export function useEventsEditorUtils(commandService: UseFormCommandService, form } }; parameters.boundEventsList.forEach(boundEventItem => { - if (!boundEventItem.command) { + if (!boundEventItem.command?.id) { return; } const mapItem: EventsEditorMapItem = { diff --git a/packages/designer/src/components/composition/use-form-schema.ts b/packages/designer/src/components/composition/use-form-schema.ts index cd75efa33d45f730bab374e49252aa8ea3fcd935..84dc6ced8a3dcda3799f05ef83d15f0ce4d5b601 100644 --- a/packages/designer/src/components/composition/use-form-schema.ts +++ b/packages/designer/src/components/composition/use-form-schema.ts @@ -2,7 +2,7 @@ import { cloneDeep, mergeWith } from "lodash-es"; import { FormBindingType, FormComponent, FormMetaDataModule, FormMetadaDataDom, FormSchema, FormSchemaEntity, FormSchemaEntityField, FormVariable, FormVariableCategory, FormVariableTypes, FormViewModel, FormViewModelField, FormWebCmd, MetadataDto, UseFormSchema, FormExpression, ExternalFormMetadata } from "../types"; import { NodeType, Node } from "../types/events-editor"; import { inject } from "vue"; -import { LookupSchemaRepositoryToken } from "@farris/ui-vue/components"; +import { LookupSchemaRepositoryToken, schemaMap } from "@farris/ui-vue/components"; import { LookupSchemaService } from "./schema-repository/lookup/lookup-schema.service"; import { DesignerMode } from "../types/designer-context"; @@ -1247,6 +1247,25 @@ export function useFormSchema(): UseFormSchema { } } + /** + * 删除控件相关的组件通讯 + */ + function removeCommunicationInComponent(componentSchema: any) { + if (!componentSchema || !formSchema.module.communications?.length) { + return; + } + + const controlEventPropertyIDList = schemaMap[componentSchema.type]?.events; + if (controlEventPropertyIDList) { + Object.keys(controlEventPropertyIDList).forEach(propertyId => { + const propertyValue = componentSchema[propertyId]; + if (propertyValue && propertyValue.includes('communication:')) { + const communicationIds = propertyValue.replace('communication:', '').split(';'); + formSchema.module.communications = formSchema.module.communications?.filter(communication => !communicationIds.includes(communication.id)); + } + }); + } + } return { getModule, setViewmodels, @@ -1290,6 +1309,7 @@ export function useFormSchema(): UseFormSchema { externalFormSchema, getComponetsByPredicate, getDefaultValueByFiledAndType, - designerMode + designerMode, + removeCommunicationInComponent }; } diff --git a/packages/designer/src/components/types/metadata.ts b/packages/designer/src/components/types/metadata.ts index 42d71030d016988ea5f25b58f843deeac26ac995..e89043ab1180c5725b357d96c231ffafe99087a1 100644 --- a/packages/designer/src/components/types/metadata.ts +++ b/packages/designer/src/components/types/metadata.ts @@ -5,6 +5,7 @@ import { DesignViewModel } from "./design-viewmodel"; import { DesignerMode, UseDesignerContext } from "./designer-context"; import { FormSchema, FormSchemaEntity, FormSchemaEntityField } from "./entity-schema"; import { FormVariable, FormViewModel, FormViewModelField } from "./view-model"; +import { Communication } from '@farris/ui-vue/components/events-editor'; export interface FormOptions { /** @@ -107,6 +108,9 @@ export interface FormMetaDataModule { metadataId?: string; hiddenComponents: ExternalComponentSchema[]; + + /** 组件通讯 */ + communications?: Array; } export interface FormMetadaDataDom { @@ -239,6 +243,7 @@ export interface UseFormSchema { getDefaultValueByFiledAndType: (propertyType: string, schema: FormSchemaEntityField) => any; getSchemaEntities: () => FormSchemaEntity[]; getComponetsByPredicate(predicate: (component: any) => boolean); + removeCommunicationInComponent: (componentSchema: any) => void; } export interface UseSchemaService { diff --git a/packages/ui-vue/components/designer-canvas/src/composition/function/use-designer-component.ts b/packages/ui-vue/components/designer-canvas/src/composition/function/use-designer-component.ts index d1db5a781705b9e625762a866a5e91c0778c053a..5cb895b373017ba3d211d66443b265c4db03ba66 100644 --- a/packages/ui-vue/components/designer-canvas/src/composition/function/use-designer-component.ts +++ b/packages/ui-vue/components/designer-canvas/src/composition/function/use-designer-component.ts @@ -184,6 +184,18 @@ export function useDesignerComponent( } } + /** + * 删除控件相关的组件通讯 + */ + function removeCommunicationInComponent(designerHostService: DesignerHostService) { + if (!designerHostService || !designItemContext?.schema) { + return; + } + const componentSchema = designItemContext.schema; + const { formSchemaUtils } = designerHostService; + formSchemaUtils.removeCommunicationInComponent(componentSchema); + } + /** * 控件删除后事件 */ @@ -196,6 +208,9 @@ export function useDesignerComponent( // 若控件配置了表达式,需要删除表达式 removeExpressionsInComponent(designerHostService); + // 若控件触发了组件通讯,需要删除通讯配置 + removeCommunicationInComponent(designerHostService); + // 递归触发子级控件的删除后事件 if (designItemContext?.schema.contents) { designItemContext.schema.contents.map(content => { diff --git a/packages/ui-vue/components/events-editor/src/components/command-source/command-source.component.tsx b/packages/ui-vue/components/events-editor/src/components/command-source/command-source.component.tsx index 9706cef7005be94987048fe9791879edb5c87416..73c60181b9b1263129032a12df4d85e0c8b8f913 100644 --- a/packages/ui-vue/components/events-editor/src/components/command-source/command-source.component.tsx +++ b/packages/ui-vue/components/events-editor/src/components/command-source/command-source.component.tsx @@ -90,7 +90,7 @@ export default defineComponent({ * @param selectedController 控制器元数据 */ async function onSubmitController(selectedController: any) { - formCommandService['getSupportedControllerMetadata']().then((result: any) => { + formCommandService['getSupportedControllerMetadata'](selectedController).then((result: any) => { if (result) { // 引入控制器 importNewController(result['controller'], result['code'], result['nameSpace']); diff --git a/packages/ui-vue/components/events-editor/src/types.ts b/packages/ui-vue/components/events-editor/src/types.ts index bde84623f1cb0a22d5506a27a6217f5f5351346e..dd8076eb44149fc468017b2c3ee56609da8a2694 100644 --- a/packages/ui-vue/components/events-editor/src/types.ts +++ b/packages/ui-vue/components/events-editor/src/types.ts @@ -214,3 +214,4 @@ export interface InteractionItem { communication?: Communication | null; } +export * from "./components/combine-form/types"; diff --git a/packages/ui-vue/components/external-container/src/schema/external-container.schema.json b/packages/ui-vue/components/external-container/src/schema/external-container.schema.json index d8018464bbb60da795be52921e5841777d21cc6e..024f8c90bd22cc31ab9909ee3535f7f787fd5d94 100644 --- a/packages/ui-vue/components/external-container/src/schema/external-container.schema.json +++ b/packages/ui-vue/components/external-container/src/schema/external-container.schema.json @@ -47,5 +47,8 @@ "id", "type", "externalComponent" - ] + ], + "events": { + "onCommunication": "通讯事件" + } } \ No newline at end of file diff --git a/packages/ui-vue/components/response-toolbar/src/designer/use-designer-item-rules.ts b/packages/ui-vue/components/response-toolbar/src/designer/use-designer-item-rules.ts index f4219aed6057ac8ea931d82dd69e2586ab4e6641..927a800fff39c16bb2164acaf9228ba9637861e6 100644 --- a/packages/ui-vue/components/response-toolbar/src/designer/use-designer-item-rules.ts +++ b/packages/ui-vue/components/response-toolbar/src/designer/use-designer-item-rules.ts @@ -181,6 +181,19 @@ export function useDesignerItemRules(designerItemContext: DesignerItemContext, d actionHandlers.changeSelectedId(id); } + /** + * 若按钮触发了组件通讯,需要删除通讯配置 + */ + function deleteCommunication(toolbarItem: any) { + designerHostService.formSchemaUtils.removeCommunicationInComponent(toolbarItem); + + if (toolbarItem.children && toolbarItem.children.length) { + toolbarItem.children.forEach(item => { + designerHostService.formSchemaUtils.removeCommunicationInComponent(item); + }); + } + + } /** * 删除下拉项 * @returns @@ -195,6 +208,8 @@ export function useDesignerItemRules(designerItemContext: DesignerItemContext, d return; } deleteExpression(designerItemContext.schema); + deleteCommunication(designerItemContext.schema); + buttons[parentIndex].children.splice(itemIndex, 1); actionHandlers.updateToolbarItems(); designerItemContext.setupContext?.emit('removeComponent'); @@ -217,6 +232,8 @@ export function useDesignerItemRules(designerItemContext: DesignerItemContext, d return; } deleteExpression(buttons[index]); + deleteCommunication(buttons[index]); + buttons?.splice(index, 1); // 更新Tab工具栏 actionHandlers.updateToolbarItems(); diff --git a/packages/ui-vue/components/section/src/components/toolbar.component.tsx b/packages/ui-vue/components/section/src/components/toolbar.component.tsx index 8d4e3275afd8c3f1ad1ab15b9efffe1b27b08f18..70a2ae16dd20d56ac79871a2970c37b39e082e96 100644 --- a/packages/ui-vue/components/section/src/components/toolbar.component.tsx +++ b/packages/ui-vue/components/section/src/components/toolbar.component.tsx @@ -28,9 +28,9 @@ export default function (props: SectionProps, context: SetupContext) { * @returns */ function renderToolbarTemplate() { - return
{props.toolbarRenderFunction()}
+ return
{props.toolbarRenderFunction()}
; } return () => { - return props.toolbarRenderFunction?renderToolbarTemplate():renderDefaultToolbar() + return props.toolbarRenderFunction?renderToolbarTemplate():renderDefaultToolbar(); }; } diff --git a/packages/ui-vue/components/section/src/designer/section-toolbar.design.component.tsx b/packages/ui-vue/components/section/src/designer/section-toolbar.design.component.tsx index 628969a47f61efe43d41470029a1b2e6279aefc5..472a7e1941a0fbb6a6176b17b457a1c8e56d3b33 100644 --- a/packages/ui-vue/components/section/src/designer/section-toolbar.design.component.tsx +++ b/packages/ui-vue/components/section/src/designer/section-toolbar.design.component.tsx @@ -51,7 +51,7 @@ export default function ( * @returns */ function renderToolbarTemplate() { - return
+ return
; } return props.toolbarHtml?.trim() ? renderToolbarTemplate() : renderDefaultToolbar(); }