diff --git a/src/api/apps.ts b/src/api/apps.ts index b72d6f7..c447d31 100644 --- a/src/api/apps.ts +++ b/src/api/apps.ts @@ -80,7 +80,11 @@ export function runSubFlow(data: any) { } // 重运行 -export function reRunApp(data: any) { +export function reRunApp(data: { + appId: string, + instanceId: string, + socketId: string +}) { return axios.post(`${runPrefix}/apps/rerun`, data); } diff --git a/src/hooks/useFlowCallbacks.ts b/src/hooks/useFlowCallbacks.ts index 44a6df2..7699684 100644 --- a/src/hooks/useFlowCallbacks.ts +++ b/src/hooks/useFlowCallbacks.ts @@ -19,6 +19,7 @@ import { updateCanvasDataMap, resetNodeStatus, updateIsRunning, + updateIsPaused, updateEventListOld, addRuntimeLog, clearRuntimeLogs, @@ -39,7 +40,7 @@ import { appFLowHandle } from '@/pages/flowEditor/utils/appFlowhandle'; import { handelEventNodeList, updateEvent, upDatePublish } from '@/pages/flowEditor/utils/common'; import { Dispatch } from 'redux'; -import { getAppListBySceneId, runMainFlow, runSubFlow, stopApp } from '@/api/apps'; +import { getAppListBySceneId, runMainFlow, runSubFlow, stopApp, pauseApp, resumeApp, reRunApp } from '@/api/apps'; import store from '@/store'; import { updateAppEvent, updateAppEventChannel, updateAppFlowData } from '@/api/appEvent'; import { getUrlParams, sleep } from '@/utils/common'; @@ -1423,6 +1424,96 @@ export const useFlowCallbacks = ( } }, [getCurrentAppKey]); + // 暂停/恢复应用 + const handlePause = useCallback(async (isPaused: boolean) => { + const { currentAppData, appRuntimeData } = store.getState().ideContainer; + const appKey = getCurrentAppKey(); + + if (!currentAppData) { + Message.warning('请先选择一个应用'); + return; + } + + // 获取runId + const runId = appKey && appRuntimeData[appKey] ? appRuntimeData[appKey].runId : ''; + + if (!runId) { + Message.warning('应用未运行'); + return; + } + + try { + if (isPaused) { + // 当前已暂停,执行恢复操作 + const res: any = await resumeApp({ id: runId }); + if (res.code === 200) { + Message.success('应用已恢复'); + // 更新暂停状态为 false + dispatch(updateIsPaused(false)); + } else { + Message.error(res.msg || '恢复失败'); + } + } else { + // 当前正在运行,执行暂停操作 + const res: any = await pauseApp({ id: runId }); + if (res.code === 200) { + Message.success('应用已暂停'); + // 更新暂停状态为 true + dispatch(updateIsPaused(true)); + } else { + Message.error(res.msg || '暂停失败'); + } + } + } catch (error) { + console.error('暂停/恢复失败:', error); + Message.error('操作失败'); + } + }, [getCurrentAppKey]); + + // 重跑应用 + const handleReRun = useCallback(async () => { + const { currentAppData, appRuntimeData, socketId } = store.getState().ideContainer; + const appKey = getCurrentAppKey(); + + if (!currentAppData) { + Message.warning('请先选择一个应用'); + return; + } + + // 获取runId (instanceId) + const instanceId = appKey && appRuntimeData[appKey] ? appRuntimeData[appKey].runId : ''; + + if (!instanceId) { + Message.warning('应用未运行'); + return; + } + + try { + // 判断是主流程还是子流程 + const appId = currentAppData.key && currentAppData.key.includes('sub') + ? currentAppData.parentAppId + : currentAppData.id; + + const res: any = await reRunApp({ + appId, + instanceId, + socketId + }); + + if (res.code === 200) { + Message.success('应用重跑成功'); + + // 重置节点状态 + dispatch(resetNodeStatus()); + } else { + Message.error(res.msg || '重跑失败'); + } + } catch (error) { + console.error('重跑失败:', error); + Message.error('重跑失败'); + } + }, [getCurrentAppKey]); + return { // Event handlers onNodesChange, @@ -1456,7 +1547,9 @@ export const useFlowCallbacks = ( // Actions saveFlowDataToServer, - handleRun + handleRun, + handlePause, + handleReRun }; }; export default useFlowCallbacks; \ No newline at end of file diff --git a/src/pages/componentDevelopment/componentList/index.tsx b/src/pages/componentDevelopment/componentList/index.tsx index c1f6375..9d859d2 100644 --- a/src/pages/componentDevelopment/componentList/index.tsx +++ b/src/pages/componentDevelopment/componentList/index.tsx @@ -758,32 +758,32 @@ const GlobalVarContainer = () => {
- {/**/} - {/* {[{ label: '全部', value: '' }, ...componentStatusDict].map((item) => {*/} - {/* return (*/} - {/* */} - {/* {({ checked }) => {*/} - {/* return (*/} - {/* */} - {/* {item.label}*/} - {/* */} - {/* );*/} - {/* }}*/} - {/* */} - {/* );*/} - {/* })}*/} - {/**/} + + {[{ label: '全部', value: '' }, ...componentStatusDict].map((item) => { + return ( + + {({ checked }) => { + return ( + + ); + }} + + ); + })} + {selectedItem === '我的组件' && }> {/**/} @@ -71,6 +98,27 @@ const ActionBar: React.FC = ({ > {currentAppIsRunning ? '停止' : '运行'} + + {/*}*/} + {/* onClick={() => handleReRun()}*/} + {/* style={{ padding: '0 8px', backgroundColor: '#fff' }}*/} + {/* disabled={!currentAppIsRunning}*/} + {/*>*/} + {/* 重跑*/} + {/**/}
diff --git a/src/store/ideContainer.ts b/src/store/ideContainer.ts index 350cbdc..614a0d9 100644 --- a/src/store/ideContainer.ts +++ b/src/store/ideContainer.ts @@ -19,6 +19,7 @@ interface IDEContainerState { appRuntimeData: Record; isRunning: boolean; + isPaused: boolean; logs: any[]; runId: string; eventSendNodeList: any[], // [{nodeID:topic}] @@ -142,6 +143,7 @@ const ideContainerSlice = createSlice({ state.appRuntimeData[targetAppKey] = { nodeStatusMap: {}, isRunning: false, + isPaused: false, logs: [], runId: '', eventSendNodeList: [], @@ -172,6 +174,7 @@ const ideContainerSlice = createSlice({ state.appRuntimeData[appKey] = { nodeStatusMap: {}, isRunning: false, + isPaused: false, logs: [], runId: '', eventSendNodeList: [], @@ -181,6 +184,24 @@ const ideContainerSlice = createSlice({ state.appRuntimeData[appKey].isRunning = payload; } }, + // 更新暂停状态 + updateIsPaused: (state, { payload }) => { + const appKey = getCurrentAppKey(state.currentAppData); + if (appKey) { + if (!state.appRuntimeData[appKey]) { + state.appRuntimeData[appKey] = { + nodeStatusMap: {}, + isRunning: false, + isPaused: false, + logs: [], + runId: '', + eventSendNodeList: [], + eventlisteneList: [] + }; + } + state.appRuntimeData[appKey].isPaused = payload; + } + }, // 添加运行id updateRuntimeId: (state, { payload }) => { const appKey = getCurrentAppKey(state.currentAppData); @@ -203,6 +224,7 @@ const ideContainerSlice = createSlice({ state.appRuntimeData[appKey] = { nodeStatusMap: {}, isRunning: false, + isPaused: false, logs: [], runId: '', eventSendNodeList: [], @@ -218,6 +240,7 @@ const ideContainerSlice = createSlice({ state.appRuntimeData[appId] = { nodeStatusMap: {}, isRunning: false, + isPaused: false, logs: [], runId: '', eventSendNodeList: [], @@ -257,6 +280,7 @@ export const { updateNodeStatus, resetNodeStatus, updateIsRunning, + updateIsPaused, updateRuntimeId, updateEventNodeList, addRuntimeLog,