Files
admin-sjzx/src/components/tree/pqs/pointTree.vue

155 lines
6.0 KiB
Vue
Raw Normal View History

2024-02-21 16:41:40 +08:00
<template>
<div class="point-tree">
<el-select
v-model="formData.statisticalType"
placeholder="请选择"
style="min-width: unset; padding: 10px 10px 0"
@change="loadData"
v-if="props.showSelect"
>
<el-option
v-for="item in classificationData"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
2024-02-21 16:41:40 +08:00
</el-select>
<div style="flex: 1; overflow: hidden">
2024-02-29 10:31:32 +08:00
<Tree ref="treeRef" :data="tree" style="width: 100%; height: 100%" :canExpand="false" v-bind="$attrs" />
2024-02-21 16:41:40 +08:00
</div>
</div>
</template>
<script lang="ts" setup>
2024-02-26 10:43:33 +08:00
import { nextTick, onMounted, ref, useAttrs } from 'vue'
2024-02-21 16:41:40 +08:00
import Tree from '../index.vue'
import { useAdminInfo } from '@/stores/adminInfo'
import { useDictData } from '@/stores/dictData'
import { getTerminalTreeForFive } from '@/api/device-boot/terminalTree'
import { useConfig } from '@/stores/config'
2025-01-15 10:44:57 +08:00
import { defineProps } from 'vue'
2024-02-21 16:41:40 +08:00
defineOptions({
name: 'pms/pointTree'
2025-01-15 10:44:57 +08:00
})
interface Props {
showSelect?: boolean
}
const props = withDefaults(defineProps<Props>(), {
showSelect: true
2024-02-21 16:41:40 +08:00
})
const emit = defineEmits(['init'])
2024-02-26 10:43:33 +08:00
const attrs = useAttrs()
2024-02-21 16:41:40 +08:00
const adminInfo = useAdminInfo()
const dictData = useDictData()
const config = useConfig()
const classificationData = dictData.getBasicData('Statistical_Type', ['Report_Type'])
const tree = ref()
2024-02-29 10:31:32 +08:00
const treeRef = ref()
2024-02-21 16:41:40 +08:00
const formData = ref({
deptIndex: adminInfo.$state.deptIndex,
monitorFlag: 2,
powerFlag: 2,
loadType: null,
manufacturer: null,
serverName: 'event-boot',
2024-11-21 11:36:36 +08:00
statisticalType: classificationData[0].id,
2024-02-21 16:41:40 +08:00
scale: null
})
2024-02-29 10:31:32 +08:00
const loadData = () => {
2024-02-29 09:37:03 +08:00
let obj = classificationData.find(function (i) {
return i.id === formData.value.statisticalType
2024-02-29 10:31:32 +08:00
}) || { code: '' }
2024-02-21 16:41:40 +08:00
let form = JSON.parse(JSON.stringify(formData.value))
form.statisticalType = classificationData.find((item: any) => item.id == form.statisticalType)
2024-02-26 10:43:33 +08:00
let nodeKey = ''
2024-02-21 16:41:40 +08:00
getTerminalTreeForFive(form).then(res => {
2025-07-28 13:24:01 +08:00
//console.log('---',res)
2024-02-29 09:37:03 +08:00
if (obj.code == 'Power_Network') {
res.data = [
{
name: '电网拓扑',
level: -1,
id: 0,
children: res.data
}
]
}
2024-02-21 16:41:40 +08:00
res.data.forEach((item: any) => {
item.icon = 'el-icon-HomeFilled'
2024-02-21 16:41:40 +08:00
item.color = config.getColorVal('elementUiPrimary')
item.children.forEach((item2: any) => {
item2.icon = 'el-icon-CollectionTag'
2025-07-10 16:32:49 +08:00
item2.color = config.getColorVal('elementUiPrimary')
2024-02-21 16:41:40 +08:00
item2.children.forEach((item3: any) => {
item3.icon = 'el-icon-Flag'
2024-02-21 16:41:40 +08:00
item3.color = config.getColorVal('elementUiPrimary')
item3.children.forEach((item4: any) => {
item4.icon = 'el-icon-OfficeBuilding'
2024-02-21 16:41:40 +08:00
item4.color = config.getColorVal('elementUiPrimary')
2024-02-26 10:43:33 +08:00
item4.children.forEach((item5: anyObj) => {
if (item5.level == 7) {
2025-04-09 10:41:56 +08:00
item5.icon = 'el-icon-DataAnalysis'
item5.color = config.getColorVal('elementUiPrimary')
item5.children.forEach((item6: anyObj) => {
item6.alias = `${item.name}>${item2.name}>${item3.name}>${item4.name}>${item5.name}>${item6.name}`
item6.pid = item4.id
item6.icon = 'fa-solid fa-location-dot'
item6.color = config.getColorVal('elementUiPrimary')
if (item6.comFlag == 0) {
item6.color = 'red !important'
} else if (item6.comFlag == 1) {
item6.color = '#00f93b !important'
} else if (item6.comFlag == 2) {
item6.color = '#8c8c8c !important'
}
})
} else {
item5.alias = `${item.name}>${item2.name}>${item3.name}>${item4.name}>${item5.name}`
item5.pid = item4.id
item5.icon = 'fa-solid fa-location-dot'
item5.color = config.getColorVal('elementUiPrimary')
if (item5.comFlag == 0) {
item5.color = 'red !important'
} else if (item5.comFlag == 1) {
item5.color = '#00f93b !important'
} else if (item5.comFlag == 2) {
item5.color = '#8c8c8c !important'
}
2024-02-21 16:41:40 +08:00
}
})
})
})
})
})
2025-04-09 10:41:56 +08:00
nodeKey =
res.data[0].children[0].children[0].children[0].children[0].children[0]?.id ||
res.data[0].children[0].children[0].children[0].children[0]?.id
emit(
'init',
res.data[0].children[0].children[0].children[0].children[0]?.children[0] ||
res.data[0].children[0].children[0].children[0].children[0]
)
2024-02-21 16:41:40 +08:00
tree.value = res.data
2024-02-26 10:43:33 +08:00
if (nodeKey) {
nextTick(() => {
2024-02-29 10:31:32 +08:00
treeRef.value.treeRef.setCurrentKey(nodeKey)
2024-02-29 10:50:14 +08:00
// treeRef.value.treeRef.setExpandedKeys(nodeKey)
2024-02-26 10:43:33 +08:00
})
}
2024-02-21 16:41:40 +08:00
})
}
loadData()
</script>
<style lang="scss">
.point-tree {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
background: #fff;
border: 1px solid var(--el-border-color);
}
</style>