From 4bb0bd5a898f27913eb0ed9bf894bca76706c6b9 Mon Sep 17 00:00:00 2001 From: allenve Date: Wed, 20 Nov 2024 14:20:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=85=A8=E5=B1=80=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=8A=A8=E4=BD=9C=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 --- packages/amis-editor-core/src/plugin.ts | 1 + .../src/renderer/event-control/helper.tsx | 4 +- .../src/renderer/event-control/index.tsx | 46 +++++++++++++++---- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/packages/amis-editor-core/src/plugin.ts b/packages/amis-editor-core/src/plugin.ts index 78e5a41fb..882252f8c 100644 --- a/packages/amis-editor-core/src/plugin.ts +++ b/packages/amis-editor-core/src/plugin.ts @@ -506,6 +506,7 @@ export interface RendererJSONSchemaResolveEventContext } export interface IGlobalEvent { + label: string; name: string; // 事件名称,唯一 description: string; // 事件描述 mapping: Array<{ diff --git a/packages/amis-editor/src/renderer/event-control/helper.tsx b/packages/amis-editor/src/renderer/event-control/helper.tsx index 19e4e779b..57df3e9af 100644 --- a/packages/amis-editor/src/renderer/event-control/helper.tsx +++ b/packages/amis-editor/src/renderer/event-control/helper.tsx @@ -3218,7 +3218,9 @@ export const getEventControlConfig = ( } } - delete config.data; + if (config.actionType !== 'broadcast') { + delete config.data; + } // 处理下 addItem 的初始化 if (action.actionType === 'addItem') { diff --git a/packages/amis-editor/src/renderer/event-control/index.tsx b/packages/amis-editor/src/renderer/event-control/index.tsx index 1ad6bdb3f..3022d4e45 100644 --- a/packages/amis-editor/src/renderer/event-control/index.tsx +++ b/packages/amis-editor/src/renderer/event-control/index.tsx @@ -152,7 +152,7 @@ export class EventControl extends React.Component< constructor(props: EventControlProps) { super(props); - const {events, value, data, rawType} = props; + const {events, value, data, rawType, globalEvents} = props; const eventPanelActive: { [prop: string]: boolean; @@ -169,6 +169,10 @@ export class EventControl extends React.Component< eventPanelActive[event.eventName] = true; }); + globalEvents?.forEach(event => { + eventPanelActive[event.name] = true; + }); + this.state = { onEvent: value ?? this.generateEmptyDefault(pluginEvents), events: pluginEvents, @@ -619,14 +623,16 @@ export class EventControl extends React.Component< actionTree, actions: pluginActions, commonActions, - allComponents + allComponents, + globalEvents } = this.props; const {events, onEvent} = this.state; - const eventConfig = events.find( item => item.eventName === data.actionData!.eventKey ); - + const globalEventConfig = globalEvents?.find( + item => item.name === data.actionData!.eventKey + ); // 收集当前事件动作出参 let actions = onEvent[data.actionData!.eventKey].actions; @@ -642,11 +648,33 @@ export class EventControl extends React.Component< let jsonSchema: any = {}; - // 动态构建事件参数 - if (typeof eventConfig?.dataSchema === 'function') { - jsonSchema = eventConfig.dataSchema(manager)?.[0]; + if (globalEventConfig) { + jsonSchema = { + type: 'object', + properties: { + data: { + type: 'object', + title: '数据', + properties: (globalEventConfig.mapping || []).reduce( + (acc: any, item) => { + acc[item.key] = { + type: item.type, + title: `${item.key}(全局事件参数)` + }; + return acc; + }, + {} + ) + } + } + }; } else { - jsonSchema = {...(eventConfig?.dataSchema?.[0] ?? {})}; + // 动态构建事件参数 + if (typeof eventConfig?.dataSchema === 'function') { + jsonSchema = eventConfig.dataSchema(manager)?.[0]; + } else { + jsonSchema = {...(eventConfig?.dataSchema?.[0] ?? {})}; + } } actions @@ -1174,7 +1202,7 @@ export class EventControl extends React.Component< tooltipPlacement: 'left', disabled: Object.keys(onEvent).includes(item.name), actionType: '', - label: item.name, + label: item.label, onClick: this.addGlobalEvent.bind( this, item, From 5279ebfb3d37b0391cc0822a49994e83a6bc81f4 Mon Sep 17 00:00:00 2001 From: allenve Date: Wed, 20 Nov 2024 14:33:54 +0800 Subject: [PATCH 2/2] fix: ts check --- packages/amis-editor/examples/Editor.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/amis-editor/examples/Editor.tsx b/packages/amis-editor/examples/Editor.tsx index 55023276d..e0bf4cb51 100644 --- a/packages/amis-editor/examples/Editor.tsx +++ b/packages/amis-editor/examples/Editor.tsx @@ -318,6 +318,7 @@ const editorLanguages = [ const globalEvents = [ { name: 'globalEventA', + label: '全局事件A', description: '全局事件动作A', mapping: [ { @@ -332,6 +333,7 @@ const globalEvents = [ }, { name: 'globalEventB', + label: '全局事件B', description: '全局事件动作A', mapping: [ {