Merge pull request #11253 from allenve/fix-globalEventPanel
Some checks failed
CodeQL / Analyze (javascript) (push) Has been cancelled
gh-pages / build (20.x) (push) Has been cancelled

fix: 全局广播事件配置面板
This commit is contained in:
Allen 2024-11-25 16:00:45 +08:00 committed by GitHub
commit 833524bbb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 78 additions and 1 deletions

View File

@ -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 (
<div>
<span className="ml-1 mr-1">{event?.label || info?.eventName}</span>
广
</div>
);
},
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: '配置参数值'
})
}
]
};
}
});

View File

@ -1,2 +1,3 @@
import './copy'; import './copy';
import './custom'; import './custom';
import './broadcast';

View File

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