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

349 lines
9.1 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">
<jlmap-visual ref="jlmapVisual" @onSelect="clickEvent" @onMenu="onContextmenu" />
</div>
2019-08-20 11:17:08 +08:00
<div class="map-draft">
<div v-show="viewDraft==='draft'">
2019-07-25 10:30:30 +08:00
<map-operate
ref="mapOperate"
:card-height="cardHeight"
:map-info="mapInfo"
:selected="selected"
:map-saveing="mapSaveing"
@handleSelectLogicalView="handleSelectLogicalView"
@handleSelectPhysicalView="handleSelectPhysicalView"
@saveMapEvent="saveMapEvent"
@verifyMapEvent="verifyMapEvent"
@addOrUpdateMapModel="addOrUpdateMapModel"
@delMapModel="delMapModel"
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-08-20 11:17:08 +08:00
<div v-show="viewDraft != 'draft'">
2019-08-16 15:12:03 +08:00
<data-relation
ref="dataRelation"
:card-height="cardHeight"
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>
import { saveMap, getMapDetail, verifyMap } from '@/api/jmap/mapdraft';
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-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-07-25 10:30:30 +08:00
export default {
name: 'MapView',
components: {
JlmapVisual,
MapOperate,
2019-08-16 15:12:03 +08:00
DataRelation,
ConfigMap
2019-07-25 10:30:30 +08:00
},
data() {
return {
2019-08-16 16:19:08 +08:00
viewSelect: ViewMode.MIX,
2019-07-25 10:30:30 +08:00
mapSaveing: false,
ViewMode: ViewMode,
viewDraft: 'draft',
autoSaveTask: null,
selected: null,
2019-08-15 10:26:29 +08:00
mapInfo: { name: this.$t('map.pleaseSelectMap') },
2019-08-20 11:17:08 +08:00
timeDemon: null
2019-07-25 10:30:30 +08:00
};
},
computed: {
cardHeight() {
return this.$store.state.app.height - 195;
}
},
2019-07-25 10:30:30 +08:00
watch: {
'$store.state.map.mapDataLoadedCount': function (val) {
this.initAutoSaveTask();
2019-08-16 16:33:59 +08:00
},
$route() {
2019-08-20 12:47:39 +08:00
this.$nextTick(() => {
this.loadInitPage();
});
2019-07-25 10:30:30 +08:00
}
},
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-07-31 09:13:37 +08:00
this.$nextTick(() => {
2019-08-02 10:36:17 +08:00
EventBus.$emit('viewLoading', false);
});
2019-07-25 10:30:30 +08:00
},
2019-08-16 15:12:03 +08:00
showMap() {
this.$refs.configMap.doShow();
},
selectViewDraft(data) {
2019-08-20 11:17:08 +08:00
this.viewDraft = data;
2019-08-16 15:12:03 +08:00
},
2019-07-25 10:30:30 +08:00
loadInitPage() {
this.$store.dispatch('training/changeMode', { mode: TrainingMode.MAP_EDIT });
2019-08-15 10:26:29 +08:00
this.mapInfo = { name: this.$t('map.pleaseSelectMap'), id: this.$route.params.mapId };
2019-07-25 10:30:30 +08:00
if (parseInt(this.mapInfo.id)) {
this.mapInfo.name = this.$route.query.name;
getMapDetail(this.$route.params.mapId).then(response => {
2019-08-26 14:30:01 +08:00
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-08-15 10:26:29 +08:00
this.$messageBox(this.$t('tip.failedLoadMap'));
2019-07-25 10:30:30 +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;
}
},
2019-07-26 10:38:57 +08:00
handleSelectControlPage (model) {
2019-07-25 10:30:30 +08:00
if (this.$refs && this.$refs.mapOperate) {
this.$refs.mapOperate.handleSelectControlPage(model);
}
},
handleSelectView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
2019-07-25 15:44:23 +08:00
this.$refs.jlmapVisual.setLayerVisible(handle);
2019-07-25 10:30:30 +08:00
}
},
handleSelectLogicalView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
2019-07-25 15:44:23 +08:00
this.$refs.jlmapVisual.setLevelVisible(handle);
2019-07-25 10:30:30 +08:00
}
},
handleSelectPhysicalView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
2019-07-25 15:44:23 +08:00
this.$refs.jlmapVisual.setLevelVisible(handle);
2019-07-25 10:30:30 +08:00
}
},
2019-08-20 11:17:08 +08:00
handleSelectHybridView(handle) {
if (this.$refs && this.$refs.jlmapVisual) {
this.$refs.jlmapVisual.setLevelVisible(handle);
}
},
2019-07-25 10:30:30 +08:00
clickEvent(em) {
2019-07-26 10:38:57 +08:00
var device = this.getDeviceByEm(em);
this.onSelect(device);
2019-08-16 15:24:41 +08:00
if (this.$refs.dataRelation) {
this.$refs.dataRelation.setSelected(device);
}
2019-07-25 10:30:30 +08:00
},
// 获取设备数据
getDeviceByEm(em) {
2019-07-26 10:38:57 +08:00
var device = this.$store.getters['map/getDeviceByCode'](em.deviceCode) || null;
if (device) {
device._viewVal = em.val;
2019-07-25 10:30:30 +08:00
}
2019-07-26 10:38:57 +08:00
return device;
2019-07-25 10:30:30 +08:00
},
2019-07-26 10:38:57 +08:00
onSelect(device) {
this.selected = device || null;
this.selected && this.handleSelectControlPage(device);
2019-07-25 10:30:30 +08:00
},
onContextmenu(em) {
this.point = {
x: em.clientX,
y: em.clientY
};
2019-08-12 14:08:16 +08:00
if (!em.deviceType) {
2019-08-13 13:34:39 +08:00
var menu = getDeviceMenuByDeviceType('Cancel');
this.$store.dispatch('menuOperation/setPopMenu', { position: this.point, menu: menu });
}
2019-07-25 10:30:30 +08:00
},
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') {
2019-08-15 10:26:29 +08:00
this.$messageBox(this.$t('tip.sectionPointsDeficiency'));
2019-07-25 10:30:30 +08:00
return;
}
}
} else {
2019-08-15 10:26:29 +08:00
this.$messageBox(this.$t('tip.sectionPointsDeficiency'));
2019-07-25 10:30:30 +08:00
return;
}
}
this.mapSaveing = true;
2019-08-06 17:00:24 +08:00
this.$store.dispatch('map/saveMapDeviceDefaultRelations').then(() => {
// map.switchList = [];
2019-07-25 10:30:30 +08:00
saveMap(Object.assign(map, { mapId: this.$route.params.mapId })).then(response => {
2019-08-15 10:26:29 +08:00
this.$message.success(this.$t('tip.saveSuccessfully'));
2019-07-25 10:30:30 +08:00
this.mapSaveing = false;
this.initAutoSaveTask();
}).catch(error => {
2019-07-30 13:29:54 +08:00
console.log(error);
2019-08-15 10:26:29 +08:00
this.$messageBox(this.$t('tip.saveFailed'));
2019-07-25 10:30:30 +08:00
this.mapSaveing = false;
if (error.code === 40004 || error.code === 40005 || error.code === 40003) {
this.clearAutoSave();
} else {
this.initAutoSaveTask();
}
});
});
}
}
},
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);
2019-08-15 10:26:29 +08:00
this.$messageBox(this.$t('tip.dataValidationFailed'));
2019-07-25 10:30:30 +08:00
} else {
2019-08-15 10:26:29 +08:00
this.$message.success(this.$t('tip.dataValidationSuccess'));
2019-07-25 10:30:30 +08:00
}
}).catch(() => {
2019-08-15 10:26:29 +08:00
this.$messageBox(this.$t('tip.requestFailed'));
2019-07-25 10:30:30 +08:00
});
}
}
},
tableToExcel(data) {
const filterVal = ['index'];
const arr = [];
data.forEach(item => {
arr.push({ index: item });
});
const dataList = this.formatJson(filterVal, arr);
2019-07-25 15:48:51 +08:00
import('@/utils/Export2Excel').then(excel => {
2019-08-15 10:26:29 +08:00
excel.export_json_to_excel([this.$t('tip.dataQuestion')], dataList, this.$t('tip.dataList'));
2019-07-25 15:48:51 +08:00
});
2019-07-25 10:30:30 +08:00
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]));
},
setDelayUnlockStatus(data, status) {
if (data && data.delayShowList) {
data.delayShowList.forEach(elem => {
elem.status = status;
});
}
},
// 增加数据数据 给vuex map对象中
addOrUpdateMapModel(obj) {
this.$store.dispatch('map/updateMapDevices', obj);
2019-07-25 10:30:30 +08:00
},
// 删除数据 同时del map
delMapModel(obj) {
this.$store.dispatch('map/deleteMapDevices', obj).then(() => {
2019-07-25 10:30:30 +08:00
this.selected = null;
});
},
// 设置显示中心
2019-07-25 15:44:23 +08:00
setCenter(code) {
this.$refs.jlmapVisual.setCenter(code);
2019-07-25 10:30:30 +08:00
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.map-draft{
/deep/{
.v-modal{
opacity: 0;
}
}
}
.mapPaint{
height: 100%;
overflow: hidden;
}
2019-07-25 10:30:30 +08:00
.map-view {
float: left;
width: auto;
}
.map-draft {
float: right;
width: 520px;
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;
}
}
</style>