2024-07-23 18:00:47 +08:00
|
|
|
|
<template>
|
2024-07-24 17:54:19 +08:00
|
|
|
|
<div id="DeviceTree">
|
2024-09-12 17:49:16 +08:00
|
|
|
|
<div class="page-header" style="margin-bottom: 1rem;" v-if="showHeader">
|
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-09-12 17:49:16 +08:00
|
|
|
|
<div v-if="showHeader" style="height: 2rem; background-color: #FFFFFF" ></div>
|
|
|
|
|
<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-09-26 15:57:55 +08:00
|
|
|
|
node-key="treeId"
|
2024-11-07 16:27:39 +08:00
|
|
|
|
:height="treeHeight?treeHeight:'78vh'"
|
2024-07-25 18:02:22 +08:00
|
|
|
|
lazy
|
2024-09-12 17:49:16 +08:00
|
|
|
|
style="padding: 0 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"
|
|
|
|
|
>
|
2024-11-05 18:23:58 +08:00
|
|
|
|
<template class="custom-tree-node" v-slot:default="{ node, data }">
|
|
|
|
|
<span class="custom-tree-node" >
|
|
|
|
|
<span v-if="node.data.type === 0 && chooseId !== node.data.deviceId" style="color: #409EFF" class="iconfont icon-bianzubeifen3"></span>
|
2024-11-07 13:28:46 +08:00
|
|
|
|
<span v-if="node.data.type === 0 && chooseId === node.data.deviceId" style="color: #c60135;" class="iconfont icon-bianzubeifen3"></span>
|
2024-10-21 12:29:15 +08:00
|
|
|
|
<span v-if="node.data.type === 1 && node.data.status === 'ON'" style="color: #409EFF" class="iconfont icon-shexiangtou2"></span>
|
|
|
|
|
<span v-if="node.data.type === 1 && node.data.status !== 'ON'" style="color: #808181" 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-11-05 18:23:58 +08:00
|
|
|
|
</template>
|
2024-07-25 18:02:22 +08:00
|
|
|
|
</vue-easy-tree>
|
|
|
|
|
</div>
|
2024-08-27 17:56:49 +08:00
|
|
|
|
<regionEdit ref="regionEdit"></regionEdit>
|
2024-07-31 15:07:54 +08:00
|
|
|
|
<gbDeviceSelect ref="gbDeviceSelect"></gbDeviceSelect>
|
2024-11-07 13:28:46 +08:00
|
|
|
|
<GbChannelSelect ref="gbChannelSelect" dataType="civilCode"></GbChannelSelect>
|
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-08-27 17:56:49 +08:00
|
|
|
|
import regionEdit from './../dialog/regionEdit'
|
2024-07-31 15:07:54 +08:00
|
|
|
|
import gbDeviceSelect from './../dialog/GbDeviceSelect'
|
2024-11-07 13:28:46 +08:00
|
|
|
|
import GbChannelSelect from "../dialog/GbChannelSelect.vue";
|
2024-07-23 18:00:47 +08:00
|
|
|
|
|
|
|
|
|
export default {
|
2024-07-24 17:54:19 +08:00
|
|
|
|
name: 'DeviceTree',
|
|
|
|
|
components: {
|
2024-11-07 13:28:46 +08:00
|
|
|
|
GbChannelSelect,
|
2024-08-27 17:56:49 +08:00
|
|
|
|
VueEasyTree, regionEdit, 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-11-07 16:27:39 +08:00
|
|
|
|
props: ['edit', 'enableAddChannel', 'clickEvent', 'onChannelChange', 'showHeader', 'hasChannel', 'addChannelToCivilCode', 'treeHeight'],
|
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-09-26 15:57:55 +08:00
|
|
|
|
treeId: "",
|
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-09-12 23:15:10 +08:00
|
|
|
|
if (node.data.leaf) {
|
|
|
|
|
resolve([]);
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-07-25 18:02:22 +08:00
|
|
|
|
this.$axios({
|
|
|
|
|
method: 'get',
|
|
|
|
|
url: `/api/region/tree/list`,
|
|
|
|
|
params: {
|
|
|
|
|
query: this.searchSrt,
|
2024-11-05 18:23:58 +08:00
|
|
|
|
parent: node.data.id,
|
|
|
|
|
hasChannel: this.hasChannel
|
2024-07-25 18:02:22 +08:00
|
|
|
|
}
|
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-09-12 17:49:16 +08:00
|
|
|
|
if (!this.edit) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-07-26 17:53:10 +08:00
|
|
|
|
console.log(node.level)
|
2024-11-05 18:23:58 +08:00
|
|
|
|
if (node.data.type === 0) {
|
2024-11-07 16:27:39 +08:00
|
|
|
|
let menuItem = [
|
|
|
|
|
{
|
|
|
|
|
label: "刷新节点",
|
|
|
|
|
icon: "el-icon-refresh",
|
|
|
|
|
disabled: false,
|
|
|
|
|
onClick: () => {
|
|
|
|
|
this.refreshNode(node);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "新建节点",
|
|
|
|
|
icon: "el-icon-plus",
|
|
|
|
|
disabled: false,
|
|
|
|
|
onClick: () => {
|
|
|
|
|
this.addRegion(data.id, node);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "编辑节点",
|
|
|
|
|
icon: "el-icon-edit",
|
|
|
|
|
disabled: node.level === 1,
|
|
|
|
|
onClick: () => {
|
|
|
|
|
this.editCatalog(data, node);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "删除节点",
|
|
|
|
|
icon: "el-icon-delete",
|
|
|
|
|
disabled: node.level === 1,
|
|
|
|
|
divided: true,
|
|
|
|
|
onClick: () => {
|
|
|
|
|
this.$confirm('确定删除?', '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
|
|
|
|
this.removeRegion(data.id, node)
|
|
|
|
|
}).catch(() => {
|
2024-07-25 18:02:22 +08:00
|
|
|
|
|
2024-11-07 16:27:39 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
if (this.enableAddChannel) {
|
|
|
|
|
menuItem.push(
|
2024-07-29 17:44:34 +08:00
|
|
|
|
{
|
|
|
|
|
label: "添加设备",
|
|
|
|
|
icon: "el-icon-plus",
|
|
|
|
|
disabled: node.level === 1,
|
|
|
|
|
onClick: () => {
|
|
|
|
|
this.addChannelFormDevice(data.id, node)
|
|
|
|
|
}
|
2024-11-07 16:27:39 +08:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
menuItem.push(
|
2024-07-29 17:44:34 +08:00
|
|
|
|
{
|
|
|
|
|
label: "移除设备",
|
|
|
|
|
icon: "el-icon-delete",
|
|
|
|
|
disabled: node.level === 1,
|
2024-11-05 18:23:58 +08:00
|
|
|
|
divided: true,
|
2024-07-29 17:44:34 +08:00
|
|
|
|
onClick: () => {
|
|
|
|
|
this.removeChannelFormDevice(data.id, node)
|
|
|
|
|
}
|
2024-11-07 16:27:39 +08:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
menuItem.push(
|
2024-11-05 18:23:58 +08:00
|
|
|
|
{
|
|
|
|
|
label: "添加通道",
|
|
|
|
|
icon: "el-icon-plus",
|
|
|
|
|
disabled: node.level === 1,
|
|
|
|
|
onClick: () => {
|
|
|
|
|
this.addChannel(data.id, node)
|
|
|
|
|
}
|
2024-11-07 16:27:39 +08:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-07-25 18:02:22 +08:00
|
|
|
|
|
2024-11-07 16:27:39 +08:00
|
|
|
|
|
|
|
|
|
this.$contextmenu({
|
|
|
|
|
items: menuItem,
|
2024-07-25 18:02:22 +08:00
|
|
|
|
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) {
|
2024-08-26 17:59:29 +08:00
|
|
|
|
this.$message.success({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: "保存成功"
|
|
|
|
|
})
|
2024-07-31 15:07:54 +08:00
|
|
|
|
if (this.onChannelChange) {
|
2024-11-07 13:28:46 +08:00
|
|
|
|
this.onChannelChange()
|
2024-07-31 15:07:54 +08:00
|
|
|
|
}
|
|
|
|
|
node.loaded = false
|
|
|
|
|
node.expand();
|
|
|
|
|
}else {
|
2024-08-26 17:59:29 +08:00
|
|
|
|
this.$message.error({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: res.data.msg
|
|
|
|
|
})
|
2024-07-31 15:07:54 +08:00
|
|
|
|
}
|
|
|
|
|
this.loading = false
|
|
|
|
|
}).catch((error)=> {
|
2024-08-26 17:59:29 +08:00
|
|
|
|
this.$message.error({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: error
|
|
|
|
|
})
|
2024-07-31 15:07:54 +08:00
|
|
|
|
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) {
|
2024-08-26 17:59:29 +08:00
|
|
|
|
this.$message.success({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: "保存成功"
|
|
|
|
|
})
|
2024-07-31 15:07:54 +08:00
|
|
|
|
if (this.onChannelChange) {
|
2024-11-05 18:23:58 +08:00
|
|
|
|
this.onChannelChange(node.data.deviceId)
|
|
|
|
|
}
|
|
|
|
|
node.loaded = false
|
|
|
|
|
node.expand();
|
|
|
|
|
}else {
|
|
|
|
|
this.$message.error({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: res.data.msg
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.loading = false
|
|
|
|
|
}).catch((error)=> {
|
|
|
|
|
this.$message.error({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: error
|
|
|
|
|
})
|
|
|
|
|
this.loading = false
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
addChannel: function (id, node) {
|
2024-11-07 13:28:46 +08:00
|
|
|
|
this.$refs.gbChannelSelect.openDialog((data) => {
|
|
|
|
|
console.log("选择的数据")
|
|
|
|
|
console.log(data)
|
|
|
|
|
this.addChannelToCivilCode(node.data.deviceId, data)
|
2024-07-31 15:07:54 +08:00
|
|
|
|
})
|
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)
|
2024-09-27 11:17:45 +08:00
|
|
|
|
if (node) {
|
|
|
|
|
node.loaded = false
|
|
|
|
|
node.expand();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-31 15:07:54 +08:00
|
|
|
|
},
|
2024-07-26 17:53:10 +08:00
|
|
|
|
addRegion: function (id, node) {
|
2024-07-25 18:02:22 +08:00
|
|
|
|
|
|
|
|
|
console.log(node)
|
|
|
|
|
|
2024-08-27 17:56:49 +08:00
|
|
|
|
this.$refs.regionEdit.openDialog(form => {
|
2024-07-25 18:02:22 +08:00
|
|
|
|
node.loaded = false
|
|
|
|
|
node.expand();
|
2024-08-24 21:54:59 +08:00
|
|
|
|
}, {
|
|
|
|
|
deviceId: "",
|
|
|
|
|
name: "",
|
|
|
|
|
parentId: node.data.id,
|
|
|
|
|
parentDeviceId: node.data.deviceId,
|
|
|
|
|
});
|
2024-07-25 18:02:22 +08:00
|
|
|
|
},
|
2024-08-24 00:29:40 +08:00
|
|
|
|
editCatalog: function (data, node){
|
|
|
|
|
// 打开添加弹窗
|
2024-08-27 17:56:49 +08:00
|
|
|
|
this.$refs.regionEdit.openDialog(form => {
|
2024-08-24 00:29:40 +08:00
|
|
|
|
node.loaded = false
|
|
|
|
|
node.expand();
|
2024-08-24 21:54:59 +08:00
|
|
|
|
}, node.data);
|
2024-08-24 00:29:40 +08:00
|
|
|
|
},
|
2024-07-26 17:53:10 +08:00
|
|
|
|
nodeClickHandler: function (data, node, tree) {
|
2024-11-07 13:28:46 +08:00
|
|
|
|
|
2024-11-05 18:23:58 +08:00
|
|
|
|
this.chooseId = data.deviceId;
|
2024-09-12 17:49:16 +08:00
|
|
|
|
if (this.clickEvent) {
|
|
|
|
|
this.clickEvent(data)
|
|
|
|
|
}
|
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>
|