<template>
|
<div class="device">
|
<div class="left-top">
|
<span>监测设备</span>
|
</div>
|
<div class="left-content device-content">
|
<div style="margin-left: 5px">
|
<span style="color: white">重点沟:</span>
|
<el-select
|
@change="handleChange"
|
v-model="selectValue"
|
placeholder="Select"
|
size="large"
|
style="width: 240px"
|
>
|
<el-option
|
v-for="item in options"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</div>
|
<el-tree
|
:data="deviceTree"
|
node-key="deviceId"
|
:props="treeProps"
|
@node-click="handleTreeNodeClick"
|
class="device-tree"
|
>
|
<template #default="{ node, data }">
|
<span v-if="!data.children" class="device-tree-item">
|
<!-- <div class="device-item-icon"></div> -->
|
<span class="device-item-text">{{ node.label }}</span>
|
</span>
|
<span v-else class="device-tree-category">
|
{{ node.label }} ({{ data.children.length }})
|
</span>
|
</template>
|
</el-tree>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, computed, onMounted } from "vue";
|
import { createPoint, removeEntities } from "@/utils/map";
|
import { deviceDictList, getDictName } from "@/constant/dict.js";
|
import { getDeviceInfo } from "@/api/hpApi";
|
|
// 定义一个响应式引用存储设备列表
|
const deviceListAll = ref([]);
|
|
// 组件挂载时获取设备信息,默认过滤“孙胡沟”
|
onMounted(() => {
|
loadDeviceList("孙胡沟");
|
});
|
|
// 根据区域名称加载设备列表
|
const loadDeviceList = async (areaName) => {
|
try {
|
const res = await getDeviceInfo(); // 调整getDeviceInfo以接受动态参数,如果需要的话
|
deviceListAll.value = res.data.pageData.filter((item) =>
|
item.deviceName?.includes(areaName)
|
);
|
} catch (error) {
|
console.error("加载设备信息失败", error);
|
}
|
};
|
|
// 处理区域变化事件
|
const handleChange = (item) => {
|
if (!item) {
|
ElMessage("请选择一个区域");
|
return;
|
}
|
// 根据新区域名重新加载设备列表
|
loadDeviceList(item);
|
console.log(deviceListAll.value);
|
};
|
|
const selectValue = ref("孙胡沟");
|
|
const options = ref([
|
{
|
value: "孙胡沟",
|
label: "孙胡沟",
|
},
|
{
|
value: "鱼水洞后沟",
|
label: "鱼水洞后沟",
|
},
|
{
|
value: "于家西沟",
|
label: "于家西沟",
|
},
|
{
|
value: "北河沟",
|
label: "北河沟",
|
},
|
{
|
value: "龙泉峪村",
|
label: "龙泉峪村",
|
},
|
]);
|
|
const treeProps = {
|
label: "deviceName",
|
children: "children",
|
};
|
|
// 计算属性:将设备列表转换为树形结构
|
const deviceTree = computed(() => {
|
const typeMap = {};
|
|
// 先按设备类型分组
|
deviceListAll.value.forEach((device) => {
|
const typeName = getDictName(deviceDictList, device.dictDeviceType);
|
|
if (!typeName) {
|
console.warn("未找到设备类型:", device);
|
return;
|
}
|
|
if (!typeMap[typeName]) {
|
typeMap[typeName] = [];
|
}
|
// 直接使用原始的设备名称,不进行任何替换操作
|
typeMap[typeName].push({
|
...device,
|
deviceName: device.deviceName.trim(), // 只去除首尾空格
|
});
|
});
|
|
// 转换为树形结构
|
return Object.keys(typeMap).map((typeName) => ({
|
deviceName: typeName,
|
children: typeMap[typeName],
|
}));
|
});
|
function handleTreeNodeClick(data) {
|
// 只有设备节点才处理点击事件
|
if (!data.children) {
|
const entity = viewer.entities.getById(data.deviceId);
|
if (entity) {
|
viewer.flyTo(entity, {
|
offset: {
|
heading: Cesium.Math.toRadians(0),
|
pitch: Cesium.Math.toRadians(-45),
|
range: 5000,
|
},
|
});
|
}
|
}
|
}
|
</script>
|
|
<style lang="less" scoped>
|
.device {
|
position: absolute;
|
width: 345px;
|
top: 100px;
|
left: 30px;
|
bottom: 55px;
|
z-index: 99;
|
}
|
|
.device-content {
|
padding: 10px;
|
box-sizing: border-box;
|
overflow-y: auto;
|
height: calc(100% - 70px);
|
}
|
|
.device-tree {
|
height: calc(100% - 50px);
|
background: transparent;
|
color: white;
|
margin-top: 10px;
|
width: 100%;
|
overflow-x: auto;
|
|
:deep(.el-tree-node__content) {
|
height: 30px;
|
margin: 5px 0;
|
}
|
|
:deep(.el-tree-node__expand-icon) {
|
color: white;
|
}
|
|
:deep(.el-tree-node:focus > .el-tree-node__content) {
|
background-color: rgba(38, 124, 124, 0.3);
|
}
|
}
|
|
.device-tree-item {
|
display: flex;
|
align-items: center;
|
cursor: pointer;
|
}
|
|
.device-tree-category {
|
font-weight: bold;
|
color: #fff;
|
}
|
|
.device-item-icon {
|
background: url("@/assets/img/menu/locationicon.png") no-repeat;
|
background-position: 5px 5px;
|
width: 30px;
|
height: 30px;
|
margin-right: 5px;
|
}
|
|
.device-item-text {
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
|
// 保持原有的选择器样式
|
:deep(.el-select__placeholder) {
|
color: white;
|
}
|
:deep(.el-select-dropdown__item.hover),
|
:deep(.el-select-dropdown__item:hover) {
|
color: white !important;
|
background-color: rgb(38, 124, 124, 0.5);
|
}
|
:deep(.el-tree-node__content) {
|
padding-left: 0px !important ;
|
}
|
</style>
|