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

370 lines
10 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-31 15:07:54 +08:00
<el-input @input="search" style="visibility:hidden; 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
2024-07-31 15:07:54 +08:00
class="flow-tree"
2024-07-25 18:02:22 +08:00
ref="veTree"
2024-08-23 17:50:29 +08:00
node-key="deviceId"
2024-07-31 15:07:54 +08:00
height="78vh"
2024-07-25 18:02:22 +08:00
lazy
2024-07-31 15:07:54 +08:00
style="padding: 2rem 0 2rem 0.5rem"
2024-07-25 18:02:22 +08:00
:load="loadNode"
:data="treeData"
2024-08-23 17:50:29 +08:00
:props="props"
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 >
2024-08-23 17:50:29 +08:00
<el-radio v-if="node.data.type === 0 && node.level !== 1 " style="margin-right: 0" v-model="chooseId" @input="chooseIdChange" :label="node.data.deviceId">{{''}}</el-radio>
2024-07-26 17:53:10 +08:00
</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>
2024-08-23 17:50:29 +08:00
<span style=" padding-left: 1px" v-if="node.data.deviceId !=='' && showCode" :title="node.data.deviceId">{{ node.label }}{{ node.data.deviceId }}</span>
<span style=" padding-left: 1px" v-if="node.data.deviceId ==='' || !showCode" :title="node.data.deviceId">{{ 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-31 15:07:54 +08:00
<gbDeviceSelect ref="gbDeviceSelect"></gbDeviceSelect>
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-31 15:07:54 +08:00
import gbDeviceSelect from './../dialog/GbDeviceSelect'
2024-07-23 18:00:47 +08:00
export default {
2024-07-24 17:54:19 +08:00
name: 'DeviceTree',
components: {
2024-07-31 15:07:54 +08:00
VueEasyTree, regionCode, gbDeviceSelect
2024-07-24 17:54:19 +08:00
},
data() {
return {
2024-08-23 17:50:29 +08:00
props: {
label: "name",
},
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-24 17:54:19 +08:00
treeData: [],
}
},
2024-07-31 15:07:54 +08:00
props: ['edit', 'clickEvent', 'chooseIdChange', 'onChannelChange'],
2024-07-24 17:54:19 +08:00
created() {
},
methods: {
2024-07-25 18:02:22 +08:00
search() {
2024-07-24 17:54:19 +08:00
},
loadNode: function (node, resolve) {
2024-07-26 17:53:10 +08:00
if (node.level === 0) {
resolve([{
2024-08-23 17:50:29 +08:00
deviceId: "",
name: "根资源组",
2024-07-26 17:53:10 +08:00
isLeaf: false,
type: 0
}]);
2024-08-23 17:50:29 +08:00
} else if (node.data.deviceId.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
}
},
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) {
2024-07-31 15:07:54 +08:00
2024-07-26 17:53:10 +08:00
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: () => {
2024-07-31 15:07:54 +08:00
console.log(data)
2024-07-25 18:02:22 +08:00
this.$axios({
2024-07-30 17:58:18 +08:00
method: "post",
url: `/api/common/channel/region/delete`,
data: {
2024-08-23 17:50:29 +08:00
channelIds: [data.id]
2024-07-30 17:58:18 +08:00
}
2024-07-26 17:53:10 +08:00
}).then((res) => {
2024-07-25 18:02:22 +08:00
console.log("移除成功")
2024-07-31 15:07:54 +08:00
if (this.onChannelChange) {
this.onChannelChange()
}
2024-07-25 18:02:22 +08:00
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: {
2024-08-23 17:50:29 +08:00
id: node.data.id,
2024-07-26 17:53:10 +08:00
}
}).then((res) => {
if (res.data.code === 0) {
console.log("移除成功")
node.parent.loaded = false
node.parent.expand();
}
2024-07-31 15:07:54 +08:00
}).catch(function (error) {
2024-07-26 17:53:10 +08:00
console.log(error);
2024-07-31 15:07:54 +08:00
});
2024-07-29 17:44:34 +08:00
},
addChannelFormDevice: function (id, node) {
2024-07-31 15:07:54 +08:00
this.$refs.gbDeviceSelect.openDialog((rows)=>{
let deviceIds = []
for (let i = 0; i < rows.length; i++) {
deviceIds.push(rows[i].id)
}
this.$axios({
method: 'post',
url: `/api/common/channel/region/device/add`,
data: {
2024-08-23 17:50:29 +08:00
civilCode: node.data.deviceId,
2024-07-31 15:07:54 +08:00
deviceIds: deviceIds,
}
}).then((res)=> {
if (res.data.code === 0) {
this.$message.success("保存成功")
if (this.onChannelChange) {
this.onChannelChange()
}
node.loaded = false
node.expand();
}else {
this.$message.error(res.data.msg)
}
this.loading = false
}).catch((error)=> {
this.$message.error(error)
this.loading = false
});
})
2024-07-29 17:44:34 +08:00
},
removeChannelFormDevice: function (id, node) {
2024-07-31 15:07:54 +08:00
this.$refs.gbDeviceSelect.openDialog((rows)=>{
let deviceIds = []
for (let i = 0; i < rows.length; i++) {
deviceIds.push(rows[i].id)
}
this.$axios({
method: 'post',
url: `/api/common/channel/region/device/delete`,
data: {
deviceIds: deviceIds,
}
}).then((res)=> {
if (res.data.code === 0) {
this.$message.success("保存成功")
if (this.onChannelChange) {
this.onChannelChange()
}
node.loaded = false
node.expand();
}else {
this.$message.error(res.data.msg)
}
this.loading = false
}).catch((error)=> {
this.$message.error(error)
this.loading = false
});
})
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-31 15:07:54 +08:00
refresh: function (id) {
// 查询node
let node = this.$refs.veTree.getNode(id)
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();
2024-08-23 17:50:29 +08:00
}, node.data.deviceId, node.data.id);
2024-07-25 18:02:22 +08:00
},
2024-08-24 00:29:40 +08:00
editCatalog: function (data, node){
// 打开添加弹窗
this.$refs.regionCode.openDialog(form => {
node.loaded = false
node.expand();
}, node.data.deviceId, node.data.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-31 15:07:54 +08:00
2024-07-23 18:00:47 +08:00
</style>