Files
admin-govern/src/components/tree/govern/deviceTree.vue

151 lines
5.2 KiB
Vue
Raw Normal View History

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"
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>
2024-09-25 16:31:45 +08:00
import { ref, nextTick, defineEmits } 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'
defineOptions({
name: 'govern/deviceTree'
})
2024-01-15 20:29:12 +08:00
const props = withDefaults(
defineProps<{
showCheckbox?: boolean
defaultCheckedKeys?: any
}>(),
{
showCheckbox: false,
defaultCheckedKeys: []
}
)
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) => {
2025-07-15 16:31:06 +08:00
console.log("🚀 ~ changeDeviceType ~ val:", val,obj)
2024-09-25 16:31:45 +08:00
emit('deviceTypeChange', val, obj)
}
2024-01-09 13:49:21 +08:00
getDeviceTree().then(res => {
let arr: any[] = []
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) => {
item3.icon = 'el-icon-Platform'
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'
item.color = item.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
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'
item2.color = item2.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
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)
// })
})
})
2025-10-14 09:51:42 +08:00
}else if (item.name == '在线设备') {
2025-10-11 10:35:25 +08:00
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) => {
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
})
2025-10-11 10:35:25 +08:00
console.log("🚀 ~ file: deviceTree.vue ~ line 18 ~ getDeviceTree ~ tree:", arr,arr2,arr3)
2024-01-09 13:49:21 +08:00
tree.value = res.data
2025-10-11 10:35:25 +08:00
2024-01-11 08:54:09 +08:00
nextTick(() => {
2024-01-29 14:57:49 +08:00
if (arr.length) {
2024-06-27 09:39:53 +08:00
treRef.value.treeRef1.setCurrentKey(arr[0].id)
2024-01-29 14:57:49 +08:00
// 注册父组件事件
emit('init', {
level: 2,
...arr[0]
})
return
}
if (arr2.length) {
treRef.value.treeRef2.setCurrentKey(arr2[0].id)
// 注册父组件事件
emit('init', {
level: 2,
...arr2[0]
})
return
2025-10-11 10:35:25 +08:00
}
console.log("🚀 ~ file: deviceTree.vue ~ line 33 ~ getDeviceTree ~ tree:", arr3.length)
if (arr3.length) {
console.log("🚀 ~ file: deviceTree.vue ~ line 33 ~ getDeviceTree ~ tree:", arr3)
treRef.value.treeRef3.setCurrentKey(arr3[0].id)
// 注册父组件事件
emit('init', {
level: 2,
...arr3[0]
})
return
}
else {
2024-01-29 14:57:49 +08:00
emit('init')
return
2024-01-29 14:57:49 +08:00
}
2024-01-11 08:54:09 +08:00
})
2024-01-09 13:49:21 +08:00
})
2024-01-15 20:29:12 +08:00
const handleCheckChange = (data: any, checked: any, indeterminate: any) => {
emit('checkChange', {
data,
checked,
indeterminate
})
}
2024-01-09 13:49:21 +08:00
</script>