rt-sim-training-client/src/views/designPlatform/userDemonList.vue

254 lines
6.1 KiB
Vue
Raw Normal View History

<template>
2019-10-25 14:41:23 +08:00
<el-card v-loading="loading" class="map-list-main" :header="$t('map.myMapList')">
2019-10-18 17:15:04 +08:00
<el-input v-model="filterText" :placeholder="this.$t('global.filteringKeywords')" clearable />
<el-scrollbar wrap-class="scrollbar-wrapper" :style="{ height: (height-185) +'px' }">
<el-tree
ref="tree"
:data="treeList"
node-key="id"
:props="defaultProps"
highlight-current
:span="22"
:filter-node-method="filterNode"
@node-click="clickEvent"
@node-contextmenu="showContextMenu"
>
<span slot-scope="{ node:tnode, data }">
<span
2019-10-18 17:15:04 +08:00
class="el-icon-tickets"
:style="{color: data.valid ? 'green':''}"
2019-10-28 11:07:33 +08:00
/>
<span>&nbsp;{{ tnode.label }}</span>
</span>
2019-10-18 17:15:04 +08:00
</el-tree>
</el-scrollbar>
<div class="buttonList">
<el-button size="small" type="primary" class="eachButton uploadDemo ">
<input
ref="files"
type="file"
class="file_box"
accept=".json, application/json"
@change="importf"
>
2019-10-21 11:15:15 +08:00
{{ $t('map.importMap') }}
2019-10-18 17:15:04 +08:00
</el-button>
2019-10-21 10:02:49 +08:00
<el-button size="small" type="primary" class="eachButton" @click="createMap">{{ $t('map.newConstruction') }}</el-button>
2019-10-18 17:15:04 +08:00
</div>
<map-operate-menu
ref="menu"
:point="point"
:edit-model="editModel"
:skin-code="skinCode"
2019-10-21 11:15:15 +08:00
@refresh="loadInitData"
2019-10-18 17:15:04 +08:00
@jlmap3d="jlmap3d"
/>
</el-card>
</template>
<script>
2019-10-18 17:15:04 +08:00
import { DeviceMenu } from '@/scripts/ConstDic';
2019-10-21 11:15:15 +08:00
import { postBuildMapImport, listMap } from '@/api/jmap/mapdraft';
2019-10-18 17:15:04 +08:00
import { UrlConfig } from '@/router/index';
import { removeSessionStorage } from '@/utils/auth';
import localStore from 'storejs';
import MapOperateMenu from '@/views/map/mapdraft/mapmanage/operateMenu';
2019-10-18 17:15:04 +08:00
export default {
name: 'UserMapList',
components: {
MapOperateMenu
},
props: {
height: {
type: Number,
required: true
},
width: {
type: Number,
required: true
}
},
data() {
return {
loading: true,
defaultShowKeys: [],
filterText: '',
treeData: [],
treeList: [],
selected: {},
defaultProps: {
children: 'children',
label: 'name'
},
node: {
},
heightUp: 450,
point: {
x: 0,
y: 0
},
editModel: {},
2019-10-21 10:02:49 +08:00
skinCode: ''
2019-10-18 17:15:04 +08:00
};
},
computed: {
role() {
return this.$store.state.user.roles.includes('04') ||
this.$store.state.user.roles.includes('05') ||
this.$store.state.user.roles.includes('01');
2019-10-18 17:15:04 +08:00
}
},
watch: {
filterText(val) {
2019-10-21 10:02:49 +08:00
this.$refs.tree.filter(val);
2019-10-18 17:15:04 +08:00
}
},
beforeDestroy () {
removeSessionStorage('demonList');
},
mounted() {
this.heightUp = Number(localStore.get('upHeight')?localStore.get('upHeight'):(this.height)/2);
2019-10-21 11:15:15 +08:00
this.loadInitData();
2019-10-18 17:15:04 +08:00
},
methods: {
filterNode(value, data) {
if (!value) return true;
return data.name.indexOf(value) !== -1;
},
createMap() {
this.$emit('createMap');
},
2019-10-21 11:15:15 +08:00
async loadInitData() {
2019-10-18 17:15:04 +08:00
this.loading = true;
this.treeData = this.treeList = [];
try {
2019-10-21 11:15:15 +08:00
const res = await listMap();
2019-10-18 17:15:04 +08:00
res.data&&res.data.forEach(elem=>{
// if(elem.children)
// {
elem.type='map';
elem.children=[
{
id: '1',
2019-10-25 14:41:23 +08:00
name: this.$t('designPlatform.mapDesign'),
2019-10-18 17:15:04 +08:00
type: 'mapDesign',
mapId: elem.id,
mapName: elem.name,
skinCode: elem.skinCode
},
{
id: '4',
2019-10-25 14:41:23 +08:00
name: this.$t('designPlatform.runPlanDesign'),
2019-10-18 17:15:04 +08:00
type: 'runPlanDesign',
mapId: elem.id,
mapName: elem.name,
skinCode: elem.skinCode
}
];
// }
});
2019-10-18 17:15:04 +08:00
this.treeData = res.data;
this.treeList = this.filterText
? res.data.filter(elem => { return elem.name.includes(this.filterText); })
: res.data;
2019-10-21 11:15:15 +08:00
this.loading = false;
2019-10-18 17:15:04 +08:00
} catch (error) {
this.loading = false;
this.$messageBox(this.$t('error.refreshFailed'));
}
},
clickEvent(obj, data, ele) {
switch (obj.type) {
case 'mapDesign': {
this.$router.push({ path: `${UrlConfig.designUser.mapDraw}/${obj.mapId}/draft`, query: { name: obj.mapName } });
break;
}
case 'runPlanDesign': {
this.$router.push({ path: `${UrlConfig.designUser.runPlan}/${obj.mapId}?skinCode=${obj.skinCode}` });
break;
}
}
this.$refs.menu.doClose();
},
showContextMenu(e, obj, node, vueElem) {
if (obj && obj.type == 'map') {
e.preventDefault();
const menu = DeviceMenu.Map;
this.point = {
x: e.clientX,
y: e.clientY
};
this.editModel = obj;
this.editModel.skinCode = obj.skinCode;
this.$store.dispatch('menuOperation/setPopMenu', { position: this.point, menu: menu });
} else {
// 关掉右键操作
}
},
jlmap3d() {
2019-10-21 16:12:03 +08:00
this.$router.push({ path: '/design/jlmap3d/edit', query: { mapid: this.editModel.id } });
2019-10-18 17:15:04 +08:00
},
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('导入成功!');
2019-10-21 11:15:15 +08:00
that.loadInitData();
2019-10-18 17:15:04 +08:00
loading.close();
}).catch(error => {
loading.close();
that.$message.error('导入失败' + error.message);
});
obj.value = '';
};
});
}
}
};
</script>
<style lang="scss" scoped>
.buttonList{
padding: 8px 0px 8px 0px;
border-top: 1px #ccc solid;
}
.eachButton{
margin-left:10px;
}
.uploadDemo {
position: relative;
overflow: hidden;
// float: right;
padding: 9px 15px;
margin-right: 3px;
cursor: pointer;
input {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
opacity: 0;
cursor: pointer;
}
}
.map-list-main{
text-align:left;
}
2019-09-29 15:55:01 +08:00
</style>