2024-01-09 13:49:21 +08:00
|
|
|
|
<template>
|
2024-01-15 20:29:12 +08:00
|
|
|
|
<Tree
|
|
|
|
|
|
ref="treRef"
|
|
|
|
|
|
@check-change="handleCheckChange"
|
|
|
|
|
|
:default-checked-keys="defaultCheckedKeys"
|
|
|
|
|
|
:show-checkbox="props.showCheckbox"
|
|
|
|
|
|
:data="tree"
|
2026-01-04 14:55:31 +08:00
|
|
|
|
:height="props.height"
|
2024-09-25 16:31:45 +08:00
|
|
|
|
@changeDeviceType="changeDeviceType"
|
2024-01-15 20:29:12 +08:00
|
|
|
|
/>
|
2024-01-09 13:49:21 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2026-01-07 13:14:26 +08:00
|
|
|
|
import { ref, nextTick } from 'vue'
|
2024-06-27 09:39:53 +08:00
|
|
|
|
import Tree from '../device.vue'
|
2024-01-09 13:49:21 +08:00
|
|
|
|
import { getDeviceTree } from '@/api/cs-device-boot/csLedger'
|
|
|
|
|
|
import { useConfig } from '@/stores/config'
|
2026-01-07 13:14:26 +08:00
|
|
|
|
import { throttle } from 'lodash'
|
2024-01-09 13:49:21 +08:00
|
|
|
|
defineOptions({
|
|
|
|
|
|
name: 'govern/deviceTree'
|
|
|
|
|
|
})
|
2024-01-15 20:29:12 +08:00
|
|
|
|
const props = withDefaults(
|
|
|
|
|
|
defineProps<{
|
|
|
|
|
|
showCheckbox?: boolean
|
|
|
|
|
|
defaultCheckedKeys?: any
|
2026-01-04 14:55:31 +08:00
|
|
|
|
height?: number
|
2024-01-15 20:29:12 +08:00
|
|
|
|
}>(),
|
|
|
|
|
|
{
|
|
|
|
|
|
showCheckbox: false,
|
2026-01-04 14:55:31 +08:00
|
|
|
|
defaultCheckedKeys: [],
|
2026-01-07 13:14:26 +08:00
|
|
|
|
height: 0
|
2024-01-15 20:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
)
|
2024-10-23 16:29:13 +08:00
|
|
|
|
const emit = defineEmits(['init', 'checkChange', 'deviceTypeChange'])
|
2024-01-09 13:49:21 +08:00
|
|
|
|
const config = useConfig()
|
|
|
|
|
|
const tree = ref()
|
2024-01-11 08:54:09 +08:00
|
|
|
|
const treRef = ref()
|
2024-09-25 16:31:45 +08:00
|
|
|
|
const changeDeviceType = (val: any, obj: any) => {
|
|
|
|
|
|
emit('deviceTypeChange', val, obj)
|
|
|
|
|
|
}
|
2024-01-09 13:49:21 +08:00
|
|
|
|
getDeviceTree().then(res => {
|
|
|
|
|
|
let arr: any[] = []
|
2024-10-23 16:29:13 +08:00
|
|
|
|
let arr2: any[] = []
|
2025-10-11 10:35:25 +08:00
|
|
|
|
let arr3: any[] = []
|
2024-06-27 09:39:53 +08:00
|
|
|
|
//治理设备
|
|
|
|
|
|
res.data.map((item: any) => {
|
|
|
|
|
|
if (item.name == '治理设备') {
|
|
|
|
|
|
item.children.forEach((item: any) => {
|
|
|
|
|
|
item.icon = 'el-icon-HomeFilled'
|
|
|
|
|
|
item.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
item.children.forEach((item2: any) => {
|
|
|
|
|
|
item2.icon = 'el-icon-List'
|
|
|
|
|
|
item2.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
item2.children.forEach((item3: any) => {
|
2026-01-23 09:24:13 +08:00
|
|
|
|
item3.pName = '治理设备'
|
2024-06-27 09:39:53 +08:00
|
|
|
|
item3.icon = 'el-icon-Platform'
|
2025-12-20 23:44:46 +08:00
|
|
|
|
item3.level = 2
|
2024-06-27 09:39:53 +08:00
|
|
|
|
item3.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
if (item3.comFlag === 1) {
|
|
|
|
|
|
item3.color = '#e26257 !important'
|
|
|
|
|
|
}
|
|
|
|
|
|
arr.push(item3)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2024-01-09 13:49:21 +08:00
|
|
|
|
})
|
2024-06-27 09:39:53 +08:00
|
|
|
|
} else if (item.name == '便携式设备') {
|
|
|
|
|
|
item.children.forEach((item: any) => {
|
|
|
|
|
|
item.icon = 'el-icon-Platform'
|
|
|
|
|
|
item.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
item.color = '#e26257 !important'
|
2024-09-18 16:28:16 +08:00
|
|
|
|
item.color = item.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
|
2026-01-07 13:14:26 +08:00
|
|
|
|
// item.disabled =true
|
|
|
|
|
|
item.pName = '便携式设备'
|
2024-10-23 16:29:13 +08:00
|
|
|
|
if (item.type == 'device') {
|
|
|
|
|
|
arr2.push(item)
|
|
|
|
|
|
}
|
2024-06-27 09:39:53 +08:00
|
|
|
|
item.children.forEach((item2: any) => {
|
|
|
|
|
|
item2.icon = 'el-icon-Platform'
|
2024-09-18 16:28:16 +08:00
|
|
|
|
item2.color = item2.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
|
2026-01-07 13:14:26 +08:00
|
|
|
|
item2.pName = '便携式设备'
|
2024-06-27 09:39:53 +08:00
|
|
|
|
// item2.children.forEach((item3: any) => {
|
|
|
|
|
|
// item3.icon = 'el-icon-Platform'
|
|
|
|
|
|
// item3.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
// if (item3.comFlag === 1) {
|
|
|
|
|
|
// item3.color = '#e26257 !important'
|
|
|
|
|
|
// }
|
|
|
|
|
|
// arr.push(item3)
|
|
|
|
|
|
// })
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2026-01-08 11:33:40 +08:00
|
|
|
|
} else if (item.name == '监测设备') {
|
2025-12-20 23:44:46 +08:00
|
|
|
|
item.children.forEach((item: any) => {
|
2025-10-11 10:35:25 +08:00
|
|
|
|
item.icon = 'el-icon-HomeFilled'
|
|
|
|
|
|
item.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
item.children.forEach((item2: any) => {
|
|
|
|
|
|
item2.icon = 'el-icon-List'
|
|
|
|
|
|
item2.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
item2.children.forEach((item3: any) => {
|
2026-01-23 09:24:13 +08:00
|
|
|
|
item3.pName = '监测设备'
|
2025-10-11 10:35:25 +08:00
|
|
|
|
item3.icon = 'el-icon-Platform'
|
|
|
|
|
|
item3.color = config.getColorVal('elementUiPrimary')
|
|
|
|
|
|
if (item3.comFlag === 1) {
|
|
|
|
|
|
item3.color = '#e26257 !important'
|
|
|
|
|
|
}
|
|
|
|
|
|
arr3.push(item3)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2024-06-27 09:39:53 +08:00
|
|
|
|
}
|
2024-01-09 13:49:21 +08:00
|
|
|
|
})
|
|
|
|
|
|
tree.value = res.data
|
2025-12-20 23:44:46 +08:00
|
|
|
|
|
2024-01-11 08:54:09 +08:00
|
|
|
|
nextTick(() => {
|
2025-12-20 23:44:46 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
if (arr.length > 0) {
|
|
|
|
|
|
treRef.value.treeRef1.setCurrentKey(arr[0].id)
|
|
|
|
|
|
// 注册父组件事件
|
|
|
|
|
|
emit('init', {
|
|
|
|
|
|
level: 2,
|
|
|
|
|
|
...arr[0]
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
} else if (arr2.length > 0) {
|
|
|
|
|
|
treRef.value.treeRef2.setCurrentKey(arr2[0].id)
|
|
|
|
|
|
// 注册父组件事件
|
|
|
|
|
|
emit('init', {
|
|
|
|
|
|
level: 2,
|
|
|
|
|
|
...arr2[0]
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
} else if (arr3.length > 0) {
|
2026-01-04 14:55:31 +08:00
|
|
|
|
console.log('🚀 ~ arr3:', arr3)
|
|
|
|
|
|
|
2025-12-20 23:44:46 +08:00
|
|
|
|
treRef.value.treeRef3.setCurrentKey(arr3[0].id)
|
|
|
|
|
|
// 注册父组件事件
|
|
|
|
|
|
emit('init', {
|
|
|
|
|
|
level: 2,
|
|
|
|
|
|
...arr3[0]
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
} else {
|
|
|
|
|
|
emit('init')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 500)
|
2024-01-11 08:54:09 +08:00
|
|
|
|
})
|
2024-01-09 13:49:21 +08:00
|
|
|
|
})
|
2026-01-07 13:14:26 +08:00
|
|
|
|
|
|
|
|
|
|
throttle(
|
|
|
|
|
|
(data: any, checked: any, indeterminate: any) => {
|
|
|
|
|
|
emit('checkChange', {
|
|
|
|
|
|
data,
|
|
|
|
|
|
checked,
|
|
|
|
|
|
indeterminate
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
300,
|
|
|
|
|
|
{
|
|
|
|
|
|
leading: true, // 首次触发立即执行(可选,默认 true)
|
|
|
|
|
|
trailing: false // 节流结束后是否执行最后一次(可选,默认 true,根据需求调整)
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2024-01-15 20:29:12 +08:00
|
|
|
|
const handleCheckChange = (data: any, checked: any, indeterminate: any) => {
|
|
|
|
|
|
emit('checkChange', {
|
|
|
|
|
|
data,
|
|
|
|
|
|
checked,
|
|
|
|
|
|
indeterminate
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-01-07 13:14:26 +08:00
|
|
|
|
defineExpose({
|
|
|
|
|
|
treRef
|
|
|
|
|
|
})
|
2024-01-09 13:49:21 +08:00
|
|
|
|
</script>
|