rt-sim-training-client/src/views/mapdraft/index.vue

426 lines
14 KiB
Vue
Raw Normal View History

2019-07-25 10:30:30 +08:00
<template>
<transition name="el-zoom-in-center">
<div class="mapPaint">
<div class="map-view">
2019-11-06 18:37:32 +08:00
<div class="operation_box">
<el-button-group>
2019-11-06 18:49:55 +08:00
<el-button size="small" :disabled="!stepData.length" @click="revocation">撤销</el-button>
<el-button size="small" :disabled="!recoverStepData.length" @click="recover">恢复</el-button>
2019-11-06 18:37:32 +08:00
</el-button-group>
</div>
2019-07-25 10:30:30 +08:00
<jlmap-visual ref="jlmapVisual" @onSelect="clickEvent" @onMenu="onContextmenu" />
</div>
2019-08-20 11:17:08 +08:00
<div class="map-draft">
2019-10-30 18:25:13 +08:00
<div v-show="viewDraft === 'draft'" class="box">
2019-07-25 10:30:30 +08:00
<map-operate
ref="mapOperate"
:map-info="mapInfo"
:selected="selected"
:map-saveing="mapSaveing"
@handleSelectLogicalView="handleSelectLogicalView"
@handleSelectPhysicalView="handleSelectPhysicalView"
@saveMapEvent="saveMapEvent"
@verifyMapEvent="verifyMapEvent"
2019-11-06 18:37:32 +08:00
@updateMapModel="updateMapModel"
2019-07-25 15:44:23 +08:00
@setCenter="setCenter"
2019-08-16 15:12:03 +08:00
@selectView="selectViewDraft"
@showMap="showMap"
2019-07-25 10:30:30 +08:00
/>
</div>
2019-10-30 18:25:13 +08:00
<div v-show="viewDraft != 'draft'" class="box">
2019-08-16 15:12:03 +08:00
<data-relation
ref="dataRelation"
2019-07-25 10:30:30 +08:00
:map-info="mapInfo"
:selected="selected"
2019-08-16 15:12:03 +08:00
@selectView="selectViewDraft"
@showMap="showMap"
2019-07-25 10:30:30 +08:00
/>
</div>
2019-08-16 15:12:03 +08:00
<config-map
ref="configMap"
@handleSelectView="handleSelectView"
@handleSelectLogicalView="handleSelectLogicalView"
@handleSelectPhysicalView="handleSelectPhysicalView"
2019-08-20 11:17:08 +08:00
@handleSelectHybridView="handleSelectHybridView"
2019-08-16 15:12:03 +08:00
/>
2019-07-25 10:30:30 +08:00
</div>
</div>
</transition>
</template>
<script>
2019-10-23 14:43:25 +08:00
import { saveMap, getMapDetail, verifyMap, postBuildMapImport } from '@/api/jmap/mapdraft';
2019-07-25 10:30:30 +08:00
import { ViewMode, TrainingMode, getDeviceMenuByDeviceType } from '@/scripts/ConstDic';
import { checkLoginLine } from '@/api/login';
import JlmapVisual from '@/views/jlmap/index';
import MapOperate from './mapoperate/index';
import { EventBus } from '@/scripts/event-bus';
2019-11-06 18:49:55 +08:00
import { mapGetters } from 'vuex';
2019-07-25 10:30:30 +08:00
2019-08-16 15:12:03 +08:00
import ConfigMap from './configMap';
import DataRelation from './dataRelation/index';
2019-11-06 18:37:32 +08:00
// import { deepAssign } from '@/utils/index';
2019-08-16 15:12:03 +08:00
2019-07-25 10:30:30 +08:00
export default {
2019-10-30 13:58:34 +08:00
name: 'MapView',
components: {
JlmapVisual,
MapOperate,
DataRelation,
ConfigMap
},
data() {
return {
viewSelect: ViewMode.MIX,
mapSaveing: false,
ViewMode: ViewMode,
viewDraft: 'draft',
autoSaveTask: null,
selected: null,
mapInfo: { name: this.$t('map.pleaseSelectMap') },
timeDemon: null
};
},
2019-11-06 18:49:55 +08:00
computed: {
...mapGetters('map', [
'stepData',
'recoverStepData'
])
},
2019-10-30 13:58:34 +08:00
watch: {
'$store.state.map.mapDataLoadedCount': function (val) {
this.initAutoSaveTask();
},
$route() {
this.$nextTick(() => {
this.loadInitPage();
});
}
},
mounted() {
this.loadInitPage();
this.timeDemon = setInterval(() => {
checkLoginLine();
}, 5000 * 60);
},
beforeDestroy() {
this.clearAutoSave();
this.$store.dispatch('map/mapClear');
if (this.timeDemon) {
clearTimeout(this.timeDemon);
}
},
methods: {
endViewLoading(isSuccess) {
if (!isSuccess) {
this.$store.dispatch('map/mapClear');
}
2019-08-02 10:36:17 +08:00
2019-10-30 13:58:34 +08:00
this.$nextTick(() => {
EventBus.$emit('viewLoading', false);
});
},
showMap() {
this.$refs.configMap.doShow();
},
selectViewDraft(data) {
this.viewDraft = data;
},
loadInitPage() {
this.$store.dispatch('training/changeMode', { mode: TrainingMode.MAP_EDIT });
this.mapInfo = { name: this.$t('map.pleaseSelectMap'), id: this.$route.params.mapId };
if (parseInt(this.mapInfo.id)) {
this.mapInfo.name = this.$route.query.name;
getMapDetail(this.$route.params.mapId).then(response => {
this.$store.dispatch('map/setMapData', response.data).then(resp => {
this.$store.dispatch('training/setMapDefaultState');
});
this.setDelayUnlockStatus(response.data, '00');
this.initAutoSaveTask();
}).catch((error) => {
console.log(error);
2019-11-06 18:37:32 +08:00
this.$message.error(this.$t('tip.failedLoadMap'));
2019-10-30 13:58:34 +08:00
this.endViewLoading();
});
} else {
this.endViewLoading();
}
},
initAutoSaveTask() {
const timeout = 1000 * 60 * 3;
this.clearAutoSave(this.autoSaveTask);
if (this.viewDraft == 'draft') {
this.autoSaveTask = setInterval(this.saveMapEvent, timeout);
}
},
clearAutoSave() {
if (this.autoSaveTask) {
clearInterval(this.autoSaveTask);
this.autoSaveTask = null;
}
},
handleSelectControlPage (model) {
if (this.$refs && this.$refs.mapOperate) {
this.$refs.mapOperate.handleSelectControlPage(model);
this.$store.dispatch('menuOperation/setMapDrawSelectCount');
}
},
handleSelectView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
this.$refs.jlmapVisual.setLayerVisible(handle);
}
},
handleSelectLogicalView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
this.$refs.jlmapVisual.setLevelVisible(handle);
}
},
handleSelectPhysicalView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
this.$refs.jlmapVisual.setLevelVisible(handle);
}
},
handleSelectHybridView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
this.$refs.jlmapVisual.setLevelVisible(handle);
}
},
clickEvent(em) {
var device = this.getDeviceByEm(em);
this.onSelect(device);
if (this.$refs.dataRelation) {
this.$refs.dataRelation.setSelected(device);
}
},
// 获取设备数据
getDeviceByEm(em) {
var device = this.$store.getters['map/getDeviceByCode'](em.deviceCode) || null;
if (device) {
device._viewVal = em.val;
}
return device;
},
onSelect(device) {
this.selected = device || null;
this.selected && this.handleSelectControlPage(device);
},
onContextmenu(em) {
this.point = {
x: em.clientX,
y: em.clientY
};
if (!em.deviceType) {
var menu = getDeviceMenuByDeviceType('Cancel');
this.$store.dispatch('menuOperation/setPopMenu', { position: this.point, menu: menu });
}
},
saveMapEvent() {
if (this.$refs.jlmapVisual) {
const map = this.$store.state.map.map;
if (map && parseInt(this.$route.params.mapId)) {
for (const i in map.sectionList) {
if (map.sectionList[i].points.length > 0) {
for (let index = 0; index < map.sectionList[i].points.length; index++) {
if (String(map.sectionList[i].points[index].x) == 'undefined' || String(map.sectionList[i].points[index].y) == 'undefined') {
this.$messageBox(this.$t('tip.sectionPointsDeficiency'));
return;
}
}
} else {
this.$messageBox(this.$t('tip.sectionPointsDeficiency'));
return;
}
}
2019-07-25 10:30:30 +08:00
2019-10-30 13:58:34 +08:00
this.mapSaveing = true;
this.$store.dispatch('map/saveMapDeviceDefaultRelations').then(() => {
saveMap(Object.assign(map, { mapId: this.$route.params.mapId })).then(response => {
this.$message.success(this.$t('tip.saveSuccessfully'));
this.mapSaveing = false;
this.initAutoSaveTask();
}).catch(error => {
console.log(error);
this.$messageBox(this.$t('tip.saveFailed'));
this.mapSaveing = false;
if (error.code === 40004 || error.code === 40005 || error.code === 40003) {
this.clearAutoSave();
} else {
this.initAutoSaveTask();
}
});
}).catch(error => {
console.log(error, '错误提示');
this.mapSaveing = false;
2019-11-06 18:37:32 +08:00
this.$message(this.$t('tip.saveFailed'));
2019-10-30 13:58:34 +08:00
});
}
}
},
verifyMapEvent() {
if (this.$refs.jlmapVisual) {
const map = this.$store.state.map.map;
if (map && this.$route.params.mapId) {
verifyMap(this.$route.params.mapId).then(res => {
if (res.data.length) {
this.tableToExcel(res.data);
this.$messageBox(this.$t('tip.dataValidationFailed'));
} else {
this.$message.success(this.$t('tip.dataValidationSuccess'));
}
}).catch(() => {
2019-11-06 18:37:32 +08:00
this.$message.error(this.$t('tip.requestFailed'));
2019-10-30 13:58:34 +08:00
});
}
}
},
2019-07-25 10:30:30 +08:00
2019-10-30 13:58:34 +08:00
tableToExcel(data) {
const filterVal = ['index'];
const arr = [];
data.forEach(item => {
arr.push({ index: item });
});
const dataList = this.formatJson(filterVal, arr);
2019-11-06 18:37:32 +08:00
import('@/utils/Export2Excel').then(excel => {
excel.export_json_to_excel([this.$t('tip.dataQuestion')], dataList, this.$t('tip.dataList'));
});
2019-10-30 13:58:34 +08:00
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]));
},
2019-07-25 10:30:30 +08:00
2019-10-30 13:58:34 +08:00
setDelayUnlockStatus(data, status) {
if (data && data.delayShowList) {
data.delayShowList.forEach(elem => {
elem.status = status;
});
}
},
2019-11-06 18:37:32 +08:00
// // 增加数据数据 给vuex map对象中
2019-10-30 13:58:34 +08:00
addOrUpdateMapModel(obj) {
this.$store.dispatch('map/updateMapDevices', obj);
},
2019-11-06 18:37:32 +08:00
updateMapModel(models) {
this.$store.dispatch('map/updateMapDevices', models);
},
// 撤销
revocation() {
this.$store.dispatch('map/setRevocation');
},
// 恢复
recover() {
this.$store.dispatch('map/setRecover');
2019-10-30 13:58:34 +08:00
},
// 设置显示中心
setCenter(code) {
this.$refs.jlmapVisual.setCenter(code);
},
createMap() {
this.$refs.mapCreate.show();
},
importf() {
const loading = this.$loading({
lock: true,
text: '正在导入中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
setTimeout(() => {
const obj = this.$refs.files;
if (!obj.files) return;
const f = obj.files[0];
const reader = new FileReader();
const that = this;
reader.readAsText(f, 'utf-8');
reader.onload = function(e) {
const data = e.target.result;
postBuildMapImport(JSON.parse(data)).then(res => {
loading.close();
that.$message.success('导入成功!');
that.refresh();
loading.close();
}).catch(error => {
loading.close();
that.$message.error('导入失败' + error.message);
});
obj.value = '';
};
});
}
}
2019-07-25 10:30:30 +08:00
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
2019-11-06 18:37:32 +08:00
.operation_box{
position: absolute;
right: 20px;
top: 20px;
z-index: 9;
}
2019-07-25 10:30:30 +08:00
.map-draft{
/deep/{
.v-modal{
opacity: 0;
}
}
}
2019-10-30 18:25:13 +08:00
.box{
height: 100%;
overflow: hidden;
}
.mapPaint{
height: 100%;
overflow: hidden;
}
2019-07-25 10:30:30 +08:00
.map-view {
float: left;
width: auto;
2019-11-06 18:37:32 +08:00
position: relative;
2019-07-25 10:30:30 +08:00
}
.map-draft {
float: right;
width: 520px;
2019-10-30 18:25:13 +08:00
height: 100%;
2019-08-21 17:34:08 +08:00
// /deep/ .el-scrollbar__view {
// width: 510px !important;
// height: calc(100% - 40px);
// }
2019-07-25 10:30:30 +08:00
}
.physical-view {
line-height: 25px;
height: 60px;
padding-left: 12px;
.el-checkbox {
width: 70px;
margin: 0;
margin-right: 12px;
}
}
2019-09-25 18:56:30 +08:00
.uploadDemo {
position: relative;
overflow: hidden;
float: right;
padding: 3px 0;
margin-right: 3px;
cursor: pointer;
2019-10-30 18:25:13 +08:00
input {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
opacity: 0;
cursor: pointer;
}
2019-09-25 18:56:30 +08:00
}
2019-07-25 10:30:30 +08:00
</style>