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

271 lines
10 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>
<!-- v-show="panelShow" :panelShow="panelShow" -->
<transition name="el-zoom-in-bottom">
<map-system-draft ref="mapCanvas" @back="back" />
</transition>
2020-05-22 18:41:23 +08:00
<status-icon v-if="$route.query.lineCode == '11' || $route.query.lineCode == '10'" 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" />
<!-- ok -->
<menu-lesson v-if="isLesson" ref="lessonMenu" :offset="offset" :data-error="dataError" :offset-bottom="offsetBottom" :tip-bottom="tipBottom" />
<!-- ok -->
<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-20 20:27:19 +08:00
<!-- @showScheduling="showScheduling"
@schedulingView="schedulingView"
@hideScheduling="hideScheduling" -->
<!-- @devicemodel="devicemodel" -->
<!-- @jl3dstation="jl3dstation" -->
<!-- @quitQuest="quitQuest" -->
<!-- @passflow="passflow" -->
<!-- @hidepanel="hidepanel" -->
<!-- :is-script-run="isScriptRun" -->
2020-07-14 18:14:39 +08:00
</template>
2020-08-20 20:27:19 +08:00
<menu-train-list v-if="isDemon" @setCenter="setCenter" />
<menu-system-time ref="menuSystemTime" :offset="offset" :group="group" />
</div>
</template>
<script>
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';
2019-12-30 09:00:16 +08:00
import MenuExam from '@/views/newMap/displayNew/menuExam';
import MenuLesson from '@/views/newMap/displayNew/menuLesson';
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';
// import MenuScript from '@/views/newMap/displayNew/menuScript';
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,
MenuTrainList
// 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;
},
isDemon() {
return this.mode === 'demon';
},
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();
this.setPosition();
},
'$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.group = this.$route.query.group;
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-20 20:27:19 +08:00
setCenter(code) {
this.$jlmap.setCenter(code);
},
// 设置 各个按钮的定位
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() {
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-07-31 15:24:44 +08:00
if (!this.planRunning) {
2020-06-29 15:55:31 +08:00
this.$store.dispatch('training/over');
}
if (this.isDemon) {
2020-07-31 15:24:44 +08:00
this.$refs.menuDemon.initPlannedDriving(this.planRunning); // 是否正在按计划行车
2020-06-29 15:55:31 +08:00
} else if (this.isScript) {
// this.$refs.menuScript.initPlannedDriving(resp.data.planRunning);
}
} 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>