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

113 lines
3.2 KiB
Vue
Raw Normal View History

2025-10-11 10:35:25 +08:00
<template>
2026-04-02 09:08:57 +08:00
<Tree
ref="treRef"
:width="width"
:showPush="props.showPush"
:expand-on-click-node="false"
:data="tree"
@changePointType="changePointType"
@onAdd="onAdd"
/>
2025-10-11 10:35:25 +08:00
</template>
<script lang="ts" setup>
import { ref, nextTick, onMounted, defineProps } from 'vue'
import Tree from '../index.vue'
2026-04-02 09:08:57 +08:00
import { getLineTree, getCldTree } from '@/api/cs-device-boot/csLedger'
2025-10-11 10:35:25 +08:00
import { useConfig } from '@/stores/config'
2026-01-27 16:32:33 +08:00
import { querySysExcel } from '@/api/harmonic-boot/luckyexcel'
2025-10-11 10:35:25 +08:00
import { useDictData } from '@/stores/dictData'
interface Props {
template?: boolean
2025-12-09 13:58:37 +08:00
showPush?: boolean
2025-10-11 10:35:25 +08:00
}
const props = withDefaults(defineProps<Props>(), {
2025-12-09 13:58:37 +08:00
template: false,
showPush: false
2025-10-11 10:35:25 +08:00
})
defineOptions({
name: 'govern/deviceTree'
})
2026-04-02 09:08:57 +08:00
const emit = defineEmits(['init', 'checkChange', 'pointTypeChange', 'Policy', 'onAdd'])
2025-10-11 10:35:25 +08:00
const config = useConfig()
const tree = ref()
const dictData = useDictData()
const treRef = ref()
const width = ref('')
const info = (selectedNodeId?: string) => {
tree.value = []
let arr1: any[] = []
getCldTree().then(res => {
2026-04-02 09:08:57 +08:00
res.data.icon = 'el-icon-Menu'
res.data.color = config.getColorVal('elementUiPrimary')
res.data?.children.map((item: any) => {
item.icon = 'el-icon-HomeFilled'
item.color = config.getColorVal('elementUiPrimary')
item.children.forEach((item: any) => {
item.icon = 'el-icon-List'
item.color = config.getColorVal('elementUiPrimary')
item.children.forEach((item2: any) => {
// item2.icon = 'el-icon-List'
// item2.color = config.getColorVal('elementUiPrimary')
item2.icon = 'el-icon-Platform'
item2.level = 2
item2.color = item2.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
item2.children.forEach((item3: any) => {
item3.icon = 'el-icon-Platform'
item3.color =
item3.comFlag === 2 ? config.getColorVal('elementUiPrimary') : '#e26257 !important'
arr1.push(item3)
2025-10-11 10:35:25 +08:00
})
})
})
2026-04-02 09:08:57 +08:00
})
tree.value = [res.data]
nextTick(() => {
setTimeout(() => {
//初始化选中
treRef.value?.treeRef.setCurrentKey(arr1[0].id)
// 注册父组件事件
emit('init', {
level: 3,
...arr1[0]
})
changePointType('4', arr1[0])
return
}, 500)
})
2025-10-11 10:35:25 +08:00
})
}
const changePointType = (val: any, obj: any) => {
2026-04-02 09:08:57 +08:00
// emit('pointTypeChange', val, obj)
2025-10-11 10:35:25 +08:00
}
2025-10-17 14:37:31 +08:00
const onAdd = () => {
emit('onAdd')
}
2025-10-11 10:35:25 +08:00
if (props.template) {
2026-01-27 16:32:33 +08:00
querySysExcel({ id: dictData.state.area[0]?.id })
2025-10-11 10:35:25 +08:00
.then((res: any) => {
emit('Policy', res.data)
info()
})
.catch(err => {
info()
})
} else {
info()
}
// 暴露 info 方法给父组件调用
defineExpose({
info
})
onMounted(() => {})
</script>