From 309fbf95a2ff02f2ded6b90f49fc1fdcae874748 Mon Sep 17 00:00:00 2001 From: ZLY Date: Fri, 31 Oct 2025 14:15:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(flow):=E4=BC=98=E5=8C=96=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E4=B8=8E=E5=8F=91=E9=80=81=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为EventListenEditor和EventSendEditor组件添加node属性传参 - 修改queryEventItemBySceneId调用方式,支持更多查询参数 - 更新事件选择逻辑,兼容新旧数据格式处理 - 修复事件选项key值,使用topic替代topicId避免重复 --- .../nodeEditors/LocalNodeEditor.tsx | 4 +-- .../components/EventListenEditor.tsx | 9 ++++-- .../nodeEditors/components/EventSelect.tsx | 28 +++++++++++-------- .../components/EventSendEditor.tsx | 2 +- .../components/nodeContentOther.tsx | 16 ++++++++--- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/components/FlowEditor/nodeEditors/LocalNodeEditor.tsx b/src/components/FlowEditor/nodeEditors/LocalNodeEditor.tsx index 347ae2b..2e55682 100644 --- a/src/components/FlowEditor/nodeEditors/LocalNodeEditor.tsx +++ b/src/components/FlowEditor/nodeEditors/LocalNodeEditor.tsx @@ -41,9 +41,9 @@ const LocalNodeEditor: React.FC = ({ case 'CYCLE': // 周期 return ; case 'EVENTLISTENE': // 事件接收 - return ; + return ; case 'EVENTSEND': // 事件发送 - return ; + return ; case 'JSON2STR': // JSON转字符串 return ; case 'STR2JSON': // 字符串转JSON diff --git a/src/components/FlowEditor/nodeEditors/components/EventListenEditor.tsx b/src/components/FlowEditor/nodeEditors/components/EventListenEditor.tsx index 01a9a20..2c8ce11 100644 --- a/src/components/FlowEditor/nodeEditors/components/EventListenEditor.tsx +++ b/src/components/FlowEditor/nodeEditors/components/EventListenEditor.tsx @@ -7,12 +7,17 @@ import { useDispatch, useSelector } from 'react-redux'; import { queryEventItemBySceneId } from '@/api/event'; import ParamsTable from '@/components/FlowEditor/nodeEditors/components/ParamsTable'; -const EventListenEditor: React.FC = ({ nodeData, updateNodeData }) => { +const EventListenEditor: React.FC = ({ node, nodeData, updateNodeData }) => { const [eventList, setEventList] = useState(); const { currentAppData } = useSelector(state => state.ideContainer); const getEventList = async () => { - const res = await queryEventItemBySceneId(currentAppData.sceneId); + const params = { + nodeId: node.id, + appId: currentAppData.id, + sceneId: currentAppData.sceneId + }; + const res = await queryEventItemBySceneId(params); setEventList(res.data); }; diff --git a/src/components/FlowEditor/nodeEditors/components/EventSelect.tsx b/src/components/FlowEditor/nodeEditors/components/EventSelect.tsx index 749721f..78b0902 100644 --- a/src/components/FlowEditor/nodeEditors/components/EventSelect.tsx +++ b/src/components/FlowEditor/nodeEditors/components/EventSelect.tsx @@ -27,25 +27,30 @@ const EventSelect: React.FC = ({ nodeData, eventList, type, on const [form] = Form.useForm(); const [showModal, setShowModal] = useState(false); const [currentEvent, setCurrentEvent] = useState(null); - const { currentAppData } = useSelector(state => state.ideContainer); + const { currentAppData, eventListOld } = useSelector(state => state.ideContainer); useEffect(() => { if (nodeData && eventList && eventList.length > 0) { setOptions(eventList.filter(item => !item.topic.includes('**empty**'))); try { + // 数据是JSON字符串,标识是接口回来的 const customDef = JSON.parse(nodeData.component?.customDef); // 先判断topic是不是**empty**,是就不设置currentevent - if (customDef.topic && customDef.topic.includes('**empty**')) { - setCurrentEvent(null); - } + if (customDef.topic && customDef.topic.includes('**empty**')) setCurrentEvent(null); else { - setCurrentEvent(eventList.find(item => customDef.topic === item.topic)); + if (!customDef.eventId) { + setCurrentEvent(eventList.find(item => customDef.topic === item.topic)); + } + else { + const currentItem = eventListOld.find(item => customDef.eventId === item.eventId); + console.log('1', currentItem); + setCurrentEvent(currentItem.topic); + } } } catch (e) { + // 数据是普通对象标识是当前操作数据 // 先判断topic是不是**empty**,是就不设置currentevent - if (nodeData.component?.customDef?.topic && nodeData.component?.customDef?.topic.includes('**empty**')) { - setCurrentEvent(null); - } + if (nodeData.component?.customDef?.topic && nodeData.component?.customDef?.topic.includes('**empty**')) setCurrentEvent(null); else { setCurrentEvent(eventList.find(item => nodeData.component?.customDef.topic === item.topic)); } @@ -80,10 +85,11 @@ const EventSelect: React.FC = ({ nodeData, eventList, type, on }; const handelSelect = (e) => { + console.log('e:', e); const data = { type: typeMap[type], customDef: { - eventId: null, + eventId: e.eventId, name: e.name, topic: e.topic } @@ -123,8 +129,8 @@ const EventSelect: React.FC = ({ nodeData, eventList, type, on )} dropdownMenuStyle={{ maxHeight: 300 }} > - {options.map((option) => ( - ))} diff --git a/src/components/FlowEditor/nodeEditors/components/EventSendEditor.tsx b/src/components/FlowEditor/nodeEditors/components/EventSendEditor.tsx index 55c06a2..e595ff6 100644 --- a/src/components/FlowEditor/nodeEditors/components/EventSendEditor.tsx +++ b/src/components/FlowEditor/nodeEditors/components/EventSendEditor.tsx @@ -12,7 +12,7 @@ const EventSendEditor: React.FC = ({ nodeData, updateNodeData } const { currentAppData } = useSelector(state => state.ideContainer); const getEventList = async () => { - const res = await queryEventItemBySceneId(currentAppData.sceneId); + const res = await queryEventItemBySceneId({sceneId:currentAppData.sceneId}); setEventList(res.data); }; diff --git a/src/pages/flowEditor/components/nodeContentOther.tsx b/src/pages/flowEditor/components/nodeContentOther.tsx index fbaed69..fd66f09 100644 --- a/src/pages/flowEditor/components/nodeContentOther.tsx +++ b/src/pages/flowEditor/components/nodeContentOther.tsx @@ -193,10 +193,18 @@ const formatFooter = (data: any, eventListOld = []) => { return cronstrue.toString(intervalSeconds, { locale: 'zh_CN' }); case 'EVENTSEND': case 'EVENTLISTENE': - const { eventId, topic, name } = isJSON(data.customDef) ? JSON.parse(data.customDef) : data.customDef; - if (topic.includes('**empty**')) return ''; - const currentEvent = eventListOld.length > 0 ? eventListOld.find(item => item.eventId === eventId) : { name: '无' }; - return `事件: ${name || currentEvent.name}`; + const parsedData = isJSON(data.customDef) ? JSON.parse(data.customDef) : null; + // 数据是JSON字符串,标识是接口回来的,数据是普通对象标识是当前操作 + if (parsedData) { + const { eventId, topic, name } = parsedData; + if (topic.includes('**empty**')) return ''; + const currentEvent = eventListOld.length > 0 ? eventListOld.find(item => item.eventId === eventId) : { name: '无' }; + return `事件: ${currentEvent.name}`; + } + else { + const { name } = data.customDef; + return `事件: ${name}`; + } case 'BASIC': return data.compIdentifier ? `当前实例:${data.compIdentifier}` : ''; default: