wvp-GB28181-pro/web_src/src/components/common/DeviceTree.vue

190 lines
7.8 KiB
Vue
Raw Normal View History

2022-04-20 18:21:18 +08:00
<template>
<div id="DeviceTree" style="width: 100%;height: 100%; background-color: #FFFFFF; overflow: auto">
2022-04-20 18:21:18 +08:00
<el-container>
<el-header>设备列表</el-header>
<el-main style="background-color: #ffffff;">
<div class="device-tree-main-box">
2022-07-03 07:40:54 +08:00
<el-tree ref="gdTree" :props="defaultProps" :load="loadNode" lazy @node-click="handleNodeClick"@node-contextmenu="handleContextMenu" node-key="id" style="min-width: 100%; display:inline-block !important;">
2022-04-20 18:21:18 +08:00
<span class="custom-tree-node" slot-scope="{ node, data }" style="width: 100%">
<span v-if="node.data.type === 0 && node.data.online" title="在线设备" class="device-online iconfont icon-jiedianleizhukongzhongxin2"></span>
<span v-if="node.data.type === 0 && !node.data.online " title="离线设备" class="device-offline iconfont icon-jiedianleizhukongzhongxin2"></span>
<span v-if="node.data.type === 2 && node.data.online" title="目录" class="device-online iconfont icon-jiedianleilianjipingtai"></span>
<span v-if="node.data.type === 2 && !node.data.online" title="目录" class="device-offline iconfont icon-jiedianleilianjipingtai"></span>
<span v-if="node.data.type === 3 && node.data.online " title="在线通道" class="device-online iconfont icon-shebeileijiankongdian"></span>
<span v-if="node.data.type === 3 && !node.data.online" title="在线通道" class="device-offline iconfont icon-shebeileijiankongdian"></span>
<span v-if="node.data.type === 4 && node.data.online " title="在线通道-球机" class="device-online iconfont icon-shebeileiqiuji"></span>
<span v-if="node.data.type === 4 && !node.data.online" title="在线通道-球机" class="device-offline iconfont icon-shebeileiqiuji"></span>
<span v-if="node.data.type === 5 && node.data.online " title="在线通道-半球" class="device-online iconfont icon-shebeileibanqiu"></span>
<span v-if="node.data.type === 5 && !node.data.online" title="在线通道-半球" class="device-offline iconfont icon-shebeileibanqiu"></span>
<span v-if="node.data.type === 6 && node.data.online " title="在线通道-枪机" class="device-online iconfont icon-shebeileiqiangjitongdao"></span>
<span v-if="node.data.type === 6 && !node.data.online" title="在线通道-枪机" class="device-offline iconfont icon-shebeileiqiangjitongdao"></span>
<span v-if="node.data.online" style="padding-left: 1px" class="device-online">{{ node.label }}</span>
<span v-if="!node.data.online" style="padding-left: 1px" class="device-offline">{{ node.label }}</span>
<span>
<i v-if="node.data.hasGPS && node.data.online" style="color: #9d9d9d" class="device-online iconfont icon-dizhi"></i>
<i v-if="node.data.hasGPS && !node.data.online" style="color: #9d9d9d" class="device-offline iconfont icon-dizhi"></i>
</span>
</span>
</el-tree>
</div>
</el-main>
</el-container>
</div>
</template>
<script>
import DeviceService from "../service/DeviceService.js";
export default {
name: 'DeviceTree',
data() {
return {
deviceService: new DeviceService(),
defaultProps: {
children: 'children',
label: 'name',
isLeaf: 'isLeaf'
}
};
},
2022-07-03 07:40:54 +08:00
props: ['device', 'onlyCatalog', 'clickEvent', 'contextMenuEvent'],
2022-04-20 18:21:18 +08:00
methods: {
handleNodeClick(data,node,element) {
2022-07-03 07:40:54 +08:00
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
2022-04-20 18:21:18 +08:00
if(typeof (this.clickEvent) == "function") {
2022-07-03 07:40:54 +08:00
this.clickEvent(deviceNode.data.userData, data.userData, data.type === 2)
2022-04-20 18:21:18 +08:00
}
},
handleContextMenu(event,data,node,element) {
2022-04-20 18:21:18 +08:00
console.log("右键点击事件")
2022-07-03 07:40:54 +08:00
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
2022-04-20 18:21:18 +08:00
if(typeof (this.contextMenuEvent) == "function") {
2022-07-03 07:40:54 +08:00
this.contextMenuEvent(deviceNode.data.userData, event, data.userData, data.type === 2)
2022-04-20 18:21:18 +08:00
}
},
loadNode: function(node, resolve){
2022-07-03 07:40:54 +08:00
console.log(this.device)
2022-04-20 18:21:18 +08:00
if (node.level === 0) {
2022-07-03 07:40:54 +08:00
if (this.device) {
let node = {
name: this.device.name || this.device.deviceId,
isLeaf: false,
id: this.device.deviceId,
type: this.device.online,
online: this.device.online === 1,
userData: this.device
}
resolve([node])
}else {
this.deviceService.getAllDeviceList((data)=>{
console.log(data)
if (data.length > 0) {
let nodeList = []
for (let i = 0; i < data.length; i++) {
console.log(data[i].name)
let node = {
name: data[i].name || data[i].deviceId,
isLeaf: false,
id: data[i].deviceId,
type: data[i].online,
online: data[i].online === 1,
userData: data[i]
}
nodeList.push(node);
2022-04-20 18:21:18 +08:00
}
2022-07-03 07:40:54 +08:00
resolve(nodeList)
}else {
resolve([])
2022-04-20 18:21:18 +08:00
}
2022-07-03 07:40:54 +08:00
}, (list)=>{
2022-05-31 15:54:39 +08:00
console.log("设备加载完成")
2022-07-03 07:40:54 +08:00
}, (error)=>{
2022-04-20 18:21:18 +08:00
2022-07-03 07:40:54 +08:00
})
}
}else {
2022-05-31 15:54:39 +08:00
let channelArray = []
2022-07-03 07:40:54 +08:00
this.deviceService.getTree(node.data.userData.deviceId, node.data.id, this.onlyCatalog, catalogData =>{
console.log(catalogData)
2022-05-31 15:54:39 +08:00
channelArray = channelArray.concat(catalogData)
this.channelDataHandler(channelArray, resolve)
},(endCatalogData) => {
2022-04-20 18:21:18 +08:00
})
}
2022-07-03 07:40:54 +08:00
2022-04-20 18:21:18 +08:00
},
channelDataHandler: function (data, resolve) {
if (data.length > 0) {
let nodeList = []
2022-07-03 07:40:54 +08:00
for (let i = 0; i <data.length; i++) {
let item = data[i];
2022-04-20 18:21:18 +08:00
let type = 3;
2022-07-03 07:40:54 +08:00
if (item.id.length <= 10) {
2022-04-20 18:21:18 +08:00
type = 2;
2022-07-03 07:40:54 +08:00
}else {
if (item.id.length > 14) {
let channelType = item.id.substring(10, 13)
console.log("channelType: " + channelType)
if (channelType === '215' || channelType === '216') {
type = 2;
}
console.log(type)
if (item.basicData.ptzType === 1 ) { // 1-球机;2-半球;3-固定枪机;4-遥控枪机
2022-07-03 07:40:54 +08:00
type = 4;
}else if (item.basicData.ptzType === 2) {
2022-07-03 07:40:54 +08:00
type = 5;
}else if (item.basicData.ptzType === 3 || item.basicData.ptzType === 4) {
2022-07-03 07:40:54 +08:00
type = 6;
}
}else {
if (item.basicData.subCount > 0 || item.basicData.parental === 1) {
type = 2;
}
}
2022-04-20 18:21:18 +08:00
}
let node = {
2022-07-03 07:40:54 +08:00
name: item.name || item.basicData.channelId,
isLeaf: type !== 2,
id: item.id,
deviceId: item.deviceId,
2022-04-20 18:21:18 +08:00
type: type,
2022-07-03 07:40:54 +08:00
online: item.basicData.status === 1,
hasGPS: item.basicData.longitude*item.basicData.latitude !== 0,
userData: item.basicData
2022-04-20 18:21:18 +08:00
}
nodeList.push(node);
}
resolve(nodeList)
}else {
resolve([])
}
2022-07-03 07:40:54 +08:00
},
reset: function (){
this.$forceUpdate();
2022-04-20 18:21:18 +08:00
}
},
destroyed() {
// if (this.jessibuca) {
// this.jessibuca.destroy();
// }
// this.playing = false;
// this.loaded = false;
// this.performance = "";
},
}
</script>
<style>
.device-tree-main-box{
text-align: left;
}
.device-online{
color: #252525;
}
.device-offline{
color: #727272;
}
</style>