rt-sim-training-client/src/views/designPlatform/bigScreen.vue

207 lines
6.7 KiB
Vue
Raw Normal View History

2020-05-06 16:57:07 +08:00
<template>
<div class="map-view">
2020-05-13 16:29:10 +08:00
<div v-show="maskOpen" class="mask" :style="{'width': maskWidth}" />
2020-05-06 16:57:07 +08:00
<jlmap-visual ref="jlmapVisual" />
2020-05-13 17:34:38 +08:00
<div v-show="disPlay" class="display-draft">
2020-05-11 17:36:21 +08:00
<el-button-group>
<el-button type="primary" @click="back">{{ $t('scriptRecord.scriptBack') }}</el-button>
</el-button-group>
</div>
2020-05-06 16:57:07 +08:00
</div>
</template>
<script>
import JlmapVisual from '@/views/newMap/jlmapNew/index';
import { loadNewMapDataByGroup, loadMapDataById } from '@/utils/loaddata';
2020-05-13 17:34:38 +08:00
import { clearSimulation } from '@/api/simulation';
2020-05-06 16:57:07 +08:00
import { EventBus } from '@/scripts/event-bus';
import { mapGetters } from 'vuex';
2020-05-11 18:15:49 +08:00
import { creatSubscribe, clearSubscribe, displayTopic} from '@/utils/stomp';
import { getToken } from '@/utils/auth';
2020-05-06 16:57:07 +08:00
export default {
name: 'MapPreview',
components: {
JlmapVisual
},
props: {
widthLeft: {
type: Number,
2020-05-09 20:13:32 +08:00
default: 0
2020-05-06 16:57:07 +08:00
}
},
data() {
return {
size: {
width: document.documentElement.clientWidth - 400,
height: document.documentElement.clientHeight - 80
2020-05-13 16:29:10 +08:00
},
maskOpen: false,
2020-05-13 17:34:38 +08:00
maskWidth: '100%',
disPlay: false
2020-05-06 16:57:07 +08:00
};
},
computed: {
mapId() {
return this.$route.params.mapId;
},
height() {
return this.$store.state.app.height - 50 - 30;
},
2020-05-13 16:29:10 +08:00
...mapGetters('map', [
'bigScreenSplitConfig'
]),
2020-05-06 16:57:07 +08:00
...mapGetters('config', [
'canvasId'
])
},
watch: {
widthLeft(val) {
this.setWindowSize();
},
$route() {
this.$nextTick(() => {
this.initLoadData();
});
},
'$store.state.app.windowSizeCount': function() {
this.setWindowSize();
},
'$store.state.map.mapViewLoadedCount':function() {
this.$store.dispatch('map/setTrainWindowShow', false);
2020-05-06 17:18:06 +08:00
this.$jlmap.off('zoom');
2020-05-06 16:57:07 +08:00
this.$jlmap.off('pan');
2020-05-07 09:04:28 +08:00
this.handleUpdateScreen();
2020-05-13 17:34:38 +08:00
if (this.$route.query.group) {
this.subscribe();
}
2020-05-11 18:15:49 +08:00
},
'$store.state.socket.equipmentStatus': function (val) {
if (val.length && this.$route.query.group) {
2020-05-11 18:15:49 +08:00
this.statusMessage(val);
}
2020-05-06 16:57:07 +08:00
}
},
async beforeDestroy() {
await this.$store.dispatch('map/mapClear');
},
async mounted() {
await this.setWindowSize();
await this.initLoadData();
2020-05-13 17:34:38 +08:00
this.disPlay = true;
if (this.$route.path.includes('design/bigScreen')) {
this.disPlay = false;
}
2020-05-06 16:57:07 +08:00
},
methods: {
async initLoadData() { // 加载地图数据
2020-05-11 18:15:49 +08:00
if (this.$route.query.group) {
await loadNewMapDataByGroup(this.$route.query.group);
2020-05-06 16:57:07 +08:00
} else {
2020-05-13 17:34:38 +08:00
this.loadMapDataById(this.$route.params.mapId);
2020-05-06 16:57:07 +08:00
}
},
// 通过id加载地图数据
async loadMapDataById(mapId) {
2020-05-13 17:34:38 +08:00
try {
await this.$store.dispatch('training/changeMode', { mode: null });
loadMapDataById(mapId).then(()=>{
this.$store.dispatch('training/over');
this.$store.dispatch('training/setMapDefaultState');
this.$store.dispatch('map/clearJlmapTrainView');
});
} catch (error) {
this.$messageBox(`获取地图数据失败: ${error.message}`);
this.endViewLoading();
2020-05-06 16:57:07 +08:00
}
2020-05-13 17:34:38 +08:00
},
async statusMessage(list) {
await this.$store.dispatch('training/updateMapState', list);
await this.$store.dispatch('socket/setEquipmentStatus');
2020-05-06 16:57:07 +08:00
},
setWindowSize() {
this.$nextTick(() => {
2020-05-09 20:13:32 +08:00
if (this.widthLeft) {
const width = this.$store.state.app.width - (this.widthLeft || 450) - 2;
2020-05-13 16:29:10 +08:00
this.maskWidth = `calc(100% - ${this.widthLeft || 450}px)`;
2020-05-09 20:13:32 +08:00
const height = this.height;
this.$store.dispatch('config/resize', { width, height });
} else {
const width = this.$store.state.app.width - 2;
const height = this.$store.state.app.height;
this.$store.dispatch('config/resize', { width, height });
}
2020-05-06 16:57:07 +08:00
});
2020-05-07 09:04:28 +08:00
},
handleUpdateScreen() {
2020-05-13 16:29:10 +08:00
this.maskOpen = false;
if (this.bigScreenSplitConfig.length) {
if (this.widthLeft) {
const size = {
width: this.$store.state.app.width - (this.widthLeft || 450) - 2,
height: this.height,
list: this.bigScreenSplitConfig.map(ele => ele.position)
};
this.$jlmap.setUpdateScreen(size);
} else {
const size = {
width: this.$store.state.app.width - 2,
height: this.$store.state.app.height,
list: this.bigScreenSplitConfig.map(ele => ele.position)
};
this.$jlmap.setUpdateScreen(size);
}
this.$refs.jlmapVisual.handleStateLoaded();
2020-05-09 20:13:32 +08:00
} else {
2020-05-13 16:29:10 +08:00
this.maskOpen = true;
this.$messageBox('该线路没有大屏切割位置信息, 请前往地图绘制编辑');
2020-05-09 20:13:32 +08:00
}
2020-05-11 17:36:21 +08:00
},
2020-05-13 17:34:38 +08:00
async back() {
if (this.$route.query.group) {
await clearSimulation(this.$route.query.group);
this.clearSubscribe();
}
2020-05-11 17:36:21 +08:00
this.$store.dispatch('training/over').then(() => {
EventBus.$emit('runPlanStop');
EventBus.$emit('chatSubscribeStop');
history.go(-1);
});
2020-05-11 18:15:49 +08:00
},
async subscribe() {
this.clearSubscribe();
const header = { group: this.$route.query.group || '', 'X-Token': getToken() };
creatSubscribe(`${displayTopic}\/${this.$route.query.group}`, header);
await this.$store.dispatch('training/setHasSubscribed');
},
clearSubscribe() {
clearSubscribe(`${displayTopic}\/${this.$route.query.group}`);
2020-05-06 16:57:07 +08:00
}
}
};
</script>
<style lang="scss" scoped>
.map-view {
float: left;
width: auto;
2020-05-13 16:29:10 +08:00
}
.mask{
opacity: 1;
background: #000;
position: absolute;
right: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 9;
2020-05-06 16:57:07 +08:00
}
2020-05-11 17:36:21 +08:00
.display-draft {
position: absolute;
float: right;
right: 15px;
bottom: 15px;
2020-05-13 17:34:38 +08:00
z-index: 19;
2020-05-11 17:36:21 +08:00
}
2020-05-06 16:57:07 +08:00
</style>