diff --git a/src/jlmap3d/jl3dpassflow/connect/passflowconnect.js b/src/jlmap3d/jl3dpassflow/connect/passflowconnect.js index 7efe6acf5..c73a83689 100644 --- a/src/jlmap3d/jl3dpassflow/connect/passflowconnect.js +++ b/src/jlmap3d/jl3dpassflow/connect/passflowconnect.js @@ -3,183 +3,183 @@ import { getToken } from '@/utils/auth'; import store from '@/store/index'; // 定于仿真socket接口 -export function PassflowConnect(deviceaction,toptrain,downtrain,routegroup,passerStation,passerAi) { - const scope = this; - this.teststomp = new StompClient(); +export function PassflowConnect(deviceaction, toptrain, downtrain, routegroup, passerStation, passerAi) { + const scope = this; + this.teststomp = new StompClient(); - // let topic = '/user/queue/simulation/jl3d/'+routegroup; - let topic = '/user/queue/simulation/'+ routegroup +'/jl3d'; - let header = {'X-Token': getToken() }; + // let topic = '/user/queue/simulation/jl3d/'+routegroup; + const topic = '/user/queue/simulation/' + routegroup + '/jl3d'; + const header = {'X-Token': getToken() }; - socketon(topic); + socketon(topic); - function socketon(topic) { - try { - scope.teststomp.subscribe(topic, callback, header); - } catch (error) { - console.error('websocket订阅失败'); - } + function socketon(topic) { + try { + scope.teststomp.subscribe(topic, callback, header); + } catch (error) { + console.error('websocket订阅失败'); + } - }; + } - this.socketoff = function(topic) { - scope.teststomp.unsubscribe(topic); - }; + this.socketoff = function(topic) { + scope.teststomp.unsubscribe(topic); + }; - // 仿真socket接口回调函数 - function callback(Response) { - const data = JSON.parse(Response.body); + // 仿真socket接口回调函数 + function callback(Response) { + const data = JSON.parse(Response.body); - if(data.type == "DeviceCtrl_3D"){ - if(data.body.type == "PSD"){ - if(data.body.code == passerStation.nowStation.toppsd){ - if(data.body.command == 'G'){ + if (data.type == 'DeviceCtrl_3D') { + if (data.body.type == 'PSD') { + if (data.body.code == passerStation.nowStation.toppsd) { + if (data.body.command == 'G') { - deviceaction.top.action.reset(); - deviceaction.top.action.time =deviceaction.top.action._clip.duration; - deviceaction.top.action.timeScale = -1; - deviceaction.top.action.play(); - }else{ - passerAi.passerout("top") - deviceaction.top.action.reset(); - deviceaction.top.action.time = 0; - deviceaction.top.action.timeScale = 1; - deviceaction.top.action.play(); - } - } - if(data.body.code == passerStation.nowStation.downpsd){ - if(data.body.command == 'G'){ - deviceaction.down.action.reset(); - deviceaction.down.action.time = deviceaction.down.action._clip.duration; - deviceaction.down.action.timeScale = -1; - deviceaction.down.action.play(); - }else{ - passerAi.passerout("down"); - deviceaction.down.action.reset(); - deviceaction.down.action.time = 0; - deviceaction.down.action.timeScale = 1; - deviceaction.down.action.play(); - } + deviceaction.top.action.reset(); + deviceaction.top.action.time = deviceaction.top.action._clip.duration; + deviceaction.top.action.timeScale = -1; + deviceaction.top.action.play(); + } else { + passerAi.passerout('top'); + deviceaction.top.action.reset(); + deviceaction.top.action.time = 0; + deviceaction.top.action.timeScale = 1; + deviceaction.top.action.play(); + } + } + if (data.body.code == passerStation.nowStation.downpsd) { + if (data.body.command == 'G') { + deviceaction.down.action.reset(); + deviceaction.down.action.time = deviceaction.down.action._clip.duration; + deviceaction.down.action.timeScale = -1; + deviceaction.down.action.play(); + } else { + passerAi.passerout('down'); + deviceaction.down.action.reset(); + deviceaction.down.action.time = 0; + deviceaction.down.action.timeScale = 1; + deviceaction.down.action.play(); + } - } - } - if(data.body.type == "TRAIN_DOOR"){ - if(toptrain.nowcode == data.body.trainCode){ + } + } + if (data.body.type == 'TRAIN_DOOR') { + if (toptrain.nowcode == data.body.trainCode) { - if(data.body.command == 'G'){ - closetraindoor(toptrain,data.body.code,"top"); + if (data.body.command == 'G') { + closetraindoor(toptrain, data.body.code, 'top'); - }else{ - opentraindoor(toptrain,data.body.code,"top"); + } else { + opentraindoor(toptrain, data.body.code, 'top'); - } + } - } - if(downtrain.nowcode == data.body.trainCode){ - // console.log(data.body); - if(data.body.command == 'G'){ - closetraindoor(downtrain,data.body.code,"down"); + } + if (downtrain.nowcode == data.body.trainCode) { + // console.log(data.body); + if (data.body.command == 'G') { + closetraindoor(downtrain, data.body.code, 'down'); - }else{ - opentraindoor(downtrain,data.body.code,"down"); + } else { + opentraindoor(downtrain, data.body.code, 'down'); - } + } - } - } - } + } + } + } - if(data.type == "TrainRun_3D"){ + if (data.type == 'TrainRun_3D') { - for(let i=0,leni = data.body.length;i { - location.reload(); - }); - } - } - let actions; + } else { + if (downtrain.nowcode == data.body[i].code) { + downtrain.position.x += 1; + } + } + } + } + // if(data.type == 'Simulation_Over') { + // store.dispatch('LogOut').then(() => { + // location.reload(); + // }); + // } + } + let actions; - function opentraindoor(train,doorcode,direct){ - if(direct == "top"){ - if(doorcode == "1"){ - actions = train.action.down; - } + function opentraindoor(train, doorcode, direct) { + if (direct == 'top') { + if (doorcode == '1') { + actions = train.action.down; + } - if(doorcode == "2"){ - actions = train.action.top; - } - }else{ - if(doorcode == "1"){ - actions = train.action.top; - } + if (doorcode == '2') { + actions = train.action.top; + } + } else { + if (doorcode == '1') { + actions = train.action.top; + } - if(doorcode == "2"){ - actions = train.action.down; - } - } + if (doorcode == '2') { + actions = train.action.down; + } + } - for(let an=actions.length-1;an>=0;an--){ - actions[an].reset(); - actions[an].time = 0; - actions[an].timeScale = 1; - actions[an].play(); - } - } - function closetraindoor(train,doorcode,direct){ + for (let an = actions.length - 1; an >= 0; an--) { + actions[an].reset(); + actions[an].time = 0; + actions[an].timeScale = 1; + actions[an].play(); + } + } + function closetraindoor(train, doorcode, direct) { - if(direct == "top"){ - if(doorcode == "1"){ - actions = train.action.down; - } - if(doorcode == "2"){ - actions = train.action.top; - } - toptrain.nowcode = null; - }else{ - if(doorcode == "1"){ - actions = train.action.top; - } - if(doorcode == "2"){ - actions = train.action.down; - } - downtrain.nowcode = null; - } + if (direct == 'top') { + if (doorcode == '1') { + actions = train.action.down; + } + if (doorcode == '2') { + actions = train.action.top; + } + toptrain.nowcode = null; + } else { + if (doorcode == '1') { + actions = train.action.top; + } + if (doorcode == '2') { + actions = train.action.down; + } + downtrain.nowcode = null; + } - for(let an=actions.length-1;an>=0;an--){ - actions[an].reset(); - actions[an].time = actions[an]._clip.duration; - actions[an].timeScale = -1; - actions[an].play(); - } + for (let an = actions.length - 1; an >= 0; an--) { + actions[an].reset(); + actions[an].time = actions[an]._clip.duration; + actions[an].timeScale = -1; + actions[an].play(); + } - } + } }