Commit a1fd278764b3a7b2ddee44748ddc944fb0e80321
1 parent
c5fa7bbb
1.websoket增加问答模式,处理一段时间后,ws断连问题
Showing
2 changed files
with
62 additions
and
32 deletions
src/mes/productionExec/productionExecMain/index.js
| ... | ... | @@ -394,37 +394,33 @@ const ProductionExecMain = baseProps => { |
| 394 | 394 | const { app = {} } = baseProps; |
| 395 | 395 | |
| 396 | 396 | const [refreshCount, setRefreshCount] = useState(0); |
| 397 | + const [sStatusNew, setStatusNew] = useState(undefined); | |
| 397 | 398 | |
| 398 | - // useEffect(() => { | |
| 399 | - // const getValue = () => { | |
| 400 | - // const changeExecInfo = commonUtils.getAppData("changeExecInfo"); | |
| 401 | - // if (changeExecInfo.dReplyPalletERp === 1) { | |
| 402 | - // try { | |
| 403 | - // const { sId } = changeExecInfo; | |
| 404 | - // const url = `${commonConfig.server_host}mqtt/updateFlushmes/${sId}`; | |
| 405 | - // commonServices.postValueService(null, {}, url).then(() => { | |
| 406 | - // props.onRefresh(); | |
| 407 | - // setRefreshCount(pre => pre + 1); | |
| 408 | - // }) | |
| 409 | - // } catch (error) { | |
| 410 | - // console.log("=====updateFlushmes报错", { | |
| 411 | - // error, changeExecInfo, | |
| 412 | - // }); | |
| 413 | - // props.onRefresh(); | |
| 414 | - // setRefreshCount(pre => pre + 1); | |
| 415 | - // } | |
| 416 | - // } | |
| 417 | - // }; | |
| 418 | - // | |
| 419 | - // getValue(); | |
| 420 | - // const timer = setInterval(() => { | |
| 421 | - // getValue(); | |
| 422 | - // }, 1000); | |
| 423 | - // | |
| 424 | - // return () => { | |
| 425 | - // clearInterval(timer); | |
| 426 | - // }; | |
| 427 | - // }, []); | |
| 399 | + useEffect(() => { | |
| 400 | + const getValue = () => { | |
| 401 | + const changeExecInfo = commonUtils.getAppData("changeExecInfo"); | |
| 402 | + setStatusNew(changeExecInfo.sStatus); | |
| 403 | + | |
| 404 | + const refreshExecInfo = commonUtils.getAppData("refreshExecInfo"); | |
| 405 | + if (refreshExecInfo.dReplyPalletERp === 1) { | |
| 406 | + commonUtils.setAppData("refreshExecInfo", { | |
| 407 | + ...refreshExecInfo, | |
| 408 | + dReplyPalletERp: 0 | |
| 409 | + }); | |
| 410 | + props.onRefresh(); | |
| 411 | + setRefreshCount(pre => pre + 1); | |
| 412 | + } | |
| 413 | + }; | |
| 414 | + | |
| 415 | + getValue(); | |
| 416 | + const timer = setInterval(() => { | |
| 417 | + getValue(); | |
| 418 | + }, 1000); | |
| 419 | + | |
| 420 | + return () => { | |
| 421 | + clearInterval(timer); | |
| 422 | + }; | |
| 423 | + }, []); | |
| 428 | 424 | |
| 429 | 425 | const { bFinish } = props; |
| 430 | 426 | const [collapsed, setCollapsed] = useState(false); |
| ... | ... | @@ -500,6 +496,7 @@ const ProductionExecMain = baseProps => { |
| 500 | 496 | {...props} |
| 501 | 497 | changeExecInfo={app.changeExecInfo} |
| 502 | 498 | refreshCount={refreshCount} |
| 499 | + sStatusNew={sStatusNew} | |
| 503 | 500 | /> |
| 504 | 501 | )} |
| 505 | 502 | </div> |
| ... | ... | @@ -530,7 +527,8 @@ const ProductionExecContentByType = props => { |
| 530 | 527 | deviceTargetInfoConfig = {}, |
| 531 | 528 | deviceTargetInfoData = [], |
| 532 | 529 | setPagesLoading, |
| 533 | - refreshCount = 0 | |
| 530 | + refreshCount = 0, | |
| 531 | + sStatusNew | |
| 534 | 532 | } = props; |
| 535 | 533 | |
| 536 | 534 | /** |
| ... | ... | @@ -580,7 +578,7 @@ const ProductionExecContentByType = props => { |
| 580 | 578 | |
| 581 | 579 | return showValue[flag]; |
| 582 | 580 | }, |
| 583 | - [deviceTargetInfoConfig, deviceTargetInfoData] | |
| 581 | + [deviceTargetInfoConfig, deviceTargetInfoData, sStatusNew] | |
| 584 | 582 | ); |
| 585 | 583 | |
| 586 | 584 | props = { ...props, sStatusNameProcess }; | ... | ... |
src/models/app.js
| ... | ... | @@ -69,6 +69,7 @@ export default { |
| 69 | 69 | "17484876300007863197993856505000" : "queryTracking" |
| 70 | 70 | }, |
| 71 | 71 | changeExecInfo: {}, |
| 72 | + refreshExecInfo: {}, | |
| 72 | 73 | }, |
| 73 | 74 | reducers: { |
| 74 | 75 | saveToken(state, { payload: token }) { |
| ... | ... | @@ -219,6 +220,12 @@ export default { |
| 219 | 220 | } |
| 220 | 221 | return state; |
| 221 | 222 | }, |
| 223 | + saveRefreshExecInfo(state, { payload }) { | |
| 224 | + if (['/indexMes/productionExec'].includes(state?.currentMesPane?.sModelType)) { | |
| 225 | + localStorage.setItem(`${config.prefix}refreshExecInfo`, JSON.stringify({ ...payload || {} })); | |
| 226 | + } | |
| 227 | + return state; | |
| 228 | + }, | |
| 222 | 229 | saveCounter(state, { payload }) { |
| 223 | 230 | return { ...state, counterInfo: payload }; |
| 224 | 231 | }, |
| ... | ... | @@ -745,6 +752,31 @@ export default { |
| 745 | 752 | const msgData = JSON.parse(msg.data); |
| 746 | 753 | dispatch({ type: 'app/changeMachineData', payload: { ...msgData.msg || {} } }); |
| 747 | 754 | } |
| 755 | + } else if (rtmsg.action === 'flushData') { | |
| 756 | + let sReqId = rtmsg.reqId; | |
| 757 | + const flag = 'ack'; | |
| 758 | + // 检查WebSocket连接是否存在且状态为打开 | |
| 759 | + if (ws && ws.readyState === WebSocket.OPEN) { | |
| 760 | + // 使用标准的 sendWebSocketMessage 函数发送消息 | |
| 761 | + commonFunc.sendWebSocketMessage( | |
| 762 | + ws, | |
| 763 | + 'ack_'+sReqId, // key: 操作类型 | |
| 764 | + flag, // flag: 操作标志 | |
| 765 | + 'noAction', // showType: 显示类型 | |
| 766 | + userinfo.sId, // currUserId: 当前用户ID | |
| 767 | + null, // msgInfo: 消息信息 | |
| 768 | + '', // sId: 操作数据主表数据ID | |
| 769 | + null, // sendTo: 消息接收人 | |
| 770 | + { reqId: sReqId } // param: 其他参数 | |
| 771 | + ); | |
| 772 | + } else { | |
| 773 | + console.log('WebSocket连接未就绪,无法发送flushData响应'); | |
| 774 | + } | |
| 775 | + | |
| 776 | + if (window.bChangeMachineData) { | |
| 777 | + const msgData = JSON.parse(msg.data); | |
| 778 | + dispatch({ type: 'app/saveRefreshExecInfo', payload: { ...msgData.msg || {} } }); | |
| 779 | + } | |
| 748 | 780 | } |
| 749 | 781 | }; |
| 750 | 782 | ws.onmessage = (msg) => { | ... | ... |