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

386 lines
11 KiB
Vue
Raw Normal View History

2024-07-23 18:00:47 +08:00
<template>
2024-07-24 17:54:19 +08:00
<div id="DeviceTree">
2024-07-28 07:36:20 +08:00
<div class="page-header" style="margin-bottom: 1rem;">
2024-07-24 17:54:19 +08:00
<div class="page-title">行政区划</div>
<div class="page-header-btn">
<div style="display: inline;">
2024-07-30 17:58:18 +08:00
<el-input @input="search" style="margin-right: 1rem; width: 12rem;" size="mini" placeholder="关键字"
2024-07-24 17:54:19 +08:00
prefix-icon="el-icon-search" v-model="searchSrt" clearable></el-input>
2024-07-30 17:58:18 +08:00
<el-checkbox v-model="showCode"></el-checkbox>
2024-07-23 18:00:47 +08:00
</div>
2024-07-24 17:54:19 +08:00
</div>
</div>
2024-07-26 17:53:10 +08:00
<div>
2024-07-25 18:02:22 +08:00
<vue-easy-tree
ref="veTree"
node-key="id"
height="72vh"
lazy
style="height: 78vh; padding: 2rem"
:load="loadNode"
:data="treeData"
2024-07-26 17:53:10 +08:00
:default-expanded-keys="['']"
2024-07-25 18:02:22 +08:00
@node-contextmenu="contextmenuEventHandler"
@node-click="nodeClickHandler"
>
<span class="custom-tree-node" slot-scope="{ node, data }">
2024-07-26 17:53:10 +08:00
<span @click.stop >
<el-radio v-if="node.data.type === 0 && node.level !== 1 " style="margin-right: 0" v-model="chooseId" @input="chooseIdChange" :label="node.data.id">{{''}}</el-radio>
</span>
<span v-if="node.data.type === 0" style="color: #409EFF" class="iconfont icon-bianzubeifen3"></span>
2024-07-30 17:58:18 +08:00
<span v-if="node.data.type === 1" style="color: #409EFF" class="iconfont icon-shexiangtou2"></span>
<span style=" padding-left: 1px" v-if="node.data.id !=='' && showCode">{{ node.label }}-{{ node.data.id }}</span>
<span style=" padding-left: 1px" v-if="node.data.id ==='' || !showCode">{{ node.label }}</span>
2024-07-26 17:53:10 +08:00
</span>
2024-07-25 18:02:22 +08:00
</vue-easy-tree>
</div>
<regionCode ref="regionCode"></regionCode>
2024-07-23 18:00:47 +08:00
</div>
</template>
<script>
2024-07-24 17:54:19 +08:00
import VueEasyTree from "@wchbrad/vue-easy-tree";
2024-07-25 18:02:22 +08:00
import regionCode from './../dialog/regionCode'
2024-07-24 17:54:19 +08:00
let treeData = []
2024-07-23 18:00:47 +08:00
export default {
2024-07-24 17:54:19 +08:00
name: 'DeviceTree',
components: {
2024-07-25 18:02:22 +08:00
VueEasyTree, regionCode
2024-07-24 17:54:19 +08:00
},
data() {
return {
2024-07-30 17:58:18 +08:00
showCode: false,
2024-07-25 18:02:22 +08:00
searchSrt: "",
2024-07-26 17:53:10 +08:00
chooseId: "",
2024-07-25 18:02:22 +08:00
// props: {
// label: "name",
// },
2024-07-24 17:54:19 +08:00
treeData: [],
}
},
2024-07-26 17:53:10 +08:00
props: ['edit', 'clickEvent', 'chooseIdChange'],
2024-07-24 17:54:19 +08:00
created() {
2024-07-25 18:02:22 +08:00
// this.$axios({
// method: 'get',
// url: `/api/region/tree/list`,
// }).then((res)=> {
// if (res.data.code === 0) {
//
// for (let i = 0; i < res.data.data.length; i++) {
// let item = res.data.data[i]
// console.log(item)
// this.treeData.push({
// id: item.deviceId,
// label: item.name,
// children: [],
// isLeaf: false,
// })
// }
//
// }
//
// }).catch(function (error) {
// console.log(error);
// });
2024-07-24 17:54:19 +08:00
},
methods: {
onClick(evt, treeId, treeNode) {
2024-07-23 18:00:47 +08:00
2024-07-24 17:54:19 +08:00
},
onCheck(evt, treeId, treeNode) {
2024-07-23 18:00:47 +08:00
2024-07-24 17:54:19 +08:00
},
handleCreated(ztreeObj) {
2024-07-23 18:00:47 +08:00
2024-07-25 18:02:22 +08:00
},
search() {
2024-07-24 17:54:19 +08:00
},
handleNodeClick(data, node, element) {
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
if (typeof (this.clickEvent) == "function") {
this.clickEvent(deviceNode.data.userData, data.userData, data.type === 2)
}
},
handleContextMenu(event, data, node, element) {
console.log("右键点击事件")
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
if (typeof (this.contextMenuEvent) == "function") {
this.contextMenuEvent(deviceNode.data.userData, event, data.userData, data.type === 2)
}
},
loadNode: function (node, resolve) {
2024-07-25 18:02:22 +08:00
console.log(22222)
2024-07-24 17:54:19 +08:00
console.log(node)
2024-07-26 17:53:10 +08:00
if (node.level === 0) {
resolve([{
id: "",
label: "根资源组",
isLeaf: false,
type: 0
}]);
} else if (node.data.id.length < 8) {
2024-07-25 18:02:22 +08:00
this.$axios({
method: 'get',
url: `/api/region/tree/list`,
params: {
query: this.searchSrt,
parent: node.data.id
}
2024-07-26 17:53:10 +08:00
}).then((res) => {
2024-07-25 18:02:22 +08:00
if (res.data.code === 0) {
resolve(res.data.data);
}
2024-07-23 18:00:47 +08:00
2024-07-25 18:02:22 +08:00
}).catch(function (error) {
console.log(error);
});
2024-07-26 17:53:10 +08:00
} else {
2024-07-25 18:02:22 +08:00
resolve([]);
2024-07-24 17:54:19 +08:00
}
},
channelDataHandler: function (data, resolve) {
if (data.length > 0) {
let nodeList = []
for (let i = 0; i < data.length; i++) {
let item = data[i];
let type = 3;
if (item.id.length <= 10) {
type = 2;
} 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-遥控枪机
type = 4;
} else if (item.basicData.ptzType === 2) {
type = 5;
} else if (item.basicData.ptzType === 3 || item.basicData.ptzType === 4) {
type = 6;
}
} else {
if (item.basicData.subCount > 0 || item.basicData.parental === 1) {
type = 2;
2024-07-23 18:00:47 +08:00
}
}
}
2024-07-24 17:54:19 +08:00
let node = {
name: item.name || item.basicData.channelId,
isLeaf: type !== 2,
id: item.id,
deviceId: item.deviceId,
type: type,
online: item.basicData.status === 1,
hasGPS: item.basicData.longitude * item.basicData.latitude !== 0,
userData: item.basicData
}
nodeList.push(node);
2024-07-23 18:00:47 +08:00
}
2024-07-24 17:54:19 +08:00
resolve(nodeList)
} else {
resolve([])
2024-07-23 18:00:47 +08:00
}
},
2024-07-24 17:54:19 +08:00
reset: function () {
this.$forceUpdate();
2024-07-25 18:02:22 +08:00
},
2024-07-26 17:53:10 +08:00
contextmenuEventHandler: function (event, data, node, element) {
console.log(node.level)
2024-07-25 18:02:22 +08:00
if (node.data.type === 1) {
data.parentId = node.parent.data.id;
this.$contextmenu({
items: [
{
label: "移除通道",
icon: "el-icon-delete",
disabled: false,
onClick: () => {
this.$axios({
2024-07-30 17:58:18 +08:00
method: "post",
url: `/api/common/channel/region/delete`,
data: {
channelIds: [data.id]
}
2024-07-26 17:53:10 +08:00
}).then((res) => {
2024-07-25 18:02:22 +08:00
console.log("移除成功")
node.parent.loaded = false
node.parent.expand();
}).catch(function (error) {
console.log(error);
});
}
}
],
event, // 鼠标事件信息
customClass: "custom-class", // 自定义菜单 class
zIndex: 3000, // 菜单样式 z-index
});
2024-07-26 17:53:10 +08:00
} else if (node.data.type === 0) {
2024-07-25 18:02:22 +08:00
this.$contextmenu({
items: [
{
label: "刷新节点",
icon: "el-icon-refresh",
disabled: false,
onClick: () => {
this.refreshNode(node);
}
},
{
label: "新建节点",
icon: "el-icon-plus",
disabled: false,
onClick: () => {
this.addRegion(data.id, node);
}
},
{
2024-07-26 17:53:10 +08:00
label: "重命名",
2024-07-25 18:02:22 +08:00
icon: "el-icon-edit",
2024-07-26 17:53:10 +08:00
disabled: node.level === 1,
2024-07-25 18:02:22 +08:00
onClick: () => {
this.editCatalog(data, node);
}
},
{
label: "删除节点",
icon: "el-icon-delete",
2024-07-26 17:53:10 +08:00
disabled: node.level === 1,
2024-07-29 17:44:34 +08:00
divided: true,
2024-07-25 18:02:22 +08:00
onClick: () => {
this.$confirm('确定删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
2024-07-26 17:53:10 +08:00
this.removeRegion(data.id, node)
2024-07-25 18:02:22 +08:00
}).catch(() => {
});
}
},
2024-07-29 17:44:34 +08:00
{
label: "添加设备",
icon: "el-icon-plus",
disabled: node.level === 1,
onClick: () => {
this.addChannelFormDevice(data.id, node)
}
},
{
label: "移除设备",
icon: "el-icon-delete",
disabled: node.level === 1,
onClick: () => {
this.removeChannelFormDevice(data.id, node)
}
},
2024-07-25 18:02:22 +08:00
// {
// label: "导出",
// icon: "el-icon-download",
// disabled: false,
// children: [
// {
// label: "导出到文件",
// onClick: () => {
//
// },
// },
// {
// label: "导出到其他平台",
// onClick: () => {
//
// },
// }
// ]
// },
],
event, // 鼠标事件信息
customClass: "custom-class", // 自定义菜单 class
zIndex: 3000, // 菜单样式 z-index
});
}
return false;
},
2024-07-26 17:53:10 +08:00
removeRegion: function (id, node) {
this.$axios({
method: "delete",
url: `/api/region/delete`,
params: {
deviceId: id,
}
}).then((res) => {
if (res.data.code === 0) {
console.log("移除成功")
node.parent.loaded = false
node.parent.expand();
}
})
.catch(function (error) {
console.log(error);
});
2024-07-29 17:44:34 +08:00
},
addChannelFormDevice: function (id, node) {
},
removeChannelFormDevice: function (id, node) {
2024-07-26 17:53:10 +08:00
},
refreshNode: function (node) {
2024-07-25 18:02:22 +08:00
node.loaded = false
node.expand();
},
2024-07-26 17:53:10 +08:00
addRegion: function (id, node) {
2024-07-25 18:02:22 +08:00
console.log(node)
2024-07-26 17:53:10 +08:00
this.$refs.regionCode.openDialog(form => {
2024-07-25 18:02:22 +08:00
node.loaded = false
node.expand();
}, id);
},
2024-07-26 17:53:10 +08:00
nodeClickHandler: function (data, node, tree) {
2024-07-25 18:02:22 +08:00
console.log(data)
console.log(node)
2024-07-26 17:53:10 +08:00
// this.chooseId = data.id;
// this.chooseName = data.name;
// if (this.catalogIdChange)this.catalogIdChange(this.chooseId, this.chooseName);
2024-07-24 17:54:19 +08:00
}
},
destroyed() {
// if (this.jessibuca) {
// this.jessibuca.destroy();
// }
// this.playing = false;
// this.loaded = false;
// this.performance = "";
},
2024-07-23 18:00:47 +08:00
}
</script>
<style>
2024-07-24 17:54:19 +08:00
.device-tree-main-box {
2024-07-23 18:00:47 +08:00
text-align: left;
}
2024-07-24 17:54:19 +08:00
.device-online {
2024-07-23 18:00:47 +08:00
color: #252525;
}
2024-07-24 17:54:19 +08:00
.device-offline {
2024-07-23 18:00:47 +08:00
color: #727272;
}
2024-07-26 17:53:10 +08:00
.custom-tree-node .el-radio__label {
padding-left: 4px !important;
}
2024-07-23 18:00:47 +08:00
</style>