From a1fd278764b3a7b2ddee44748ddc944fb0e80321 Mon Sep 17 00:00:00 2001 From: pengm <674192343@qq.com> Date: Mon, 27 Apr 2026 21:04:26 +0800 Subject: [PATCH] 1.websoket增加问答模式,处理一段时间后,ws断连问题 --- src/mes/productionExec/productionExecMain/index.js | 62 ++++++++++++++++++++++++++++++-------------------------------- src/models/app.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 32 deletions(-) diff --git a/src/mes/productionExec/productionExecMain/index.js b/src/mes/productionExec/productionExecMain/index.js index e87a892..cead2c0 100644 --- a/src/mes/productionExec/productionExecMain/index.js +++ b/src/mes/productionExec/productionExecMain/index.js @@ -394,37 +394,33 @@ const ProductionExecMain = baseProps => { const { app = {} } = baseProps; const [refreshCount, setRefreshCount] = useState(0); + const [sStatusNew, setStatusNew] = useState(undefined); - // useEffect(() => { - // const getValue = () => { - // const changeExecInfo = commonUtils.getAppData("changeExecInfo"); - // if (changeExecInfo.dReplyPalletERp === 1) { - // try { - // const { sId } = changeExecInfo; - // const url = `${commonConfig.server_host}mqtt/updateFlushmes/${sId}`; - // commonServices.postValueService(null, {}, url).then(() => { - // props.onRefresh(); - // setRefreshCount(pre => pre + 1); - // }) - // } catch (error) { - // console.log("=====updateFlushmes报错", { - // error, changeExecInfo, - // }); - // props.onRefresh(); - // setRefreshCount(pre => pre + 1); - // } - // } - // }; - // - // getValue(); - // const timer = setInterval(() => { - // getValue(); - // }, 1000); - // - // return () => { - // clearInterval(timer); - // }; - // }, []); + useEffect(() => { + const getValue = () => { + const changeExecInfo = commonUtils.getAppData("changeExecInfo"); + setStatusNew(changeExecInfo.sStatus); + + const refreshExecInfo = commonUtils.getAppData("refreshExecInfo"); + if (refreshExecInfo.dReplyPalletERp === 1) { + commonUtils.setAppData("refreshExecInfo", { + ...refreshExecInfo, + dReplyPalletERp: 0 + }); + props.onRefresh(); + setRefreshCount(pre => pre + 1); + } + }; + + getValue(); + const timer = setInterval(() => { + getValue(); + }, 1000); + + return () => { + clearInterval(timer); + }; + }, []); const { bFinish } = props; const [collapsed, setCollapsed] = useState(false); @@ -500,6 +496,7 @@ const ProductionExecMain = baseProps => { {...props} changeExecInfo={app.changeExecInfo} refreshCount={refreshCount} + sStatusNew={sStatusNew} /> )} @@ -530,7 +527,8 @@ const ProductionExecContentByType = props => { deviceTargetInfoConfig = {}, deviceTargetInfoData = [], setPagesLoading, - refreshCount = 0 + refreshCount = 0, + sStatusNew } = props; /** @@ -580,7 +578,7 @@ const ProductionExecContentByType = props => { return showValue[flag]; }, - [deviceTargetInfoConfig, deviceTargetInfoData] + [deviceTargetInfoConfig, deviceTargetInfoData, sStatusNew] ); props = { ...props, sStatusNameProcess }; diff --git a/src/models/app.js b/src/models/app.js index f096120..d4bab7b 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -69,6 +69,7 @@ export default { "17484876300007863197993856505000" : "queryTracking" }, changeExecInfo: {}, + refreshExecInfo: {}, }, reducers: { saveToken(state, { payload: token }) { @@ -219,6 +220,12 @@ export default { } return state; }, + saveRefreshExecInfo(state, { payload }) { + if (['/indexMes/productionExec'].includes(state?.currentMesPane?.sModelType)) { + localStorage.setItem(`${config.prefix}refreshExecInfo`, JSON.stringify({ ...payload || {} })); + } + return state; + }, saveCounter(state, { payload }) { return { ...state, counterInfo: payload }; }, @@ -745,6 +752,31 @@ export default { const msgData = JSON.parse(msg.data); dispatch({ type: 'app/changeMachineData', payload: { ...msgData.msg || {} } }); } + } else if (rtmsg.action === 'flushData') { + let sReqId = rtmsg.reqId; + const flag = 'ack'; + // 检查WebSocket连接是否存在且状态为打开 + if (ws && ws.readyState === WebSocket.OPEN) { + // 使用标准的 sendWebSocketMessage 函数发送消息 + commonFunc.sendWebSocketMessage( + ws, + 'ack_'+sReqId, // key: 操作类型 + flag, // flag: 操作标志 + 'noAction', // showType: 显示类型 + userinfo.sId, // currUserId: 当前用户ID + null, // msgInfo: 消息信息 + '', // sId: 操作数据主表数据ID + null, // sendTo: 消息接收人 + { reqId: sReqId } // param: 其他参数 + ); + } else { + console.log('WebSocket连接未就绪,无法发送flushData响应'); + } + + if (window.bChangeMachineData) { + const msgData = JSON.parse(msg.data); + dispatch({ type: 'app/saveRefreshExecInfo', payload: { ...msgData.msg || {} } }); + } } }; ws.onmessage = (msg) => { -- libgit2 0.22.2