From fa932d66940ae945c7470d78e127d57dbc9a737a Mon Sep 17 00:00:00 2001 From: allenve Date: Mon, 25 Nov 2024 15:54:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A8=E5=B1=80=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E9=85=8D=E7=BD=AE=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../otherActionsPanel/broadcast.tsx | 74 +++++++++++++++++++ .../otherActionsPanel/index.ts | 1 + .../event-control/eventControlConfigHelper.ts | 4 +- 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/broadcast.tsx diff --git a/packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/broadcast.tsx b/packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/broadcast.tsx new file mode 100644 index 00000000000..8a9dd61c80e --- /dev/null +++ b/packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/broadcast.tsx @@ -0,0 +1,74 @@ +import React from 'react'; +import {registerActionPanel} from '../../actionsPanelManager'; +import {getSchemaTpl, EditorManager} from 'amis-editor-core'; + +registerActionPanel('broadcast', { + label: '全局广播事件', + tag: '其他', + description: '触发全局广播事件', + innerArgs: [], + descDetail: (info: any, context: any, props: any) => { + const globalEvents = props.globalEvents || []; + const event = globalEvents.find( + (item: any) => item.name === info?.eventName + ); + return ( +
+ 触发 + {event?.label || info?.eventName} + 全局广播事件 +
+ ); + }, + schema: (manager: EditorManager) => { + const globalEvents = + manager.config?.actionOptions?.globalEventGetter?.(manager) || []; + return { + type: 'wrapper', + body: [ + { + type: 'select', + name: 'eventName', + required: true, + label: '请选择全局事件', + options: globalEvents.map(item => ({ + label: item.label, + value: item.name, + mapping: item.mapping + })), + size: 'lg', + mode: 'horizontal', + initAutoFill: true, + autoFill: { + __mapping: '${mapping}' + }, + onChange: async (val: any, oldVal: any, props: any, form: any) => { + form.setValueByName('data', void 0); + } + }, + { + type: 'input-kv', + name: 'data', + label: '参数映射', + mode: 'horizontal', + draggable: false, + visibleOn: 'this.eventName', + keySchema: { + type: 'select', + label: false, + name: 'key', + source: '${ARRAYMAP(__mapping, i => i.key)}' + }, + valueSchema: getSchemaTpl('tplFormulaControl', { + label: false, + name: 'value', + clearable: true, + placeholder: '请输入参数值', + variables: '${variables}', + header: '配置参数值' + }) + } + ] + }; + } +}); diff --git a/packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/index.ts b/packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/index.ts index f8d49ff1843..dcdeea3efb8 100644 --- a/packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/index.ts +++ b/packages/amis-editor/src/renderer/event-control/actionsPanelPlugins/otherActionsPanel/index.ts @@ -1,2 +1,3 @@ import './copy'; import './custom'; +import './broadcast'; diff --git a/packages/amis-editor/src/renderer/event-control/eventControlConfigHelper.ts b/packages/amis-editor/src/renderer/event-control/eventControlConfigHelper.ts index 7c4e998a836..c6ed96f25af 100644 --- a/packages/amis-editor/src/renderer/event-control/eventControlConfigHelper.ts +++ b/packages/amis-editor/src/renderer/event-control/eventControlConfigHelper.ts @@ -403,7 +403,9 @@ export const actionConfigInitFormatterHoc = } } - delete config.data; + if (config.actionType !== 'broadcast') { + delete config.data; + } // 处理下 addItem 的初始化 if (action.actionType === 'addItem') {