rt-sim-training-client/src/views/newMap/displayNew/index.vue

266 lines
9.8 KiB
Vue
Raw Normal View History

<template>
2020-08-20 20:27:19 +08:00
<div class="main" :style="{width: canvasWidth+'px',height:'100%',position:'absolute',overflow:'hidden'}">
<template>
<transition name="el-zoom-in-bottom">
<map-system-draft ref="mapCanvas" @back="back" />
</transition>
2020-08-31 13:27:27 +08:00
<status-icon v-if="($route.query.lineCode == '11' || $route.query.lineCode == '10') && isDemon" ref="statusIcon" />
2020-08-20 20:27:19 +08:00
<menu-demon v-if="isDemon" ref="menuDemon" :offset="offset" :offset-bottom="offsetBottom" :data-error="dataError" :text-status-height="textStatusHeight" />
<menu-lesson v-if="isLesson" ref="lessonMenu" :offset="offset" :data-error="dataError" :offset-bottom="offsetBottom" :tip-bottom="tipBottom" />
<menu-exam v-if="isExam" ref="menuExam" :offset="offset" :data-error="dataError" :offset-bottom="offsetBottom" />
2020-08-13 16:18:19 +08:00
<menu-script
v-if="isScript"
ref="menuScript"
:offset-bottom="offsetBottom"
:offset="offset"
:project="project"
:text-status-height="textStatusHeight"
:data-error="dataError"
/>
2020-06-29 15:55:31 +08:00
<menu-practice
v-if="isPractice"
ref="menuPractice"
:offset="offset"
:offset-bottom="offsetBottom"
2020-06-29 15:55:31 +08:00
:data-error="dataError"
/>
2020-08-26 13:21:47 +08:00
<menu-dispather-contest v-if="isContest" ref="menuDispatherContest" :offset="offset" :offset-bottom="offsetBottom" :data-error="dataError" :text-status-height="textStatusHeight" />
2020-07-14 18:14:39 +08:00
</template>
2020-10-13 17:32:39 +08:00
<menu-train-list v-if="isDemon||isContest" @setCenter="setCenter" />
2020-08-20 20:27:19 +08:00
<menu-system-time ref="menuSystemTime" :offset="offset" :group="group" />
</div>
</template>
<script>
2020-08-20 20:39:38 +08:00
import { getSessionStorage } from '@/utils/auth';
2020-08-20 20:27:19 +08:00
import { mapGetters } from 'vuex';
import { OperateMode } from '@/scripts/ConstDic';
import { timeFormat } from '@/utils/date';
import MapSystemDraft from '@/views/newMap/mapsystemNew/index';
2020-06-29 15:55:31 +08:00
import StatusIcon from '@/views/components/StatusIcon/statusIcon';
2020-08-20 20:27:19 +08:00
import MenuDemon from '@/views/newMap/displayNew/menuDemon';
2020-08-27 14:02:27 +08:00
2020-08-26 13:21:47 +08:00
import MenuExam from './exam/index';
import MenuLesson from './lesson/index';
2020-08-27 14:02:27 +08:00
import MenuScript from './scriptDisplay/scriptRecord/index';
import MenuDispatherContest from './dispatherContest/index';
2020-06-29 15:55:31 +08:00
import MenuTrainList from '@/views/newMap/displayNew/menuTrainList';
2020-08-20 20:27:19 +08:00
import MenuSystemTime from '@/views/newMap/displayNew/menuSystemTime';
2020-08-27 14:02:27 +08:00
2020-08-20 20:27:19 +08:00
import { clearSimulation, getSimulationInfoNew } from '@/api/simulation';
2020-06-29 15:55:31 +08:00
import { loadNewMapDataByGroup } from '@/utils/loaddata';
2020-08-20 20:27:19 +08:00
import { EventBus } from '@/scripts/event-bus';
export default {
name: 'DisplayDraft',
components: {
MapSystemDraft,
2020-06-29 15:55:31 +08:00
StatusIcon,
2020-08-20 20:27:19 +08:00
MenuDemon,
2020-06-29 15:55:31 +08:00
MenuExam,
MenuLesson,
2020-08-20 20:27:19 +08:00
MenuSystemTime,
2020-08-20 20:39:38 +08:00
MenuTrainList,
2020-08-26 13:21:47 +08:00
MenuDispatherContest,
2020-08-20 20:39:38 +08:00
MenuScript
},
data() {
return {
offset: 15,
offsetBottom: 15,
tipBottom: 0,
2020-08-20 20:27:19 +08:00
textStatusHeight: 0,
planRunning:false,
2020-08-20 20:27:19 +08:00
dataError: false,
group:''
};
},
2020-06-29 15:55:31 +08:00
computed:{
...mapGetters([
'canvasWidth'
2020-07-29 18:26:58 +08:00
]),
2020-06-29 15:55:31 +08:00
mode() {
return this.$route.params.mode;
},
2020-08-26 13:21:47 +08:00
project() {
return getSessionStorage('project');
},
2020-06-29 15:55:31 +08:00
isDemon() {
2020-08-26 13:21:47 +08:00
return this.mode === 'demon' && this.project != 'drts';
},
isContest() {
return this.mode === 'demon' && this.project == 'drts';
2020-06-29 15:55:31 +08:00
},
isExam() {
return this.mode === 'exam';
},
isLesson() {
return (this.mode === 'teach' || this.mode === 'manage');
},
isScript() {
return this.mode === 'script';
},
2020-08-20 20:27:19 +08:00
isPractice() {
return this.mode === 'practice';
},
mapId() {
return this.$route.query.mapId;
},
2020-08-20 20:27:19 +08:00
width() {
return this.$store.state.app.width;
},
2020-08-20 20:27:19 +08:00
height() {
return this.$store.state.app.height;
}
},
2020-08-20 20:27:19 +08:00
watch:{
2020-06-29 15:55:31 +08:00
'$store.state.socket.permissionOver': function () {
this.$alert('用户权限已被收回', '提示', {
confirmButtonText: '确定',
callback: action => {
this.back();
}
});
},
2020-08-20 20:27:19 +08:00
'$store.state.config.menuBarLoadedCount': function (val) { // menuBar加载完成
this.setPosition();
},
'$store.state.app.windowSizeCount': function() { // 窗口缩放
this.setWindowSize();
},
'$store.state.training.prdType': function (val) { // 根据权限类型计算高度
this.setPosition();
},
2020-06-29 15:55:31 +08:00
'$store.state.map.mapViewLoadedCount': function (val) { // 地图视图加载完成标识 开始加载默认状态
if (this.planRunning) {
this.$store.dispatch('training/simulationStart');
}
2020-08-20 20:27:19 +08:00
},
$route() {
this.initLoadData();
}
},
2020-06-19 18:58:55 +08:00
beforeDestroy() {
2020-06-29 15:55:31 +08:00
this.quit(this.group);
2020-06-19 18:58:55 +08:00
this.$store.dispatch('training/reset');
this.$store.dispatch('map/mapClear');
},
2020-08-20 20:27:19 +08:00
async mounted() {
this.setWindowSize();
this.initLoadData();
},
2020-06-29 15:55:31 +08:00
methods:{
2020-08-20 20:27:19 +08:00
// 结束加载状态
endViewLoading(isSuccess) {
if (!isSuccess) {
this.$store.dispatch('map/mapClear');
2020-07-23 17:09:29 +08:00
}
2020-08-20 20:27:19 +08:00
this.$nextTick(() => {
EventBus.$emit('viewLoading', false);
});
},
// 销毁仿真
quit(group) {
clearSimulation(group);
this.$store.dispatch('training/over');
2020-07-23 17:09:29 +08:00
},
2020-06-29 15:55:31 +08:00
// 仿真错误时,被动退出时调用
async back() {
if (this.isExam) {
await this.$refs.menuExam.back();
} else if (this.isLesson) {
await this.$refs.lessonMenu.back();
} else if (this.isDemon) {
await this.$refs.menuDemon.back();
} else if (this.isScript) {
await this.$refs.menuScript.back();
2020-08-27 14:02:27 +08:00
} else if (this.isContest) {
await this.$refs.menuDispatherContest.back();
2020-06-29 15:55:31 +08:00
}
},
2020-08-26 13:21:47 +08:00
// 以某个设备居中显示
2020-08-20 20:27:19 +08:00
setCenter(code) {
this.$jlmap.setCenter(code);
},
2020-11-05 13:17:40 +08:00
// 设置各个按钮的定位
2020-08-20 20:27:19 +08:00
setPosition() {
this.$nextTick(() => {
this.offset = 10;
this.offsetBottom = 15;
const menuBar = document.getElementById('menuBar');
const menuTool = document.getElementById('menuTool');
const menuBottom = document.getElementById('menuButton');
const menuButtonsBox = document.getElementById('menuButtons_box');
const textStatus = document.getElementById('textStatus');
if (menuBar) {
this.offset = (menuBar.offsetHeight || 0) + 15;
}
if (menuTool) {
this.offset = (menuTool.offsetHeight || 0) + 15;
}
const buttonWidth = this.width - 1200; // B box widht
if (menuBottom && buttonWidth < 780) {
this.offsetBottom = (menuBottom.offsetHeight || 0) + 15;
}
if (menuButtonsBox) {
this.tipBottom = (menuButtonsBox.offsetHeight || 0) + 15;
}
if (textStatus) {
this.textStatusHeight = textStatus.offsetHeight || 0;
textStatus.style.top = this.offset - 15 + 'px';
}
});
2020-06-29 15:55:31 +08:00
},
// 缩放设置
setWindowSize() {
const width = this.width;
2020-07-29 18:26:58 +08:00
const height = this.height;
2020-06-29 15:55:31 +08:00
this.$store.dispatch('config/resize', { width, height });
// this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
},
2020-08-20 20:27:19 +08:00
// 初始化
initLoadData() {
2020-08-26 14:08:50 +08:00
this.group = this.$route.query.group;
2020-08-20 20:27:19 +08:00
this.$store.dispatch('training/reset');
this.loadSimulationInfo();
this.loadMapData();
},
2020-07-31 15:24:44 +08:00
// 新版地图根据仿真group获取仿真基础信息
2020-06-29 15:55:31 +08:00
async loadSimulationInfo() {
const resp = await getSimulationInfoNew(this.group);
if (resp && resp.code == 200 && resp.data && !resp.data.dataError) {
this.dataError = false;
2020-07-31 18:49:35 +08:00
this.$store.dispatch('scriptRecord/updateSimulationPause', resp.data.pause); // 是否暂停判断
2020-06-29 15:55:31 +08:00
this.$store.dispatch('training/setInitTime', +new Date(`${new Date().toLocaleDateString()} ${timeFormat(resp.data.systemTime)}`));
2020-08-03 13:27:17 +08:00
this.$store.dispatch('training/countTime');
2020-06-29 15:55:31 +08:00
this.planRunning = resp.data.planRunning;
2020-11-05 17:32:48 +08:00
if (resp.data.planRunning) {
this.$store.commit('training/start');
2020-06-29 15:55:31 +08:00
}
} else if (resp && resp.code == 200 && resp.data && resp.data.dataError) {
this.dataError = true;
this.$messageBox('此地图数据正在维护中,无法运行!');
}
},
2020-08-20 20:27:19 +08:00
// 加载地图数据
loadMapData() {
2020-06-29 15:55:31 +08:00
if (parseInt(this.mapId)) {
2020-08-20 20:27:19 +08:00
this.loadNewMapDataByGroup(this.group);
2020-06-29 15:55:31 +08:00
} else {
this.endViewLoading();
}
},
2020-06-29 15:55:31 +08:00
// 通过group加载地图数据
2019-12-30 09:00:16 +08:00
async loadNewMapDataByGroup(group) {
try {
2020-08-20 20:27:19 +08:00
this.$store.dispatch('training/changeOperateMode', { mode: OperateMode.NORMAL }); // 默认为正常模式
2019-12-30 09:00:16 +08:00
await loadNewMapDataByGroup(group);
await this.$store.dispatch('training/setMapDefaultState');
} catch (error) {
this.$messageBox(`获取地图数据失败: ${error.message}`);
this.endViewLoading();
}
}
}
};
</script>