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>
|
2020-09-18 14:42:17 +08:00
|
|
|
|
<audio id="buzzer" controls loop="loop">
|
|
|
|
|
<source :src="buzzerAudio" type="audio/mpeg">
|
|
|
|
|
</audio>
|
2019-10-31 15:34:38 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
import IbpPan from '@/ibp/ibpPan';
|
|
|
|
|
import { parser } from '@/ibp/utils/parser';
|
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
|
import { exitFullscreen } from '@/utils/screen';
|
|
|
|
|
import { handlerIbpEvent } from '@/api/simulation';
|
|
|
|
|
import { IbpOperation } from '@/scripts/ConstDic';
|
2020-09-18 14:42:17 +08:00
|
|
|
|
import { creatSubscribe, clearSubscribe, displayTopic} from '@/utils/stomp';
|
|
|
|
|
import { getToken } from '@/utils/auth';
|
2020-03-16 16:06:50 +08:00
|
|
|
|
import { getIbpInfoByStation } from '@/api/ibp';
|
2020-09-18 14:42:17 +08:00
|
|
|
|
import { getSimulationInfoNew, getIbpInitialState } from '@/api/simulation';
|
|
|
|
|
import BuzzerAudio from '@/assets/buzzer.mp3';
|
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,
|
2020-09-18 14:42:17 +08:00
|
|
|
|
banDownOpenScreenDoor: false,
|
|
|
|
|
buzzerAudio:BuzzerAudio
|
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() {
|
2020-03-27 13:52:14 +08:00
|
|
|
|
return this.$route.query.drawWay + '';
|
2019-10-31 15:34:38 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
'$store.state.config.canvasSizeCount': function (val) {
|
|
|
|
|
this.reSize();
|
|
|
|
|
},
|
2020-09-18 14:42:17 +08:00
|
|
|
|
'$store.state.socket.simulationIbpStatus': function (val) {
|
|
|
|
|
if (val && val[this.stationCode]) {
|
|
|
|
|
this.statusMessage(val[this.stationCode]);
|
|
|
|
|
this.controlAudio(val[this.stationCode].jjtcBuzzer);
|
2019-10-31 15:34:38 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2020-09-18 14:42:17 +08:00
|
|
|
|
'$store.state.socket.simulationTimeSync': function (time) { // 仿真时间更新
|
2019-10-31 15:34:38 +08:00
|
|
|
|
if (this.$ibp) {
|
2020-09-18 14:42:17 +08:00
|
|
|
|
this.initClockTime(time);
|
2019-10-31 15:34:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-09-16 14:26:04 +08:00
|
|
|
|
async mounted() {
|
2019-10-31 15:34:38 +08:00
|
|
|
|
this.setWindowSize();
|
2020-09-18 14:42:17 +08:00
|
|
|
|
if (this.$route.query.noPreLogout) {
|
|
|
|
|
this.subscribe();
|
|
|
|
|
getSimulationInfoNew(this.$route.query.group).then(resp => {
|
|
|
|
|
if (resp.data && resp.data.systemTime) {
|
|
|
|
|
this.initTime = resp.data.systemTime;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-16 14:47:59 +08:00
|
|
|
|
this.initIbp();
|
2020-09-16 14:26:04 +08:00
|
|
|
|
if (this.$route.query.loadAll && this.$route.query.stationCode) {
|
|
|
|
|
await this.show(this.$route.query.stationCode);
|
|
|
|
|
await this.setMoveInit(true);
|
|
|
|
|
this.showBackButton = false;
|
|
|
|
|
}
|
2019-10-31 15:34:38 +08:00
|
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
2020-09-18 14:42:17 +08:00
|
|
|
|
if (this.$route.query.noPreLogout) {
|
|
|
|
|
this.clearSubscribe();
|
|
|
|
|
this.$ibp.setClockStart(false);
|
|
|
|
|
}
|
2019-10-31 15:34:38 +08:00
|
|
|
|
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;
|
2020-09-18 14:42:17 +08:00
|
|
|
|
this.initClockTime(this.initTime || this.$store.state.socket.simulationTimeSync);
|
2019-10-31 15:34:38 +08:00
|
|
|
|
this.$ibp.on('contextmenu', this.onContextMenu, this);
|
|
|
|
|
if (this.$route.query.group) {
|
|
|
|
|
this.$ibp.on('selected', this.onSelected, this);
|
2020-09-16 17:53:33 +08:00
|
|
|
|
this.$ibp.on('mouseDown', this.onMouseDown, this);
|
2019-10-31 15:34:38 +08:00
|
|
|
|
}
|
2020-03-16 14:47:59 +08:00
|
|
|
|
},
|
2020-03-16 16:06:50 +08:00
|
|
|
|
async show (deviceCode, ibpPart) {
|
2020-03-16 14:47:59 +08:00
|
|
|
|
if (!deviceCode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-16 16:06:50 +08:00
|
|
|
|
try {
|
2020-08-26 17:44:01 +08:00
|
|
|
|
// const ibpDatas = ibpData[deviceCode];
|
2020-03-16 16:06:50 +08:00
|
|
|
|
const res = await getIbpInfoByStation(this.$route.query.mapId, deviceCode);
|
|
|
|
|
if (res.data.data) {
|
|
|
|
|
const ibpDatas = JSON.parse(res.data.data).drawData;
|
|
|
|
|
this.stationCode = deviceCode;
|
2020-09-18 14:42:17 +08:00
|
|
|
|
getIbpInitialState(this.$route.query.group, this.stationCode).then(resp => {
|
|
|
|
|
if (resp.data) {
|
|
|
|
|
this.statusMessage(resp.data);
|
|
|
|
|
this.controlAudio(resp.data.jjtcBuzzer);
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.$message.error('获取IBP盘初始状态异常!');
|
|
|
|
|
});
|
2020-03-16 16:06:50 +08:00
|
|
|
|
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 14:47:59 +08:00
|
|
|
|
|
2020-03-16 16:06:50 +08:00
|
|
|
|
this.setIbp(data, ibpDatas);
|
|
|
|
|
this.$store.dispatch('ibp/setIbpData', ibpDatas);
|
|
|
|
|
this.handleBanOpenScreenDoorStatus();
|
|
|
|
|
} 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);
|
2020-09-14 10:59:02 +08:00
|
|
|
|
this.$store.dispatch('ibp/setIbpData', oldData);
|
2019-12-06 17:54:38 +08:00
|
|
|
|
},
|
|
|
|
|
handleBanOpenScreenDoorStatus() {
|
|
|
|
|
this.$store.state.ibp.ibp['keyList'].forEach(item => {
|
2020-09-16 17:53:33 +08:00
|
|
|
|
if (item.mean === 'SXYS') {
|
2019-12-06 17:54:38 +08:00
|
|
|
|
item.status === 'on' ? this.banDownOpenScreenDoor = false : this.banDownOpenScreenDoor = true;
|
2020-09-16 17:53:33 +08:00
|
|
|
|
} else if (item.mean === 'XXYS') {
|
2019-12-06 17:54:38 +08:00
|
|
|
|
item.status === 'on' ? this.banUpOpenScreenDoor = false : this.banUpOpenScreenDoor = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-10-31 15:34:38 +08:00
|
|
|
|
},
|
|
|
|
|
// 点击选择事件
|
|
|
|
|
onSelected(em) {
|
2020-09-16 17:53:33 +08:00
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onMouseDown(em) {
|
2019-10-31 16:52:49 +08:00
|
|
|
|
if (em.deviceModel.mean) {
|
2020-03-16 16:06:50 +08:00
|
|
|
|
if (IbpOperation[em.deviceModel.mean]) {
|
2020-09-18 09:26:25 +08:00
|
|
|
|
handlerIbpEvent(this.$route.query.group, IbpOperation[em.deviceModel.mean].event, this.stationCode);
|
2019-12-06 17:54:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-10-31 15:34:38 +08:00
|
|
|
|
// 右键点击事件
|
|
|
|
|
onContextMenu(em) {
|
2019-10-31 16:52:49 +08:00
|
|
|
|
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;
|
|
|
|
|
},
|
2020-09-16 14:26:04 +08:00
|
|
|
|
// 地图可拖拽
|
|
|
|
|
setMoveInit(data) {
|
|
|
|
|
this.$ibp && this.$ibp.setMoveOnMouseMove(data);
|
|
|
|
|
},
|
2019-10-31 15:34:38 +08:00
|
|
|
|
// 初始化电子表时间
|
|
|
|
|
initClockTime(initTime) {
|
|
|
|
|
this.$ibp.initClockTime(initTime);
|
|
|
|
|
},
|
|
|
|
|
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-07-01 18:52:29 +08:00
|
|
|
|
if (this.$route.query.projectDevice) {
|
|
|
|
|
this.$store.dispatch('LogOut').then(() => {
|
|
|
|
|
location.reload();
|
2020-03-16 15:29:26 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2020-07-01 18:52:29 +08:00
|
|
|
|
history.go(-1);
|
|
|
|
|
exitFullscreen();
|
2020-03-16 15:29:26 +08:00
|
|
|
|
}
|
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);
|
2020-09-18 14:42:17 +08:00
|
|
|
|
},
|
|
|
|
|
async subscribe() {
|
|
|
|
|
this.clearSubscribe();
|
|
|
|
|
const header = { group: this.$route.query.group || '', 'X-Token': getToken() };
|
|
|
|
|
creatSubscribe(`${displayTopic}\/${this.$route.query.group}`, header);
|
|
|
|
|
|
|
|
|
|
await this.$store.dispatch('training/setHasSubscribed');
|
|
|
|
|
},
|
|
|
|
|
clearSubscribe() {
|
|
|
|
|
clearSubscribe(`${displayTopic}\/${this.$route.query.group}`);
|
|
|
|
|
},
|
|
|
|
|
controlAudio(val) {
|
|
|
|
|
const audio = document.getElementById('buzzer');
|
2020-09-27 13:41:25 +08:00
|
|
|
|
// console.log(val, audio);
|
2020-09-18 14:42:17 +08:00
|
|
|
|
if (audio !== null) {
|
|
|
|
|
if (val) {
|
|
|
|
|
audio.play();
|
|
|
|
|
} else if (val === false) {
|
|
|
|
|
audio.pause();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-31 15:34:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
|
|
|
|
.ibp-button{
|
|
|
|
|
position: absolute;
|
|
|
|
|
float: right;
|
|
|
|
|
right: 20px;
|
|
|
|
|
bottom: 15px;
|
2020-08-26 17:27:02 +08:00
|
|
|
|
z-index: 38;
|
2019-10-31 15:34:38 +08:00
|
|
|
|
}
|
|
|
|
|
.ibp-canvas{
|
2020-08-26 17:27:02 +08:00
|
|
|
|
position: absolute;
|
|
|
|
|
z-index: 37;
|
2019-10-31 15:34:38 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|