rt-sim-training-client/src/views/ibp/ibpsystem/index.vue

283 lines
10 KiB
Vue
Raw Normal View History

2019-10-31 15:34:38 +08:00
<template>
<div>
2020-03-13 21:17:20 +08:00
<div :id="ibpId" v-loading="loading" :style="{ width: canvasWidth+'px', height: canvasHeight +'px',background:'#000' }" class="ibp-canvas" />
2019-10-31 15:34:38 +08:00
<el-button v-if="showBackButton" class="ibp-button" type="primary" @click="back">{{ $t('global.back') }}</el-button>
</div>
</template>
<script>
import Vue from 'vue';
import IbpPan from '@/ibp/ibpPan';
import { parser } from '@/ibp/utils/parser';
2020-03-16 16:06:50 +08:00
// import ibpData from '@/ibp/constant/ibpData';
2019-10-31 15:34:38 +08:00
import { mapGetters } from 'vuex';
import { exitFullscreen } from '@/utils/screen';
import { putJointTrainingSimulationUser } from '@/api/chat';
2020-03-16 15:29:26 +08:00
import { putJointTrainingSimulationUserNew} from '@/api/jointTraining';
2019-10-31 15:34:38 +08:00
import { handlerIbpEvent } from '@/api/simulation';
import { IbpOperation } from '@/scripts/ConstDic';
2020-03-16 16:06:50 +08:00
import { getIbpInfoByStation } from '@/api/ibp';
2019-10-31 15:34:38 +08:00
export default {
name: 'Ibp',
props: {
size: {
type: Object,
default() {
return null;
}
}
},
data() {
return {
width: this.$store.state.config.width,
height: this.$store.state.config.height,
dataZoom: {
offsetX: '0',
offsetY: '0',
scaleRate: '1'
},
config: {
scaleRate: '1',
origin: {
x: 0,
y: 0
}
},
showBackButton: true,
initTime: '',
started: false,
loading: false,
2019-12-06 17:54:38 +08:00
stationCode: '',
banUpOpenScreenDoor: false,
banDownOpenScreenDoor: false
2019-10-31 15:34:38 +08:00
};
},
computed: {
...mapGetters([
'canvasWidth',
'canvasHeight'
]),
ibpId() {
return ['ibp', (Math.random().toFixed(5)) * 100000].join('_');
2020-03-13 21:17:20 +08:00
},
2020-03-16 15:29:26 +08:00
drawWay() {
return this.$route.query.drawWay;
2019-10-31 15:34:38 +08:00
}
},
watch: {
'$store.state.config.canvasSizeCount': function (val) {
this.reSize();
},
'$store.state.training.initTime': function (initTime) {
this.initTime = initTime;
if (this.$ibp) {
this.initClockTime(initTime);
}
},
'$store.state.training.started': function (started) {
this.started = started;
if (this.$ibp) {
this.setClockStart(started);
}
},
'$store.state.socket.equipmentStatus': function (val) {
if (val.length) {
this.statusMessage(val);
}
}
},
mounted() {
this.setWindowSize();
this.initIbp();
2019-10-31 15:34:38 +08:00
},
beforeDestroy() {
this.ibpDestroy();
},
methods: {
2020-03-16 16:06:50 +08:00
initIbp(offsetX = 0) {
2019-10-31 15:34:38 +08:00
this.ibpDestroy();
this.loading = true;
this.$ibp = new IbpPan({
dom: document.getElementById(this.ibpId),
config: {
renderer: 'canvas',
width: this.canvasWidth,
height: this.canvasHeight
},
options: {
scaleRate: 1,
2020-03-16 16:06:50 +08:00
offsetX: offsetX,
2019-10-31 15:34:38 +08:00
offsetY: 0
},
methods: {
viewLoaded: this.handleViewLoaded
}
});
Vue.prototype.$ibp = this.$ibp;
this.$ibp.on('contextmenu', this.onContextMenu, this);
if (this.$route.query.group) {
this.$ibp.on('selected', this.onSelected, this);
}
},
2020-03-16 16:06:50 +08:00
async show (deviceCode, ibpPart) {
if (!deviceCode) {
return;
}
2020-03-16 16:06:50 +08:00
// console.log(deviceCode);
// const ibpDatas = ibpData[deviceCode];
try {
const res = await getIbpInfoByStation(this.$route.query.mapId, deviceCode);
if (res.data.data) {
const ibpDatas = JSON.parse(res.data.data).drawData;
this.stationCode = deviceCode;
document.getElementById(this.ibpId).oncontextmenu = function (e) {
return false;
};
let offsetX = 0;
if (ibpPart === 'left') {
offsetX = 0;
} else if (ibpPart === 'right') {
offsetX = 1920;
}
const data = parser(ibpDatas, {width: this.canvasWidth, height: this.canvasHeight}); // ibp 绘图编译数据
this.initIbp(offsetX);
2020-03-16 16:06:50 +08:00
this.setIbp(data, ibpDatas);
this.$store.dispatch('ibp/setIbpData', ibpDatas);
this.handleBanOpenScreenDoorStatus();
this.initClockTime(this.initTime);
} else {
// 无数据
this.loading = false;
this.$alert('当前ibp盘数据不存在', '信息', {
confirmButtonText: '确定',
callback: action => {}
});
}
} catch (error) {
this.loading = false;
this.$alert('当前ibp盘数据不存在', '信息', {
confirmButtonText: '确定',
callback: action => {}
});
}
2019-10-31 15:34:38 +08:00
window.document.oncontextmenu = function () {
return false;
};
2020-03-16 16:06:50 +08:00
2019-10-31 15:34:38 +08:00
},
2019-12-06 17:54:38 +08:00
setIbp(data, oldData) {
this.$ibp.setIbp(oldData, data);
},
handleBanOpenScreenDoorStatus() {
this.$store.state.ibp.ibp['keyList'].forEach(item => {
if (item.mean === 'Ban_Down_Open_Screen_Door') {
item.status === 'on' ? this.banDownOpenScreenDoor = false : this.banDownOpenScreenDoor = true;
} else if (item.mean === 'Ban_Up_Open_Screen_Door') {
item.status === 'on' ? this.banUpOpenScreenDoor = false : this.banUpOpenScreenDoor = true;
}
});
2019-10-31 15:34:38 +08:00
},
// 点击选择事件
onSelected(em) {
if (em.deviceModel.mean) {
2020-03-16 16:06:50 +08:00
if (IbpOperation[em.deviceModel.mean]) {
switch (IbpOperation[em.deviceModel.mean].event) {
case 'UpHoldTrain':
case 'UpCancelHoldTrain':
case 'DownHoldTrain':
case 'DownCancelHoldTrain':
handlerIbpEvent(this.$route.query.group, {operate: IbpOperation[em.deviceModel.mean].operate, stationCode: this.stationCode});
break;
case 'BanUpOpenScreenDoor':
this.banUpOpenScreenDoor = !this.banUpOpenScreenDoor;
break;
case 'BanDownOpenScreenDoor':
this.banDownOpenScreenDoor = !this.banDownOpenScreenDoor;
break;
case 'UpOpenScreenDoor':
this.openScreenDoor(this.banUpOpenScreenDoor, IbpOperation[em.deviceModel.mean].operate);
break;
case 'DownOpenScreenDoor':
this.openScreenDoor(this.banDownOpenScreenDoor, IbpOperation[em.deviceModel.mean].operate);
break;
}
2019-12-06 17:54:38 +08:00
}
}
},
openScreenDoor(flag, operate) {
if (flag) {
2020-03-16 16:06:50 +08:00
handlerIbpEvent(this.$route.query.group, {operate: operate, stationCode: this.stationCode});
2019-10-31 15:34:38 +08:00
}
},
// 右键点击事件
onContextMenu(em) {
this.$store.dispatch('ibp/setUpdateDeviceData', em.eventTarget.model);
2019-10-31 15:34:38 +08:00
},
// 绘图时调用,元素可拖拽
drawIbpInit() {
this.$ibp && this.$ibp.drawIbpInit();
this.showBackButton = false;
},
// 初始化电子表时间
initClockTime(initTime) {
this.$ibp.initClockTime(initTime);
},
// 设置电子时钟开始或停止
setClockStart(started) {
this.$ibp.setClockStart(started);
},
reSize() {
2020-03-13 21:17:20 +08:00
this.width = this.$store.state.config.width;
this.height = this.$store.state.config.height;
this.$ibp && this.$ibp.resize({ width: this.width, height: this.height });
2019-10-31 15:34:38 +08:00
},
setWindowSize() {
2020-03-13 21:17:20 +08:00
const width = this.size ? this.size.width : this.$store.state.app.width;
const height = this.size ? this.size.height : this.$store.state.app.height;
this.$store.dispatch('config/resize', { width: width, height: height });
2019-10-31 15:34:38 +08:00
},
back() {
this.group = this.$route.query.group;
this.$store.dispatch('training/over').then(() => {
2020-03-16 15:29:26 +08:00
if (this.drawWay) {
putJointTrainingSimulationUserNew(this.group).then(() => {
this.$router.replace({ path: `/trainroom`, query: { group: this.group, lineCode:this.$route.query.lineCode, drawWay: this.drawWay } });
exitFullscreen();
});
} else {
putJointTrainingSimulationUser(this.group).then(() => {
this.$router.replace({ path: `/trainroom`, query: { group: this.group, lineCode:this.$route.query.lineCode } });
exitFullscreen();
});
}
2019-10-31 15:34:38 +08:00
});
},
ibpDestroy() {
if (this.$ibp) {
this.$ibp.dispose();
this.$ibp = '';
Vue.prototype.$ibp = '';
}
},
handleViewLoaded() {
this.loading = false;
},
statusMessage(val) {
this.$ibp && this.$ibp.setDeviceStatus(val);
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.ibp-button{
position: absolute;
float: right;
right: 20px;
bottom: 15px;
}
.ibp-canvas{
}
</style>