2020-01-14 09:06:03 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
2020-06-01 18:21:36 +08:00
|
|
|
<div :id="iscsId" v-loading="loading" :style="{ width: canvasWidth +'px', height: canvasHeight +'px',background:'#45607B' }" class="iscs-canvas" />
|
2020-01-14 09:06:03 +08:00
|
|
|
<el-button v-if="showBackButton" class="iscs-button" type="primary" @click="back">{{ $t('global.back') }}</el-button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Vue from 'vue';
|
|
|
|
import Iscs from '@/iscs/iscs';
|
2020-06-01 18:21:36 +08:00
|
|
|
import { parser, deviceFactory } from '@/iscs/utils/parser';
|
2020-09-18 18:30:14 +08:00
|
|
|
import {getIscsData} from '@/api/iscs';
|
|
|
|
// import {getIscsData} from '@/iscs/constant/iscsData';
|
2020-01-14 09:06:03 +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';
|
2020-05-10 21:51:44 +08:00
|
|
|
// import { handlerIscsEvent } from '@/api/simulation';
|
2020-05-10 15:58:08 +08:00
|
|
|
// import { IscsOperation } from '@/scripts/ConstDic';
|
2020-06-01 18:21:36 +08:00
|
|
|
import { deepAssign } from '@/utils/index';
|
|
|
|
import { getUID } from '@/iscs/utils/Uid';
|
2020-01-14 09:06:03 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Iscs',
|
|
|
|
props: {
|
|
|
|
size: {
|
|
|
|
type: Object,
|
|
|
|
default() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dataZoom: {
|
|
|
|
offsetX: '0',
|
|
|
|
offsetY: '0',
|
|
|
|
scaleRate: '1'
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
scaleRate: '1',
|
|
|
|
origin: {
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
}
|
|
|
|
},
|
2020-06-01 18:21:36 +08:00
|
|
|
selected: null, // 选择复制元素
|
|
|
|
copyModel: {}, // 复制元素内容
|
2020-06-09 13:24:18 +08:00
|
|
|
copyList: [],
|
2020-01-14 09:06:03 +08:00
|
|
|
showBackButton: true,
|
|
|
|
initTime: '',
|
|
|
|
started: false,
|
|
|
|
loading: false,
|
|
|
|
stationCode: '',
|
|
|
|
banUpOpenScreenDoor: false,
|
|
|
|
banDownOpenScreenDoor: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters([
|
|
|
|
'canvasWidth',
|
|
|
|
'canvasHeight'
|
|
|
|
]),
|
2020-06-01 18:21:36 +08:00
|
|
|
...mapGetters('iscs', [
|
|
|
|
'iscs'
|
|
|
|
]),
|
2020-01-14 09:06:03 +08:00
|
|
|
iscsId() {
|
|
|
|
return ['iscs', (Math.random().toFixed(5)) * 100000].join('_');
|
2020-01-15 10:11:26 +08:00
|
|
|
},
|
2020-03-16 15:29:26 +08:00
|
|
|
drawWay() {
|
2020-03-27 13:52:14 +08:00
|
|
|
return this.$route.query.drawWay + '';
|
2020-03-16 15:29:26 +08:00
|
|
|
},
|
2020-01-15 10:11:26 +08:00
|
|
|
width() {
|
|
|
|
return this.$store.state.config.width;
|
|
|
|
},
|
|
|
|
height() {
|
|
|
|
return this.$store.state.config.height;
|
2020-01-14 09:06:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$store.state.config.canvasSizeCount': function (val) {
|
|
|
|
this.reSize();
|
|
|
|
},
|
|
|
|
'$store.state.socket.equipmentStatus': function (val) {
|
|
|
|
if (val.length) {
|
|
|
|
this.statusMessage(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.iscsDestroy();
|
|
|
|
},
|
|
|
|
methods: {
|
2020-06-24 15:02:09 +08:00
|
|
|
show (mode, system, part) {
|
|
|
|
if (!mode || !system || !part) {
|
2020-02-05 12:21:56 +08:00
|
|
|
return;
|
|
|
|
}
|
2020-01-14 09:06:03 +08:00
|
|
|
document.getElementById(this.iscsId).oncontextmenu = function (e) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
this.iscsDestroy();
|
|
|
|
this.loading = true;
|
2020-09-18 18:30:14 +08:00
|
|
|
|
|
|
|
// const data = parser(getIscsData(mode, system, part), {width: this.canvasWidth, height: this.canvasHeight});
|
2020-01-14 09:06:03 +08:00
|
|
|
this.$iscs = new Iscs({
|
|
|
|
dom: document.getElementById(this.iscsId),
|
|
|
|
config: {
|
|
|
|
renderer: 'canvas',
|
2020-01-15 13:27:07 +08:00
|
|
|
width: this.width,
|
|
|
|
height: this.height
|
2020-01-14 09:06:03 +08:00
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scaleRate: 1,
|
2020-01-15 13:27:07 +08:00
|
|
|
offsetX: 0,
|
2020-01-14 09:06:03 +08:00
|
|
|
offsetY: 0
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
viewLoaded: this.handleViewLoaded
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Vue.prototype.$iscs = this.$iscs;
|
2020-09-18 18:30:14 +08:00
|
|
|
const params = {
|
|
|
|
lineCode: this.$route.query.lineCode,
|
|
|
|
totalSystem: mode,
|
|
|
|
system: system,
|
|
|
|
userInterface: part
|
|
|
|
};
|
|
|
|
// const data = getIscsData(mode, system, part);
|
|
|
|
// const parserData = parser(data, {width: this.canvasWidth, height: this.canvasHeight});
|
|
|
|
// this.setIscs(parserData, data);
|
|
|
|
// this.$store.dispatch('iscs/setIscsData', data);
|
|
|
|
getIscsData(params).then(resp => {
|
|
|
|
if (resp.data) {
|
|
|
|
const data = JSON.parse(resp.data.graphData);
|
|
|
|
const parserData = parser(data, {width: this.canvasWidth, height: this.canvasHeight});
|
|
|
|
this.setIscs(parserData, data);
|
|
|
|
this.$store.dispatch('iscs/setIscsData', data);
|
2020-09-21 10:26:34 +08:00
|
|
|
} else {
|
2020-09-21 14:29:02 +08:00
|
|
|
const data = {};
|
2020-09-21 10:26:34 +08:00
|
|
|
const parserData = parser(data, {width: this.canvasWidth, height: this.canvasHeight});
|
|
|
|
this.setIscs(parserData, data);
|
|
|
|
this.$store.dispatch('iscs/setIscsData', data);
|
2020-09-18 18:30:14 +08:00
|
|
|
}
|
|
|
|
});
|
2020-01-14 09:06:03 +08:00
|
|
|
this.$iscs.on('contextmenu', this.onContextMenu, this);
|
|
|
|
if (this.$route.query.group) {
|
|
|
|
this.$iscs.on('selected', this.onSelected, this);
|
|
|
|
}
|
2020-09-18 18:30:14 +08:00
|
|
|
|
2020-06-01 18:21:36 +08:00
|
|
|
if (this.$route.path.startsWith('/iscs/design')) {
|
|
|
|
this.$iscs.on('keyboard', this.onKeyboard, this);
|
|
|
|
}
|
2020-01-14 09:06:03 +08:00
|
|
|
window.document.oncontextmenu = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
setIscs(data, oldData) {
|
2020-09-23 10:38:22 +08:00
|
|
|
this.$iscs.setIscs(oldData, data, this.$route.query.lineCode);
|
2020-01-14 09:06:03 +08:00
|
|
|
},
|
2020-06-01 18:21:36 +08:00
|
|
|
// 键盘快捷键事件
|
|
|
|
onKeyboard(hook) {
|
|
|
|
if (this.selected && this.selected.code) {
|
|
|
|
switch (hook) {
|
2020-09-27 14:29:32 +08:00
|
|
|
case 'KeyC': {
|
2020-10-10 15:03:05 +08:00
|
|
|
const list = this.getSelectList();
|
2020-06-09 13:24:18 +08:00
|
|
|
if (list.length) {
|
|
|
|
this.copyList = [];
|
|
|
|
const mapIscs = {};
|
|
|
|
list.forEach(item => {
|
|
|
|
if (item && item.code) {
|
|
|
|
const copyModel = this.copyModelInfo(item, 30);
|
2020-06-11 14:48:40 +08:00
|
|
|
const type1 = item._type.charAt(0).toLowerCase() + item._type.slice(1);
|
2020-06-09 13:24:18 +08:00
|
|
|
if (!mapIscs[type1 + 'List']) {
|
|
|
|
mapIscs[type1 + 'List'] = this.iscs[type1 + 'List'] || [];
|
|
|
|
}
|
|
|
|
const list = mapIscs[type1 + 'List'] || [];
|
|
|
|
copyModel.code = getUID(item._type, list);
|
|
|
|
mapIscs[type1 + 'List'].push(copyModel);
|
|
|
|
this.copyList.push(copyModel);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (this.selected._type != 'CheckBox') {
|
|
|
|
this.copyModel = this.copyModelInfo(this.selected, 10);
|
2020-06-11 14:48:40 +08:00
|
|
|
const type1 = this.selected._type.charAt(0).toLowerCase() + this.selected._type.slice(1);
|
2020-06-05 18:04:27 +08:00
|
|
|
this.copyModel.code = getUID(this.selected._type, this.iscs[type1 + 'List'] || []);
|
|
|
|
} else {
|
2020-06-09 13:24:18 +08:00
|
|
|
this.copyModel = {};
|
|
|
|
}
|
|
|
|
} break;
|
2020-09-27 14:29:32 +08:00
|
|
|
case 'KeyV': {
|
2020-10-10 15:03:05 +08:00
|
|
|
const list = this.getSelectList();
|
2020-06-09 13:24:18 +08:00
|
|
|
if (list.length) {
|
|
|
|
this.copyList.forEach(item => {
|
|
|
|
item.code && this.createDataModel(item);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.copyModel.code && this.createDataModel(this.copyModel);
|
2020-06-05 18:04:27 +08:00
|
|
|
}
|
2020-06-01 18:21:36 +08:00
|
|
|
} break;
|
2020-06-12 17:16:08 +08:00
|
|
|
case 'Delete': {
|
2020-06-11 14:48:40 +08:00
|
|
|
const list = this.getSelectList();
|
|
|
|
if (list.length) {
|
|
|
|
list.forEach(item => {
|
|
|
|
item && item.code && this.$store.dispatch('iscs/deleteIscsDevices', item);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.copyModel.code && this.$store.dispatch('iscs/deleteIscsDevices', this.copyModel);
|
|
|
|
}
|
|
|
|
} break;
|
2020-06-01 18:21:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-06-09 13:24:18 +08:00
|
|
|
copyModelInfo(model, length) { // copy 模块信息
|
|
|
|
const copyModel = deepAssign({}, model);
|
2020-09-23 10:38:22 +08:00
|
|
|
if (copyModel.points && copyModel.points.length) {
|
|
|
|
copyModel.points.forEach(point => {
|
|
|
|
point.x = point.x + length;
|
|
|
|
point.y = point.y + length;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
copyModel.point = {
|
|
|
|
x: model.point.x + length,
|
|
|
|
y: model.point.y + length
|
2020-06-09 13:24:18 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return copyModel;
|
|
|
|
},
|
|
|
|
getSelectList() {
|
|
|
|
return this.$iscs.getCopyList() || [];
|
|
|
|
},
|
2020-06-01 18:21:36 +08:00
|
|
|
createDataModel(model) {
|
2020-09-27 14:44:59 +08:00
|
|
|
const newModel = deviceFactory(model._type, model);
|
2020-06-01 18:21:36 +08:00
|
|
|
this.$store.dispatch('iscs/updateIscsDevices', newModel.model);
|
|
|
|
},
|
2020-01-14 09:06:03 +08:00
|
|
|
// 点击选择事件
|
|
|
|
onSelected(em) {
|
|
|
|
},
|
|
|
|
// 右键点击事件
|
|
|
|
onContextMenu(em) {
|
2020-02-06 10:29:59 +08:00
|
|
|
if (em.eventTarget) {
|
2020-06-01 18:21:36 +08:00
|
|
|
this.selected = em.eventTarget.model;
|
2020-02-06 10:29:59 +08:00
|
|
|
this.$store.dispatch('iscs/setUpdateDeviceData', em.eventTarget.model);
|
|
|
|
}
|
2020-01-14 09:06:03 +08:00
|
|
|
},
|
|
|
|
// 绘图时调用,元素可拖拽
|
|
|
|
drawIscsInit() {
|
|
|
|
this.$iscs && this.$iscs.drawIscsInit();
|
|
|
|
this.showBackButton = false;
|
|
|
|
},
|
|
|
|
reSize() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$iscs && this.$iscs.resize({ width: this.width, height: this.height });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
back() {
|
|
|
|
this.group = this.$route.query.group;
|
|
|
|
this.$store.dispatch('training/over').then(() => {
|
2020-03-27 13:52:14 +08:00
|
|
|
if (this.drawWay === 'true') {
|
2020-03-16 15:29:26 +08:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
2020-01-14 09:06:03 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
iscsDestroy() {
|
|
|
|
if (this.$iscs) {
|
|
|
|
this.$iscs.dispose();
|
|
|
|
this.$iscs = '';
|
|
|
|
Vue.prototype.$iscs = '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleViewLoaded() {
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
statusMessage(val) {
|
|
|
|
this.$iscs && this.$iscs.setDeviceStatus(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
|
|
|
.iscs-button{
|
|
|
|
position: absolute;
|
|
|
|
float: right;
|
|
|
|
right: 20px;
|
|
|
|
bottom: 15px;
|
|
|
|
}
|
|
|
|
.iscs-canvas{
|
|
|
|
}
|
|
|
|
</style>
|