diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index d2fb102..e6dff2f 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -2,7 +2,7 @@ import { GraphicApp, GraphicData, GraphicState, - // ClientEngine, + ClientEngine, } from 'src/jl-graphic'; import { TrainState } from './graphics/TrainInteraction'; import { Train, TrainTemplate } from 'src/graphics/train/Train'; @@ -308,91 +308,91 @@ export async function loadLineDatas(app: GraphicApp) { } }); - // app.enableWsMassaging({ - // engine: ClientEngine.Centrifugo, - // wsUrl: `${getWebsocketUrl()}`, - // token: getOnlyToken() as string, - // }); + app.enableWsMassaging({ + engine: ClientEngine.Centrifugo, + wsUrl: `${getWebsocketUrl()}`, + token: getOnlyToken() as string, + }); - // app.subscribe({ - // // destination: `/simulation/${simulationId}/devices/status`, - // destination: `simulation-${simulationId}-devices-status`, - // messageConverter: (message: Uint8Array) => { - // const states: GraphicState[] = []; - // const storage = state.PushedDevicesStatus.deserialize(message); - // // console.log(storage, 'storage'); - // if (storage.all) { - // storage.allStatus.sectionState.forEach((item) => { - // if (state.SectionType[item.type] == 'Axle') { - // //计轴区段 - // // states.push(new AxleCountingState(item)); - // } else if (state.SectionType[item.type] == 'Logic') { - // // 逻辑区段 - // // states.push(new LogicSectionState(item)); - // } else if (state.SectionType[item.type] == 'Physic') { - // // 物理区段 - // // states.push(new SectionState(item)); - // } - // }); - // storage.allStatus.switchState.forEach((item) => { - // // 道岔 - // states.push(new TurnoutStates(item)); - // }); - // storage.allStatus.trainState.forEach((item) => { - // // 列车 - // states.push(new TrainState(item)); - // }); - // } else { - // storage.varStatus.updatedSection.forEach((item) => { - // if (state.SectionType[item.type] == 'Axle') { - // //计轴区段 - // // states.push(new AxleCountingState(item)); - // } else if (state.SectionType[item.type] == 'Logic') { - // // 逻辑区段 - // // states.push(new LogicSectionState(item)); - // } else if (state.SectionType[item.type] == 'Physic') { - // // 物理区段 - // // states.push(new SectionState(item)); - // } - // }); - // storage.varStatus.updatedSwitch.forEach((item) => { - // // 道岔 - // states.push(new TurnoutStates(item)); - // }); - // storage.varStatus.updatedTrain.forEach((item) => { - // // 列车 - // states.push(new TrainState(item)); - // }); - // storage.varStatus.removedTrainId.forEach((item) => { - // // 移除列车 - // const train = app.queryStore.queryByCodeAndType(item, Train.Type); - // if (train) { - // app.deleteGraphics(train); - // } - // }); - // } - // if (states && states.length > 0) { - // lineStore.setSocketStates(states); - // } - // return states; - // }, - // }); + app.subscribe({ + // destination: `/simulation/${simulationId}/devices/status`, + destination: `simulation-${simulationId}-devices-status`, + messageConverter: (message: Uint8Array) => { + const states: GraphicState[] = []; + const storage = state.PushedDevicesStatus.deserialize(message); + // console.log(storage, 'storage'); + if (storage.all) { + storage.allStatus.sectionState.forEach((item) => { + if (state.SectionType[item.type] == 'Axle') { + //计轴区段 + // states.push(new AxleCountingState(item)); + } else if (state.SectionType[item.type] == 'Logic') { + // 逻辑区段 + // states.push(new LogicSectionState(item)); + } else if (state.SectionType[item.type] == 'Physic') { + // 物理区段 + // states.push(new SectionState(item)); + } + }); + storage.allStatus.switchState.forEach((item) => { + // 道岔 + states.push(new TurnoutStates(item)); + }); + storage.allStatus.trainState.forEach((item) => { + // 列车 + states.push(new TrainState(item)); + }); + } else { + storage.varStatus.updatedSection.forEach((item) => { + if (state.SectionType[item.type] == 'Axle') { + //计轴区段 + // states.push(new AxleCountingState(item)); + } else if (state.SectionType[item.type] == 'Logic') { + // 逻辑区段 + // states.push(new LogicSectionState(item)); + } else if (state.SectionType[item.type] == 'Physic') { + // 物理区段 + // states.push(new SectionState(item)); + } + }); + storage.varStatus.updatedSwitch.forEach((item) => { + // 道岔 + states.push(new TurnoutStates(item)); + }); + storage.varStatus.updatedTrain.forEach((item) => { + // 列车 + states.push(new TrainState(item)); + }); + storage.varStatus.removedTrainId.forEach((item) => { + // 移除列车 + const train = app.queryStore.queryByCodeAndType(item, Train.Type); + if (train) { + app.deleteGraphics(train); + } + }); + } + if (states && states.length > 0) { + lineStore.setSocketStates(states); + } + return states; + }, + }); - // let msgNotify: null | ((props?: QNotifyUpdateOptions | undefined) => void) = - // null; - // app.on('websocket-connect-state-change', (connected) => { - // if (!connected && !msgNotify) { - // msgNotify = Notify.create({ - // type: 'negative', - // timeout: 0, - // position: 'top-right', - // message: '通信链接已断开!', - // }); - // } else if (msgNotify && connected) { - // msgNotify(); - // msgNotify = null; - // } - // }); + let msgNotify: null | ((props?: QNotifyUpdateOptions | undefined) => void) = + null; + app.on('websocket-connect-state-change', (connected) => { + if (!connected && !msgNotify) { + msgNotify = Notify.create({ + type: 'negative', + timeout: 0, + position: 'top-right', + message: '通信链接已断开!', + }); + } else if (msgNotify && connected) { + msgNotify(); + msgNotify = null; + } + }); } else { app.loadGraphic([]); }