|
|
|
@ -31,6 +31,9 @@ import {
|
|
|
|
} from '@/components/FlowEditor/nodeEditors/validators/nodeValidators';
|
|
|
|
} from '@/components/FlowEditor/nodeEditors/validators/nodeValidators';
|
|
|
|
|
|
|
|
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
|
|
|
|
import { runMainFlow } from '@/api/apps';
|
|
|
|
|
|
|
|
import store from '@/store';
|
|
|
|
|
|
|
|
import { updateAppEvent } from '@/api/appEvent';
|
|
|
|
|
|
|
|
|
|
|
|
// 根据节点类型获取对应的节点组件
|
|
|
|
// 根据节点类型获取对应的节点组件
|
|
|
|
const getNodeComponent = (nodeType: string) => {
|
|
|
|
const getNodeComponent = (nodeType: string) => {
|
|
|
|
@ -774,6 +777,14 @@ export const useFlowCallbacks = (
|
|
|
|
})
|
|
|
|
})
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeType === 'EVENTSEND' || nodeType === 'EVENTLISTENE') {
|
|
|
|
|
|
|
|
const { eventList } = store.getState().ideContainer;
|
|
|
|
|
|
|
|
const emptyEvent = eventList.find(item => item.topic.includes('**empty**'));
|
|
|
|
|
|
|
|
newNode.data.component = {
|
|
|
|
|
|
|
|
type: nodeType,
|
|
|
|
|
|
|
|
customDef: { eventId: emptyEvent.id, name: emptyEvent.name, topic: emptyEvent.topic }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将未定义的节点动态追加进nodeTypes
|
|
|
|
// 将未定义的节点动态追加进nodeTypes
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
@ -863,7 +874,6 @@ export const useFlowCallbacks = (
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建新节点
|
|
|
|
// 创建新节点
|
|
|
|
const newNode = {
|
|
|
|
const newNode = {
|
|
|
|
id: `${nodeType}-${Date.now()}`,
|
|
|
|
id: `${nodeType}-${Date.now()}`,
|
|
|
|
@ -885,6 +895,14 @@ export const useFlowCallbacks = (
|
|
|
|
})
|
|
|
|
})
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeType === 'EVENTSEND' || nodeType === 'EVENTLISTENE') {
|
|
|
|
|
|
|
|
const { eventList } = store.getState().ideContainer;
|
|
|
|
|
|
|
|
const emptyEvent = eventList.find(item => item.topic.includes('**empty**'));
|
|
|
|
|
|
|
|
newNode.data.component = {
|
|
|
|
|
|
|
|
type: nodeType,
|
|
|
|
|
|
|
|
customDef: { eventId: emptyEvent.id, name: emptyEvent.name, topic: emptyEvent.topic }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将未定义的节点动态追加进nodeTypes
|
|
|
|
// 将未定义的节点动态追加进nodeTypes
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key));
|
|
|
|
@ -945,8 +963,9 @@ export const useFlowCallbacks = (
|
|
|
|
// 转换会原始数据类型
|
|
|
|
// 转换会原始数据类型
|
|
|
|
const revertedData = revertFlowData(nodes, edges);
|
|
|
|
const revertedData = revertFlowData(nodes, edges);
|
|
|
|
console.log('revertedData(中断):', revertedData);
|
|
|
|
console.log('revertedData(中断):', revertedData);
|
|
|
|
|
|
|
|
|
|
|
|
// return;
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateEvent(revertedData.nodeConfigs);
|
|
|
|
const res: any = await setMainFlow(revertedData, initialData.appId);
|
|
|
|
const res: any = await setMainFlow(revertedData, initialData.appId);
|
|
|
|
if (res.code === 200) {
|
|
|
|
if (res.code === 200) {
|
|
|
|
Message.success('保存成功');
|
|
|
|
Message.success('保存成功');
|
|
|
|
@ -960,49 +979,78 @@ export const useFlowCallbacks = (
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [nodes, edges, initialData?.appId]);
|
|
|
|
}, [nodes, edges, initialData?.appId]);
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化WebSocket hook
|
|
|
|
const updateEvent = (revertedData) => {
|
|
|
|
const ws = useWebSocket({
|
|
|
|
// 初始化参数对象
|
|
|
|
onOpen: () => {
|
|
|
|
const params: any = {
|
|
|
|
console.log('WebSocket连接已建立');
|
|
|
|
eventListenes: [],
|
|
|
|
Message.success('运行已启动');
|
|
|
|
eventSends: []
|
|
|
|
},
|
|
|
|
};
|
|
|
|
onClose: () => {
|
|
|
|
|
|
|
|
console.log('WebSocket连接已关闭');
|
|
|
|
// 遍历所有节点,查找事件相关节点
|
|
|
|
setIsRunning(false);
|
|
|
|
Object.entries(revertedData).forEach(([nodeId, nodeConfig]: [string, any]) => {
|
|
|
|
Message.info('运行已停止');
|
|
|
|
// 检查节点是否有component属性和type定义
|
|
|
|
},
|
|
|
|
if (nodeConfig.component?.type) {
|
|
|
|
onError: (event) => {
|
|
|
|
const nodeType = nodeConfig.component.type;
|
|
|
|
console.error('WebSocket错误:', event);
|
|
|
|
const customDef = nodeConfig.component.customDef;
|
|
|
|
setIsRunning(false);
|
|
|
|
|
|
|
|
Message.error('运行连接出错');
|
|
|
|
// 解析customDef,可能是字符串也可能是对象
|
|
|
|
},
|
|
|
|
let eventConfig;
|
|
|
|
onMessage: (event) => {
|
|
|
|
if (typeof customDef === 'string') {
|
|
|
|
console.log('收到WebSocket消息:', event.data);
|
|
|
|
try {
|
|
|
|
// 这里可以处理从后端收到的消息,例如日志更新等
|
|
|
|
eventConfig = JSON.parse(customDef);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
console.error('Failed to parse customDef:', e);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
eventConfig = customDef;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据节点类型处理事件节点
|
|
|
|
|
|
|
|
if (nodeType === 'EVENTLISTENE') {
|
|
|
|
|
|
|
|
// 事件接收节点
|
|
|
|
|
|
|
|
params.eventListenes.push({
|
|
|
|
|
|
|
|
eventId: eventConfig?.eventId || '',
|
|
|
|
|
|
|
|
topic: eventConfig?.topic || '',
|
|
|
|
|
|
|
|
eventName: eventConfig?.name || '',
|
|
|
|
|
|
|
|
dataOuts: nodeConfig.dataOuts || []
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeType === 'EVENTSEND') {
|
|
|
|
|
|
|
|
// 事件发送节点
|
|
|
|
|
|
|
|
params.eventSends.push({
|
|
|
|
|
|
|
|
eventId: eventConfig?.eventId || '',
|
|
|
|
|
|
|
|
topic: eventConfig?.topic || '',
|
|
|
|
|
|
|
|
eventName: eventConfig?.name || '',
|
|
|
|
|
|
|
|
dataIns: nodeConfig.dataIns || []
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用更新事件的API
|
|
|
|
|
|
|
|
if (initialData?.appId) {
|
|
|
|
|
|
|
|
updateAppEvent(initialData.appId, params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 运行处理函数
|
|
|
|
// 运行处理函数
|
|
|
|
const handleRun = useCallback(async (running: boolean) => {
|
|
|
|
const handleRun = useCallback(async (running: boolean) => {
|
|
|
|
if (running) {
|
|
|
|
if (running) {
|
|
|
|
|
|
|
|
const { currentAppData, socketId } = store.getState().ideContainer;
|
|
|
|
// 启动运行
|
|
|
|
// 启动运行
|
|
|
|
const res = await getUserToken();
|
|
|
|
const params = {
|
|
|
|
const token = res.data;
|
|
|
|
appId: currentAppData.id,
|
|
|
|
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
|
|
|
|
socketId
|
|
|
|
let wsApi = `${protocol}://${window.location.host}/ws/v1/bpms-runtime`;
|
|
|
|
};
|
|
|
|
if (window.location.host.includes('localhost')) {
|
|
|
|
runMainFlow(params);
|
|
|
|
wsApi = `ws://api.myserver.com:4121/ws/v1/bpms-runtime`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const uri = `${wsApi}?x-auth0-token=${token}`;
|
|
|
|
|
|
|
|
ws.connect(uri);
|
|
|
|
|
|
|
|
setIsRunning(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
// 停止运行
|
|
|
|
// 停止运行
|
|
|
|
ws.disconnect();
|
|
|
|
|
|
|
|
setIsRunning(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [initialData?.appId, ws]);
|
|
|
|
}, [initialData?.appId]);
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
// Event handlers
|
|
|
|
// Event handlers
|
|
|
|
|