Merge pull request #11228 from allenve/feat-globalevent-panel

feat: 全局事件动作配置面板
This commit is contained in:
Allen 2024-11-20 14:49:53 +08:00 committed by GitHub
commit 66fc73b18c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 10 deletions

View File

@ -506,6 +506,7 @@ export interface RendererJSONSchemaResolveEventContext
}
export interface IGlobalEvent {
label: string;
name: string; // 事件名称,唯一
description: string; // 事件描述
mapping: Array<{

View File

@ -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: [
{

View File

@ -3218,7 +3218,9 @@ export const getEventControlConfig = (
}
}
delete config.data;
if (config.actionType !== 'broadcast') {
delete config.data;
}
// 处理下 addItem 的初始化
if (action.actionType === 'addItem') {

View File

@ -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,