import { WsConnect } from './websocket' import store from "@/store"; // 创建websocket链接 const timestr = new Date().getTime() const dcsConn = new WsConnect( // websocket地址 process.env.VUE_APP_Socket_Dcs_API + '/xc-screen/websocket/dcsmsg' + timestr, // 传递给后台的数据 '', (data) => { // console.log('dcs成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "FanFrequencyInfo": { store.dispatch({ type: "websocket/setFanFrequencyInfo", payload: msgData.data.FanFrequencyInfo }) break; } case "KilnInfo": { store.dispatch({ type: "websocket/setKilnInfo", payload: msgData.data }) break; } case "GasInfo": { store.dispatch({ type: "websocket/setGasInfo", payload: msgData.data }) break; } case "SumGasInfo": { store.dispatch({ type: "websocket/setSumGasInfo", payload: msgData.data }) break; } default: } }, (err) => { console.log('失败的回调函数', err) } ) // ISRA const mesIsra = new WsConnect( process.env.VUE_APP_Socket_API + '/websocket/message?userId=KILN' + timestr, '', (data) => { // console.log('mes ISRA成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "israKiln": { store.dispatch({ type: "websocket/setIsraKiln", payload: msgData.detData.dayStatistic }) break; } default: } }, (err) => { console.log('失败的回调函数', err) } ) // 原料 MA const mesMA = new WsConnect( process.env.VUE_APP_Socket_API + '/websocket/message?userId=MA' + timestr, '', (data) => { // console.log('mes 原料成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "material": { store.dispatch({ type: "websocket/setMaterial", payload: msgData.data }) break; } default: } }, (err) => { console.log('失败的回调函数', err) } ) // 能耗 EN const mesEN = new WsConnect( // websocket地址 process.env.VUE_APP_Socket_API + '/websocket/message?userId=ENERGY' + timestr, // 传递给后台的数据 '', // 成功拿到后台返回的数据的回调函数 (data) => { // console.log('mes 能耗成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "EnergyInfo": { let keys = Object.keys(msgData.data) if (keys.includes('elecQty1') || keys.includes('waterQty')) { store.dispatch({ type: "websocket/setEnergyInfo", payload: msgData.data }) } break; } case "EnergyTrend": { store.dispatch({ type: "websocket/setEnergyTrend", payload: msgData.data }) break; } case "EnergyMonitoring": { store.dispatch({ type: "websocket/setEnergyMonitoring", payload: msgData.data }) break; } default: } }, // websocket连接失败的回调函数 (err) => { console.log('失败的回调函数', err) } ) // 烟气 GAS const mesGAS = new WsConnect( // websocket地址 process.env.VUE_APP_Socket_API + '/websocket/message?userId=GAS' + timestr, // 传递给后台的数据 '', // 成功拿到后台返回的数据的回调函数 (data) => { // console.log('mes 烟气成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "exhaustGas": { store.dispatch({ type: "websocket/setExhaustGasInfo", payload: msgData.realtime }) store.dispatch({ type: "websocket/setExhaustGasChart", payload: { dayTrend: msgData.dayTrend, weekTrend: msgData.weekTrend, monthTrend: msgData.monthTrend, yearTrend: msgData.yearTrend, } }) break; } default: } }, // websocket连接失败的回调函数 (err) => { console.log('失败的回调函数', err) } ) // 缺陷分类/统计 IS const mesIS = new WsConnect( // websocket地址 process.env.VUE_APP_Socket_API + '/websocket/message?userId=IS' + timestr, // 传递给后台的数据 '', // 成功拿到后台返回的数据的回调函数 (data) => { // console.log('mes 缺陷成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "isra": { store.dispatch({ type: "websocket/setDefectChart", payload: { checkType: msgData.detData.checkType, dayStatistic: msgData.detData.dayStatistic, weekStatistic: msgData.detData.weekStatistic, monthStatistic: msgData.detData.monthStatistic, yearStatistic: msgData.detData.yearStatistic, } }) break; } default: } }, // websocket连接失败的回调函数 (err) => { console.log('失败的回调函数', err) } ) // 深加工生产运行驾驶舱(除能源) SJG const mesSJG = new WsConnect( // websocket地址 process.env.VUE_APP_Socket_API + '/websocket/message?userId=SJG' + timestr, // 传递给后台的数据 '', // 成功拿到后台返回的数据的回调函数 (data) => { // console.log('mes 产线产量及良品率成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "productline": { store.dispatch({ type: "websocket/setProductline", payload: msgData.detData }) break; } case "equipment": { store.dispatch({ type: "websocket/setSJGEq", payload: msgData.detData }) break; } case "order": { store.dispatch({ type: "websocket/setWorkOrder", payload: msgData.detData }) break; } case "defectSum": { store.dispatch({ type: "websocket/setDefectSum", payload: msgData.detData }) break; } default: } }, // websocket连接失败的回调函数 (err) => { console.log('失败的回调函数', err) } ) // 订单完成情况 OV const mesOV = new WsConnect( // websocket地址 process.env.VUE_APP_Socket_API + '/websocket/message?userId=OV' + timestr, // 'ws://192.168.0.33:48082/websocket/message?userId=OV'+timestr, // 传递给后台的数据 '', // 成功拿到后台返回的数据的回调函数 (data) => { // console.log('mes 产线产量及良品率成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "order": { store.dispatch({ type: "websocket/setOrder", payload: msgData.detData }) break; } default: } }, // websocket连接失败的回调函数 (err) => { console.log('失败的回调函数', err) } ) // 本日生产良品率 CUTTING const mesCUTTING = new WsConnect( // websocket地址 process.env.VUE_APP_Socket_API + '/websocket/message?userId=CUTTING' + timestr, // 传递给后台的数据 '', // 成功拿到后台返回的数据的回调函数 (data) => { // console.log('mes 产线产量及良品率成功的回调函数, 接收到的data数据: ', data) let msgData = {} try { msgData = JSON.parse(data) } catch (error) { console.log("websocket: [unable to msgData] : ", data); } if (msgData == null) return; switch (msgData?.type) { case "cutting": { if (msgData?.name === 'table') { store.dispatch({ type: "websocket/setYieldRateTable", payload: msgData.data }) return } if (msgData?.dateType === 'day') { store.dispatch({ type: "websocket/setCutChartDay", payload: msgData.detData }) return } if (msgData?.dateType === 'weekly') { store.dispatch({ type: "websocket/setCutChartWeek", payload: msgData.detData }) return } if (msgData?.dateType === 'month') { store.dispatch({ type: "websocket/setCutChartMonth", payload: msgData.detData }) return } if (msgData?.dateType === 'year') { store.dispatch({ type: "websocket/setCutChartYear", payload: msgData.detData }) return } break; } default: } }, // websocket连接失败的回调函数 (err) => { console.log('失败的回调函数', err) } ) export const getDcsMsg = () => { dcsConn.createWebSoket() mesIsra.createWebSoket() mesMA.createWebSoket() mesEN.createWebSoket() mesGAS.createWebSoket() mesIS.createWebSoket() mesSJG.createWebSoket() mesOV.createWebSoket() mesCUTTING.createWebSoket() } export const closeDcsMsg = () => { dcsConn.closeWebsocket() mesIsra.closeWebsocket() mesMA.closeWebsocket() mesEN.closeWebsocket() mesGAS.closeWebsocket() mesIS.closeWebsocket() mesSJG.closeWebsocket() mesOV.closeWebsocket() mesCUTTING.closeWebsocket() }