rt-sim-training-client/src/views/newMap/displayNew/demon/equipment.vue

199 lines
7.1 KiB
Vue
Raw Normal View History

2020-07-14 13:27:00 +08:00
<template>
<div>
2020-08-03 17:30:01 +08:00
<el-drawer
title="设备管理"
:visible.sync="show"
direction="ltr"
:before-close="doClose"
custom-class="dialog_box"
size="43%"
>
2020-07-29 10:27:02 +08:00
<div style="margin-bottom: 3px; overflow: hidden; padding: 0 10px;">
2020-07-14 13:27:00 +08:00
<div class="plc_box">名称: {{ plcInfo.name }}</div>
<div class="plc_box">状态: <span :style="{'color': plcInfo.status ? 'green' : 'red'}">{{ plcInfo.status ? '在线' : '不在线' }}</span></div>
2020-07-14 16:07:43 +08:00
<el-button type="text" size="small" class="freshen_box" @click="getList">刷新</el-button>
2020-07-14 13:27:00 +08:00
</div>
<el-table :data="tableData" border style="width: 100%; max-height: calc(100% - 24px); overflow: auto;">
<el-table-column prop="code" label="设备编号" width="180" />
<el-table-column prop="typeName" label="设备类型" width="180" />
<el-table-column prop="vrDeviceCode" label="连接设备编码">
<template slot-scope="scope">
2020-07-16 09:38:20 +08:00
<div v-if="scope.row.vrDeviceCode" class="flex_box">{{ scope.row.vrDeviceName }}</div>
2020-07-14 13:27:00 +08:00
<div v-if="!scope.row.vrDeviceCode" class="flex_box">()</div>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
2020-07-14 16:07:43 +08:00
<el-button :type="scope.row.buttonShowType ? 'danger' : 'primary'" size="small" @click="handleClick(scope.row, scope.$index)">连接</el-button>
<el-button size="small" @click="cancel(scope.row, scope.$index)">断开</el-button>
2020-07-14 13:27:00 +08:00
</template>
</el-table-column>
</el-table>
2020-08-03 17:30:01 +08:00
</el-drawer>
2020-07-14 13:27:00 +08:00
</div>
</template>
<script>
import { getAllSimulationList, postSimulationConnectById, putSimulationDisconnectById } from '@/api/simulation.js';
import ConstConfig from '@/scripts/ConstConfig';
import { EventBus } from '@/scripts/event-bus';
import { getSessionStorage } from '@/utils/auth';
2020-07-14 13:27:00 +08:00
export default {
name: 'Equipment',
data() {
return {
show: false,
group: '',
tableData: [],
typeList: ConstConfig.ConstSelect.projectDeviceTypeList,
plcInfo: {
name: '',
status: ''
},
2020-07-14 16:07:43 +08:00
index: 0,
selected: {},
typeObj: {
Section: '区段',
Signal: '信号机',
Switch: '道岔',
Psd: '屏蔽门',
StationStand: '站台'
}
2020-07-14 13:27:00 +08:00
};
2020-08-03 17:30:01 +08:00
},
computed: {
project() {
return getSessionStorage('project');
2020-08-03 17:30:01 +08:00
}
},
2020-07-14 13:27:00 +08:00
mounted() {
EventBus.$on('selectDevice', (data) => {
2020-07-14 16:07:43 +08:00
this.selected = data;
2020-07-14 13:27:00 +08:00
this.tableData[this.index]['buttonShowType'] = false;
this.tableData.splice(this.index, 1, this.tableData[this.index]);
this.$store.dispatch('map/selectDeviceCode', {flag: false, type: ''});
2020-07-14 16:07:43 +08:00
this.connect(this.tableData[this.index]);
2020-07-14 13:27:00 +08:00
});
},
async beforeDestroy() {
EventBus.$off('selectDevice');
},
methods: {
async doShow() {
this.show = true;
this.group = this.$route.query.group;
this.getList();
},
async getList() {
try {
const res = await getAllSimulationList(this.group);
this.tableData = [];
res.data.forEach((item, index) => {
2020-07-14 13:27:00 +08:00
if (item.type == 'PLC_GATEWAY') {
this.plcInfo = {
name: 'PLC网关',
status: item.online
};
} else {
item.buttonShowType = false;
item.typeName = this.typeList.find(el => el.value == item.type).label;
if (item.vrDeviceCode && this.$store.getters['map/getDeviceByCode'](item.vrDeviceCode)) {
2020-07-16 09:38:20 +08:00
item.vrDeviceName = this.$store.getters['map/getDeviceByCode'](item.vrDeviceCode).name;
} else {
item.vrDeviceName = item.vrDeviceCode;
2020-08-03 17:30:01 +08:00
}
if (this.project == 'heb' || this.project == 'designheb') {
if (item.type == 'SWITCH') {
this.tableData.push(item);
}
} else {
this.tableData.push(item);
}
2020-07-14 13:27:00 +08:00
}
});
} catch (error) {
console.error(error);
}
},
2020-07-14 16:07:43 +08:00
doClose() {
this.show = false;
},
handleClick(row, index) {
2020-07-14 13:27:00 +08:00
row.buttonShowType = !row.buttonShowType;
this.index = index;
this.tableData.splice(index, 1, row);
this.$store.dispatch('map/selectDeviceCode', {flag: row.buttonShowType, type: row.type});
},
2020-07-14 16:07:43 +08:00
async connect(row) {
this.$confirm(`您确定连接${this.typeObj[this.selected._type] || '设备'}: ${this.selected.name}, 是否继续?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
try {
const res = await postSimulationConnectById(this.group, row.id, this.selected.code);
if (res && res.code == 200) {
this.$message.success('连接成功!');
this.tableData[this.index]['vrDeviceCode'] = this.selected.code;
2020-07-16 09:38:20 +08:00
this.tableData[this.index]['vrDeviceName'] = this.selected.name;
2020-07-14 16:07:43 +08:00
this.tableData.splice(this.index, 1, this.tableData[this.index]);
2020-07-14 13:27:00 +08:00
}
2020-07-14 16:07:43 +08:00
} catch (error) {
console.error(error);
}
});
2020-07-14 13:27:00 +08:00
},
async cancel(row, index) {
this.$confirm('您确定将次设备断开, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
if (row.vrDeviceCode) {
row.vrDeviceCode = '';
2020-07-16 09:38:20 +08:00
row.vrDeviceName = '';
2020-07-14 13:27:00 +08:00
this.tableData.splice(index, 1, row);
try {
const res = await putSimulationDisconnectById(this.group, row.id);
if (res && res.code == 200) {
this.$message.success('断开成功!');
}
} catch (error) {
console.error(error);
}
}
});
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.plc_box{
float: left;
margin-right: 40px;
padding: 9px;
}
.freshen_box{
float: right;
}
.flex_box{
float: left;
margin-right: 5px;
line-height: 30px;
}
/deep/ {
.el-dialog__wrapper{
width: 800px;
}
.dialog_box{
height: 100%;
}
.el-dialog__body{
padding-top: 6px;
height: calc(100% - 54px);
}
}
</style>