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

312 lines
12 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>
<menu-demon v-if="isDemon" ref="menuDemon" :offset="offset" :offset-bottom="offsetBottom" :data-error="dataError" :text-status-height="textStatusHeight" @start="start" @end="end" />
2020-08-20 20:27:19 +08:00
<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" />
<menu-script v-if="isScript" ref="menuScript" :offset-bottom="offsetBottom" :offset="offset" :text-status-height="textStatusHeight" :data-error="dataError" @start="start" @end="end" />
<menu-dispather-contest v-if="isContest" ref="menuDispatherContest" :offset="offset" :offset-bottom="offsetBottom" :data-error="dataError" :text-status-height="textStatusHeight" @start="start" @end="end" />
2020-07-14 18:14:39 +08:00
</template>
2020-11-06 15:04:18 +08:00
<menu-train-list v-if="isDemon||isContest||isScript" @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';
2020-11-09 15:17:11 +08:00
import MapSystemDraft from '@/views/newMap/mapsystemNew/index';
2020-08-26 13:21:47 +08:00
import MenuLesson from './lesson/index';
2020-11-09 15:17:11 +08:00
import MenuDemon from './menuDemon';
import MenuExam from './exam/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
import { clearSimulation, getSimulationInfoNew, ranAsPlan, exitRunPlan } from '@/api/simulation';
// loadNewMapDataByGroup,
import { loadMapDataById } from '@/utils/loaddata';
2020-08-20 20:27:19 +08:00
import { EventBus } from '@/scripts/event-bus';
2020-11-09 15:17:11 +08:00
export default {
name: 'DisplayDraft',
components: {
MapSystemDraft,
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-11-13 14:14:18 +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-11-12 19:04:57 +08:00
isPlan() {
return this.mode === 'plan';
},
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() {
2020-11-27 14:05:10 +08:00
if (!this.isLesson && !this.isExam) {
2020-11-24 19:17:10 +08:00
this.initLoadData();
}
}
},
2020-06-19 18:58:55 +08:00
beforeDestroy() {
2020-11-09 15:17:11 +08:00
clearSimulation(this.group);
2020-06-19 18:58:55 +08:00
this.$store.dispatch('training/reset');
2020-11-24 16:53:13 +08:00
// this.$store.dispatch('map/mapClear');
},
2020-08-20 20:27:19 +08:00
async mounted() {
2020-11-11 09:13:41 +08:00
this.setWindowSize();
2020-08-20 20:27:19 +08:00
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);
});
},
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);
2020-11-09 15:17:11 +08:00
if (resp && resp.code == 200 && resp.data) {
if (!resp.data.dataError) {
this.$store.dispatch('scriptRecord/updateSimulationPause', resp.data.pause); // 是否暂停判断
this.$store.dispatch('training/setInitTime', +new Date(`${new Date().toLocaleDateString()} ${timeFormat(resp.data.systemTime)}`));
this.$store.dispatch('training/countTime');
this.planRunning = resp.data.planRunning;
if (resp.data.planRunning) {
this.$store.commit('training/start');
}
} else {
this.$messageBox('此地图数据正在维护中,无法运行!');
2020-06-29 15:55:31 +08:00
}
2020-11-09 15:17:11 +08:00
this.dataError = resp.data.dataError;
}
},
2020-08-20 20:27:19 +08:00
// 加载地图数据
loadMapData() {
2020-06-29 15:55:31 +08:00
if (parseInt(this.mapId)) {
// this.loadNewMapDataByGroup(this.group);
this.loadNewMapDataById(this.mapId);
2020-06-29 15:55:31 +08:00
} else {
this.endViewLoading();
}
},
2020-06-29 15:55:31 +08:00
// 通过group加载地图数据
async loadNewMapDataById(mapId) {
try {
2020-08-20 20:27:19 +08:00
this.$store.dispatch('training/changeOperateMode', { mode: OperateMode.NORMAL }); // 默认为正常模式
// await loadNewMapDataByGroup(group);
await loadMapDataById(mapId, 'Group');
await this.$store.dispatch('training/setMapDefaultState');
} catch (error) {
this.$messageBox(`获取地图数据失败: ${error.message}`);
this.endViewLoading();
}
},
start(model) { // 开始仿真
const data = {
time: model.initTime
};
if (this.$route.query.prdType === '04') {
data.loadNumber = model.loadNum;
}
ranAsPlan(data, this.group).then(res => {
this.$store.dispatch('training/setInitTime', +new Date(`${new Date().toLocaleDateString()} ${model.initTime}`));
}).catch(error => {
let message = '';
switch (error.code) {
case '5001':
message = this.$t('error.mapDataError');
break;
case '5002':
message = this.$t('error.runningChartDataError');
break;
case '5003':
message = this.$t('error.runningChartIsNotLoaded');
break;
case '5004':
message = this.$t('error.runningDataError');
break;
case '5000':
message = this.$t('error.systemError');
break;
case '4000':
message = this.$t('error.simulationDoesNotExist');
break;
case '4001':
message = this.$t('error.simulationOperationIsNotDefined');
break;
case '4002':
message = this.$t('error.simulationOperationProcessingMethodNotFound');
break;
case '4003':
message = this.$t('error.simulationOperationFailed');
break;
case '4004':
message = this.$t('error.operationConflict');
break;
default:
message = '按计划行车异常,请退出重试!';
// this.$messageBox('按计划行车异常,请退出重试!');
break;
}
this.$messageBox(message + '' + this.$t('error.startSimulationFailed'));
});
},
end() {
exitRunPlan(this.group).then(() => {
this.$store.dispatch('training/over').then(() => {
this.$store.dispatch('training/setMapDefaultState').then(() => {
this.$store.dispatch('map/clearJlmapTrainView');
this.$store.dispatch('map/resetActiveTrainList', false);
this.$store.dispatch('map/setTrainWindowShow', false);
});
});
}).catch(() => {
this.$messageBox(this.$t('display.demon.endSimulationFail'));
});
}
}
};
</script>