2019-07-25 10:32:29 +08:00
|
|
|
<template>
|
2019-08-06 10:11:32 +08:00
|
|
|
<div class="mainContext">
|
2019-11-08 13:01:41 +08:00
|
|
|
<map-common ref="mapCommon" />
|
2019-08-06 10:11:32 +08:00
|
|
|
</div>
|
2019-07-25 10:32:29 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-08-06 10:11:32 +08:00
|
|
|
import MapCommon from './common/index';
|
|
|
|
import { handleToken } from '@/utils/auth';
|
2019-11-12 17:27:30 +08:00
|
|
|
import { creatSubscribe, clearSubscribe, displayTopic, planTopic, designDisplayTopic} from '@/utils/stomp';
|
2019-08-06 10:11:32 +08:00
|
|
|
import { sendCommand } from '@/api/jmap/training';
|
2019-11-08 17:52:30 +08:00
|
|
|
import { getSessionStorage } from '@/utils/auth';
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-08-06 10:11:32 +08:00
|
|
|
export default {
|
2019-11-08 13:01:41 +08:00
|
|
|
name: 'MapSystemDraft',
|
|
|
|
components: {
|
|
|
|
MapCommon
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
topic: '/user/queue/training',
|
|
|
|
stomp: null,
|
|
|
|
currentMap: null,
|
2019-11-08 17:52:30 +08:00
|
|
|
mode: '',
|
|
|
|
isDesignPlatform: false
|
2019-11-08 13:01:41 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
group() { return this.$route.query.group; }
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$store.state.map.mapViewLoadedCount': function (val) {
|
|
|
|
this.subscribe();
|
|
|
|
},
|
|
|
|
'$store.state.socket.equipmentStatus': function (val) {
|
|
|
|
if (val.length) {
|
|
|
|
this.statusMessage(val);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'$store.state.socket.trainStationList': function (val) {
|
|
|
|
if (val.length) {
|
|
|
|
this.runFactMessage(val);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'$store.state.socket.simulationError': function (val) {
|
|
|
|
if (val) {
|
|
|
|
this.simulationError(val);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'$store.state.socket.simulationReset': function (val) {
|
|
|
|
if (val) {
|
|
|
|
this.simulationReset(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
window.onbeforeunload = this.clearSubscribe;
|
|
|
|
this.mode = this.$route.params.mode || '';
|
|
|
|
this.currentMap = this.$refs.mapCommon;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$store.dispatch('config/resetCanvasOffset');
|
|
|
|
}, 100);
|
|
|
|
});
|
2019-11-08 17:52:30 +08:00
|
|
|
this.isDesignPlatform = getSessionStorage('project').startsWith('design');
|
2019-11-08 13:01:41 +08:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.clearSubscribe();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async mapViewLoaded(loading) {
|
|
|
|
this.currentMap.mapViewLoaded(loading);
|
|
|
|
},
|
|
|
|
async statusMessage(list) {
|
|
|
|
await this.$store.dispatch('training/updateMapState', list);
|
|
|
|
await this.$store.dispatch('socket/setEquipmentStatus');
|
|
|
|
},
|
|
|
|
async runFactMessage(list) {
|
|
|
|
await this.$store.dispatch('runPlan/updateRunPlanData', list);
|
|
|
|
await this.$store.dispatch('socket/setTrainStationList');
|
|
|
|
},
|
|
|
|
async simulationError() {
|
|
|
|
await this.$store.dispatch('map/clearJlmapTrainView');
|
|
|
|
await this.$store.dispatch('map/setTrainWindowShow', false);
|
|
|
|
await this.$store.dispatch('socket/setSimulationError');
|
|
|
|
await this.$store.dispatch('training/setMapDefaultState');
|
|
|
|
this.clearSubscribe();
|
|
|
|
this.$confirm(this.$t('tip.getMapStateDataException'), this.$t('tip.hint'), {
|
|
|
|
confirmButtonText: this.$t('global.confirm'),
|
|
|
|
showCancelButton: false,
|
|
|
|
type: 'warning'
|
|
|
|
}).then(() => {
|
|
|
|
this.$emit('back');
|
|
|
|
}).catch(() => {
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async simulationReset() {
|
|
|
|
await this.$store.dispatch('map/clearJlmapTrainView');
|
|
|
|
await this.$store.dispatch('map/setTrainWindowShow', false);
|
|
|
|
await this.$store.dispatch('training/over');
|
|
|
|
await this.$store.dispatch('socket/setSimulationReset');
|
|
|
|
await this.$store.dispatch('socket/setSimulationStart');
|
|
|
|
await this.$store.dispatch('training/setMapDefaultState');
|
|
|
|
},
|
|
|
|
async subscribe() {
|
|
|
|
this.clearSubscribe();
|
|
|
|
const header = { group: this.group || '', 'X-Token': handleToken() };
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-11-12 17:27:30 +08:00
|
|
|
if (this.mode === 'plan') {
|
2019-11-08 13:01:41 +08:00
|
|
|
creatSubscribe(planTopic, header);
|
|
|
|
} else {
|
2019-11-08 17:52:30 +08:00
|
|
|
creatSubscribe(this.isDesignPlatform ? designDisplayTopic : displayTopic, header);
|
2019-11-08 13:01:41 +08:00
|
|
|
}
|
2019-07-25 10:32:29 +08:00
|
|
|
|
2019-11-08 13:01:41 +08:00
|
|
|
await this.$store.dispatch('training/setHasSubscribed');
|
|
|
|
},
|
|
|
|
clearSubscribe() {
|
2019-11-12 17:27:30 +08:00
|
|
|
if (this.mode === 'plan') {
|
2019-11-08 13:01:41 +08:00
|
|
|
clearSubscribe(planTopic);
|
|
|
|
} else {
|
2019-11-08 17:52:30 +08:00
|
|
|
clearSubscribe(this.isDesignPlatform ? designDisplayTopic : displayTopic);
|
2019-11-08 13:01:41 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
sendDeviceChangeEvent(data, header) {
|
|
|
|
// 发送设备操作事件到服务器
|
|
|
|
sendCommand('', data).then(response => {
|
|
|
|
}).catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 10:11:32 +08:00
|
|
|
};
|
2019-07-25 10:32:29 +08:00
|
|
|
</script>
|
|
|
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
|
|
|
@import "src/styles/mixin.scss";
|
|
|
|
|
|
|
|
.mainContext {
|
|
|
|
font-family: "Helvetica Neue ", Helvetica, "PingFang SC ", "Hiragino Sans GB ", "Microsoft YaHei ", "PingFang SC ", Arial, consolas;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-moz-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
}
|
2019-08-06 10:11:32 +08:00
|
|
|
</style>
|