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

106 lines
2.9 KiB
Vue
Raw Normal View History

<template>
2019-10-28 11:07:33 +08:00
<div class="map-view">
<jlmap-visual ref="jlmapVisual" />
2019-10-28 11:07:33 +08:00
</div>
</template>
<script>
2019-10-28 11:07:33 +08:00
import JlmapVisual from '@/views/jlmap/index';
import { loadMapDataById } from '@/utils/loaddata';
import { EventBus } from '@/scripts/event-bus';
2019-10-28 11:07:33 +08:00
export default {
2019-10-30 13:58:34 +08:00
name: 'MapPreview',
components: {
JlmapVisual
},
props: {
widthLeft: {
type: Number,
required: true
}
},
data() {
return {
size: {
width: document.documentElement.clientWidth - 400,
height: document.documentElement.clientHeight - 80
}
};
},
computed: {
mapId() {
return this.$route.params.mapId;
},
height() {
return this.$store.state.app.height - 50 - 30;
}
},
watch: {
widthLeft(val) {
this.setWindowSize();
},
$route() {
this.$nextTick(() => {
this.initLoadData();
});
},
'$store.state.app.windowSizeCount': function() {
this.setWindowSize();
}
},
async beforeDestroy() {
await this.$store.dispatch('map/mapClear');
},
async mounted() {
await this.setWindowSize();
await this.initLoadData();
},
methods: {
async initLoadData() {
if (parseInt(this.mapId)) {
await this.loadMapDataById(this.mapId);
} else {
this.endViewLoading();
}
},
// 通过id加载地图数据
async loadMapDataById(mapId) {
try {
await this.$store.dispatch('training/changeMode', { mode: null });
await loadMapDataById(mapId);
await this.$store.dispatch('training/over');
await this.$store.dispatch('training/setMapDefaultState');
await this.$store.dispatch('map/clearJlmapTrainView');
await this.$store.dispatch('map/setTrainWindowShow', false);
} catch (error) {
this.$messageBox(`获取地图数据失败: ${error.message}`);
this.endViewLoading();
}
},
// 结束加载状态
endViewLoading(isSuccess) {
if (!isSuccess) {
this.$store.dispatch('map/mapClear');
}
2019-10-30 13:58:34 +08:00
this.$nextTick(() => {
EventBus.$emit('viewLoading', false);
});
},
setWindowSize() {
this.$nextTick(() => {
const width = this.$store.state.app.width - (this.widthLeft || 450);
const height = this.height;
this.$store.dispatch('config/resize', { width, height });
});
}
}
2019-10-28 11:07:33 +08:00
};
</script>
<style lang="scss" scoped>
.map-view {
float: left;
width: auto;
}
</style>