2024-06-27 09:39:53 +08:00
|
|
|
|
<!-- 设备监控使用折叠面板渲染多个tree -->
|
|
|
|
|
|
<template>
|
2025-07-08 08:44:13 +08:00
|
|
|
|
<div :style="{ width: menuCollapse ? '40px' : props.width }" style="display: flex; overflow: hidden">
|
|
|
|
|
|
<Icon
|
|
|
|
|
|
v-show="menuCollapse"
|
|
|
|
|
|
@click="onMenuCollapse"
|
|
|
|
|
|
:name="menuCollapse ? 'el-icon-Expand' : 'el-icon-Fold'"
|
|
|
|
|
|
:class="menuCollapse ? 'unfold' : ''"
|
|
|
|
|
|
size="18"
|
|
|
|
|
|
class="fold ml10 mt20 menu-collapse"
|
|
|
|
|
|
style="cursor: pointer"
|
|
|
|
|
|
v-if="route.path != '/admin/govern/reportCore/statistics/index'"
|
|
|
|
|
|
/>
|
2024-12-23 11:30:28 +08:00
|
|
|
|
<div class="cn-tree" :style="{ opacity: menuCollapse ? 0 : 1, display: menuCollapse ? 'none' : '' }">
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<div style="display: flex; align-items: center" class="mb10">
|
2024-12-25 10:53:07 +08:00
|
|
|
|
<el-input maxlength="32" show-word-limit v-model.trim="filterText" placeholder="请输入内容" clearable>
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<template #prefix>
|
|
|
|
|
|
<Icon name="el-icon-Search" style="font-size: 16px" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-input>
|
2025-07-08 08:44:13 +08:00
|
|
|
|
<Icon
|
|
|
|
|
|
@click="onMenuCollapse"
|
|
|
|
|
|
:name="menuCollapse ? 'el-icon-Expand' : 'el-icon-Fold'"
|
|
|
|
|
|
:class="menuCollapse ? 'unfold' : ''"
|
|
|
|
|
|
size="18"
|
|
|
|
|
|
class="fold ml10 menu-collapse"
|
2024-06-27 09:39:53 +08:00
|
|
|
|
style="cursor: pointer"
|
2025-07-08 08:44:13 +08:00
|
|
|
|
v-if="props.canExpand && route.path != '/admin/govern/reportCore/statistics/index'"
|
|
|
|
|
|
/>
|
2024-06-27 09:39:53 +08:00
|
|
|
|
</div>
|
2025-07-08 08:44:13 +08:00
|
|
|
|
<el-collapse
|
|
|
|
|
|
:accordion="true"
|
|
|
|
|
|
v-model.trim="activeName"
|
|
|
|
|
|
style="flex: 1; height: 100%"
|
|
|
|
|
|
@change="changeDevice"
|
|
|
|
|
|
>
|
2024-09-25 16:31:45 +08:00
|
|
|
|
<el-collapse-item title="治理设备" name="0" v-if="zlDeviceData.length != 0">
|
2025-07-09 16:48:18 +08:00
|
|
|
|
<el-select v-model.trim="process" clearable placeholder="请选择状态" class="mb10">
|
|
|
|
|
|
<el-option label="功能调试" value="2"></el-option>
|
|
|
|
|
|
<el-option label="出厂调试" value="3"></el-option>
|
|
|
|
|
|
<el-option label="正式投运" value="4"></el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<el-tree
|
2025-07-09 16:48:18 +08:00
|
|
|
|
:style="{ height: bxsDeviceData.length != 0 ? 'calc(100vh - 340px)' : 'calc(100vh - 278px)' }"
|
2025-07-08 08:44:13 +08:00
|
|
|
|
ref="treeRef1"
|
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
|
highlight-current
|
|
|
|
|
|
:filter-node-method="filterNode"
|
|
|
|
|
|
node-key="id"
|
|
|
|
|
|
default-expand-all
|
|
|
|
|
|
v-bind="$attrs"
|
2025-07-09 16:48:18 +08:00
|
|
|
|
:data="zlDevList"
|
2025-07-08 08:44:13 +08:00
|
|
|
|
style="overflow: auto"
|
|
|
|
|
|
>
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<template #default="{ node, data }">
|
|
|
|
|
|
<span class="custom-tree-node">
|
2025-07-08 08:44:13 +08:00
|
|
|
|
<Icon
|
|
|
|
|
|
:name="data.icon"
|
|
|
|
|
|
style="font-size: 16px"
|
|
|
|
|
|
:style="{ color: data.color }"
|
|
|
|
|
|
v-if="data.icon"
|
|
|
|
|
|
/>
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<span style="margin-left: 4px">{{ node.label }}</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-tree>
|
|
|
|
|
|
</el-collapse-item>
|
2024-09-25 16:31:45 +08:00
|
|
|
|
<el-collapse-item title="便携式设备" name="1" v-if="bxsDeviceData.length != 0">
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<el-tree
|
2024-09-25 16:31:45 +08:00
|
|
|
|
:style="{ height: zlDeviceData.length != 0 ? 'calc(100vh - 280px)' : 'calc(100vh - 238px)' }"
|
2025-07-08 08:44:13 +08:00
|
|
|
|
ref="treeRef2"
|
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
|
highlight-current
|
|
|
|
|
|
default-expand-all
|
|
|
|
|
|
:filter-node-method="filterNode"
|
|
|
|
|
|
node-key="id"
|
|
|
|
|
|
:data="bxsDeviceData"
|
|
|
|
|
|
v-bind="$attrs"
|
|
|
|
|
|
style="overflow: auto"
|
|
|
|
|
|
>
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<template #default="{ node, data }">
|
|
|
|
|
|
<span class="custom-tree-node">
|
2025-07-08 08:44:13 +08:00
|
|
|
|
<Icon
|
|
|
|
|
|
:name="data.icon"
|
|
|
|
|
|
style="font-size: 16px"
|
|
|
|
|
|
:style="{ color: data.color }"
|
|
|
|
|
|
v-if="data.icon"
|
|
|
|
|
|
/>
|
2024-06-27 09:39:53 +08:00
|
|
|
|
<span style="margin-left: 4px">{{ node.label }}</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-tree>
|
|
|
|
|
|
</el-collapse-item>
|
|
|
|
|
|
</el-collapse>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
|
import useCurrentInstance from '@/utils/useCurrentInstance'
|
|
|
|
|
|
import { ElTree } from 'element-plus'
|
2025-07-09 16:48:18 +08:00
|
|
|
|
import { ref, watch, defineEmits, onMounted, nextTick, computed } from 'vue'
|
2024-07-24 15:20:43 +08:00
|
|
|
|
import { useRoute } from 'vue-router'
|
2024-06-27 09:39:53 +08:00
|
|
|
|
defineOptions({
|
|
|
|
|
|
name: 'govern/tree'
|
|
|
|
|
|
})
|
2024-08-23 08:51:36 +08:00
|
|
|
|
const emit = defineEmits(['changePointType'])
|
2024-06-27 09:39:53 +08:00
|
|
|
|
interface Props {
|
|
|
|
|
|
width?: string
|
|
|
|
|
|
canExpand?: boolean
|
|
|
|
|
|
type?: string
|
|
|
|
|
|
data?: any
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
2024-07-22 10:35:01 +08:00
|
|
|
|
width: '100%',
|
2024-06-27 09:39:53 +08:00
|
|
|
|
canExpand: true,
|
|
|
|
|
|
type: '',
|
|
|
|
|
|
data: []
|
|
|
|
|
|
})
|
2025-07-15 16:31:06 +08:00
|
|
|
|
const process = ref('')
|
2024-07-24 15:20:43 +08:00
|
|
|
|
const route = useRoute()
|
2024-06-27 09:39:53 +08:00
|
|
|
|
const { proxy } = useCurrentInstance()
|
|
|
|
|
|
const menuCollapse = ref(false)
|
2024-08-23 08:51:36 +08:00
|
|
|
|
const activeName = ref('0')
|
2024-06-27 09:39:53 +08:00
|
|
|
|
const filterText = ref('')
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
|
label: 'name',
|
|
|
|
|
|
value: 'id'
|
|
|
|
|
|
}
|
|
|
|
|
|
//治理设备数据
|
2024-10-09 11:29:20 +08:00
|
|
|
|
const zlDeviceData = ref<any>([])
|
2025-07-09 16:48:18 +08:00
|
|
|
|
const zlDevList = ref<any>([])
|
2024-06-27 09:39:53 +08:00
|
|
|
|
//便携式设备数据
|
2024-10-09 11:29:20 +08:00
|
|
|
|
const bxsDeviceData = ref<any>([])
|
2024-06-27 09:39:53 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.data,
|
|
|
|
|
|
(val, oldVal) => {
|
|
|
|
|
|
if (val && val.length != 0) {
|
|
|
|
|
|
val.map((item: any) => {
|
|
|
|
|
|
if (item.name == '治理设备') {
|
|
|
|
|
|
item.children.map((vv: any) => {
|
|
|
|
|
|
zlDeviceData.value.push(vv)
|
|
|
|
|
|
})
|
2025-07-08 08:44:13 +08:00
|
|
|
|
// console.log('🚀 ~ item.children.map ~ zlDeviceData.value:', zlDeviceData.value)
|
2024-06-27 09:39:53 +08:00
|
|
|
|
} else if (item.name == '便携式设备') {
|
|
|
|
|
|
item.children.map((vv: any) => {
|
|
|
|
|
|
bxsDeviceData.value.push(vv)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2025-07-08 08:44:13 +08:00
|
|
|
|
if (zlDeviceData.value.length != 0) {
|
2025-07-09 16:48:18 +08:00
|
|
|
|
zlDevList.value = filterProcess(JSON.parse(JSON.stringify(zlDeviceData.value)))
|
2025-07-08 08:44:13 +08:00
|
|
|
|
activeName.value = '0'
|
|
|
|
|
|
}
|
|
|
|
|
|
if (zlDeviceData.value.length === 0 && bxsDeviceData.value.length != 0) {
|
|
|
|
|
|
activeName.value = '1'
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!zlDeviceData.value && !bxsDeviceData.value) {
|
|
|
|
|
|
activeName.value = ''
|
|
|
|
|
|
}
|
2025-07-09 16:48:18 +08:00
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
changeDevice(activeName.value)
|
|
|
|
|
|
})
|
2024-06-27 09:39:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
immediate: true,
|
|
|
|
|
|
deep: true
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
watch(filterText, val => {
|
2024-08-23 08:51:36 +08:00
|
|
|
|
if (activeName.value == '0') {
|
2024-06-27 09:39:53 +08:00
|
|
|
|
treeRef1.value!.filter(val)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
treeRef2.value!.filter(val)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2025-07-09 16:48:18 +08:00
|
|
|
|
watch(process, val => {
|
|
|
|
|
|
if (val == '') {
|
|
|
|
|
|
zlDevList.value = JSON.parse(JSON.stringify(zlDeviceData.value))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
zlDevList.value = filterProcess(JSON.parse(JSON.stringify(zlDeviceData.value)))
|
|
|
|
|
|
}
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
changeDevice(activeName.value)
|
|
|
|
|
|
}, 0)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2024-06-27 09:39:53 +08:00
|
|
|
|
const changeDevice = (val: any) => {
|
|
|
|
|
|
let arr1: any = []
|
2025-07-09 16:48:18 +08:00
|
|
|
|
//zlDeviceData
|
|
|
|
|
|
zlDevList.value.forEach((item: any) => {
|
2024-06-27 09:39:53 +08:00
|
|
|
|
item.children.forEach((item2: any) => {
|
|
|
|
|
|
item2.children.forEach((item3: any) => {
|
|
|
|
|
|
item3.children.forEach((item4: any) => {
|
|
|
|
|
|
arr1.push(item4)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
let arr2: any = []
|
|
|
|
|
|
bxsDeviceData.value.forEach((item: any) => {
|
|
|
|
|
|
item.children.forEach((item2: any) => {
|
|
|
|
|
|
arr2.push(item2)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2024-10-09 11:29:20 +08:00
|
|
|
|
activeName.value = val
|
2024-08-23 08:51:36 +08:00
|
|
|
|
if (val == '0') {
|
|
|
|
|
|
arr2.map((item: any) => {
|
2024-06-27 09:39:53 +08:00
|
|
|
|
item.checked = false
|
|
|
|
|
|
})
|
2024-09-25 16:31:45 +08:00
|
|
|
|
treeRef1?.value && treeRef1.value.setCurrentKey(arr1[0]?.id)
|
2024-08-23 08:51:36 +08:00
|
|
|
|
emit('changePointType', activeName.value, arr1[0])
|
2024-09-26 16:11:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (val == '1') {
|
2024-08-23 08:51:36 +08:00
|
|
|
|
arr1.map((item: any) => {
|
2024-06-27 09:39:53 +08:00
|
|
|
|
item.checked = false
|
|
|
|
|
|
})
|
2024-09-25 16:31:45 +08:00
|
|
|
|
treeRef2?.value && treeRef2.value.setCurrentKey(arr2[0]?.id)
|
2024-08-23 08:51:36 +08:00
|
|
|
|
emit('changePointType', activeName.value, arr2[0])
|
2024-06-27 09:39:53 +08:00
|
|
|
|
}
|
2024-08-23 08:51:36 +08:00
|
|
|
|
// if(activeName.value){
|
|
|
|
|
|
// emit('changePointType', activeName.value)
|
|
|
|
|
|
// }
|
2024-06-27 09:39:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
const onMenuCollapse = () => {
|
|
|
|
|
|
menuCollapse.value = !menuCollapse.value
|
|
|
|
|
|
proxy.eventBus.emit('cnTreeCollapse', menuCollapse)
|
|
|
|
|
|
}
|
2024-12-17 20:57:07 +08:00
|
|
|
|
const filterNode = (value: string, data: any, node: any) => {
|
2024-06-27 09:39:53 +08:00
|
|
|
|
if (!value) return true
|
2024-12-17 20:57:07 +08:00
|
|
|
|
// return data.name.includes(value)
|
|
|
|
|
|
if (data.name) {
|
|
|
|
|
|
return chooseNode(value, data, node)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-09 16:48:18 +08:00
|
|
|
|
function filterProcess(nodes: any) {
|
2025-07-15 16:31:06 +08:00
|
|
|
|
if (process.value == '') {
|
|
|
|
|
|
return nodes
|
|
|
|
|
|
}
|
2025-07-09 16:48:18 +08:00
|
|
|
|
return nodes
|
|
|
|
|
|
.map(node => {
|
|
|
|
|
|
// 递归处理子节点
|
|
|
|
|
|
const children = node.children ? filterProcess(node.children) : []
|
|
|
|
|
|
|
|
|
|
|
|
// 如果当前节点的process=4,或者有子节点满足条件,则保留当前节点
|
2025-07-15 16:31:06 +08:00
|
|
|
|
|
2025-07-09 16:48:18 +08:00
|
|
|
|
if (node.process == process.value || children.length > 0) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
...node,
|
|
|
|
|
|
children: node.children
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-17 20:57:07 +08:00
|
|
|
|
|
2025-07-09 16:48:18 +08:00
|
|
|
|
// 否则过滤掉当前节点
|
|
|
|
|
|
return null
|
|
|
|
|
|
})
|
|
|
|
|
|
.filter(Boolean) // 移除null节点
|
|
|
|
|
|
}
|
2024-12-17 20:57:07 +08:00
|
|
|
|
// 过滤父节点 / 子节点 (如果输入的参数是父节点且能匹配,则返回该节点以及其下的所有子节点;如果参数是子节点,则返回该节点的父节点。name是中文字符,enName是英文字符.
|
|
|
|
|
|
const chooseNode = (value: string, data: any, node: any) => {
|
|
|
|
|
|
if (data.name.indexOf(value) !== -1) {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
const level = node.level
|
|
|
|
|
|
// 如果传入的节点本身就是一级节点就不用校验了
|
|
|
|
|
|
if (level === 1) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
// 先取当前节点的父节点
|
|
|
|
|
|
let parentData = node.parent
|
|
|
|
|
|
// 遍历当前节点的父节点
|
|
|
|
|
|
let index = 0
|
|
|
|
|
|
while (index < level - 1) {
|
|
|
|
|
|
// 如果匹配到直接返回,此处name值是中文字符,enName是英文字符。判断匹配中英文过滤
|
|
|
|
|
|
if (parentData.data.name.indexOf(value) !== -1) {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
// 否则的话再往上一层做匹配
|
|
|
|
|
|
parentData = parentData.parent
|
|
|
|
|
|
index++
|
|
|
|
|
|
}
|
|
|
|
|
|
// 没匹配到返回false
|
|
|
|
|
|
return false
|
2024-06-27 09:39:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
//治理
|
|
|
|
|
|
const treeRef1 = ref<InstanceType<typeof ElTree>>()
|
|
|
|
|
|
//便携式
|
|
|
|
|
|
const treeRef2 = ref<InstanceType<typeof ElTree>>()
|
|
|
|
|
|
defineExpose({ treeRef1, treeRef2 })
|
2024-09-25 16:31:45 +08:00
|
|
|
|
onMounted(() => {
|
2025-07-08 08:44:13 +08:00
|
|
|
|
// nextTick(() => {
|
|
|
|
|
|
// // setTimeout(() => {
|
|
|
|
|
|
// // }, 500)
|
|
|
|
|
|
// })
|
2024-09-25 16:31:45 +08:00
|
|
|
|
})
|
2024-06-27 09:39:53 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.cn-tree {
|
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
height: 100%;
|
2024-12-23 11:30:28 +08:00
|
|
|
|
width: 280px;
|
2024-07-22 10:35:01 +08:00
|
|
|
|
background: #fff;
|
2024-06-27 09:39:53 +08:00
|
|
|
|
|
|
|
|
|
|
:deep(.el-tree) {
|
|
|
|
|
|
border: 1px solid var(--el-border-color);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content) {
|
|
|
|
|
|
background-color: var(--el-color-primary-light-7);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu-collapse {
|
|
|
|
|
|
color: var(--el-color-primary);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.custom-tree-node {
|
2024-10-25 14:08:42 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2024-06-27 09:39:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|