wangjuncheng
2025-05-19 e98dee8d702092a88610c3e3ae08bbf4a9c4d494
fix change
已修改3个文件
52 ■■■■ 文件已修改
src/components/menu/Device.vue 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/tools/LayerTree.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/map.js 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/menu/Device.vue
@@ -27,26 +27,46 @@
</template>
<script setup>
import { ref, computed, onMounted, watch, onBeforeUnmount, } from "vue";
import { useRoute, onBeforeRouteUpdate } from 'vue-router';
import { createPoint, removeEntities } from "@/utils/map";
import { ref, computed, onMounted, watch } from "vue";
import { deviceDictList, getDictName } from "@/constant/dict.js";
import { getDeviceInfo } from "@/api/hpApi";
import { initeWaterPrimitiveView } from "@/utils/water"; //相机flyTo函数,后续options列表中有对应经纬度后弃用
import { useSimStore } from "@/store/simulation";
const simStore = useSimStore();
const deviceListAll = ref([]);
onMounted(() => {
  loadDeviceList("孙胡沟");
  initeWaterPrimitiveView()
});
onBeforeRouteUpdate((to, from, next) => {
  if (to.path !== '/zhjc') {
    handleCleanup();
  }
  next();
});
const route = useRoute();
onBeforeUnmount(() => {
  if (route.path !== '/zhjc') {
    handleCleanup();
  }
});
watch(() => simStore.DeviceShowSwitch, (newValue, oldValue) => {
  if (newValue) {
    initializeDevicePoints();
  } else {
    removeEntities();
    handleCleanup()
  }
});
const deviceListAll = ref([]);
const deviceEntities = ref([]);
const handleCleanup = () => {
  deviceListAll.value.forEach(item => {
    removeEntities(item.deviceId);
  });
}
const initializeDevicePoints = () => {
  const list = [];
  deviceListAll.value.forEach((item, index) => {
@@ -57,7 +77,7 @@
    item.className = "device";
    item.showLabel = true;
    // 打印每个设备的名称和设备类型
    // console.log(`设备名称: ${item.deviceName}, 设备类型: ${item.dictDeviceType}`);
    console.log(`设备名称: ${item.id}, 设备类型: ${item.name}`);
    createPoint(item);
  });
  deviceEntities.value = list;
@@ -65,13 +85,14 @@
// 根据区域名称加载设备列表
const loadDeviceList = async (areaName) => {
  try {
    handleCleanup()
    const res = await getDeviceInfo();
    const allDevices = res.data.pageData;
    const devicesInArea = allDevices.filter((item) =>
      item.deviceName?.includes(areaName)
    );
    deviceListAll.value = devicesInArea;
    removeEntities();
    deviceListAll.length = 0;
    initializeDevicePoints();
  } catch (error) {
    console.error("加载设备信息失败", error);
@@ -125,12 +146,10 @@
  // 先按设备类型分组
  deviceListAll.value.forEach((device) => {
    const typeName = getDictName(deviceDictList, device.dictDeviceType);
    if (!typeName) {
      console.warn("未找到设备类型:", device);
      return;
    }
    if (!typeMap[typeName]) {
      typeMap[typeName] = [];
    }
src/components/tools/LayerTree.vue
@@ -231,7 +231,7 @@
  } else if (entityList && typeof entityList.show !== "undefined") {
    entityList.show = checked;
  } else {
    // console.error(`无法设置图层 ${name} 的可见性`);
    console.error(`无法设置图层 ${name} 的可见性`);
  }
}
src/utils/map.js
@@ -156,12 +156,19 @@
  return entity;
}
export function removeEntities() {
  entities.forEach(entity => {
    viewer.entities.remove(entity)
    entity.show = false;
// export function removeEntities() {
//   entities.forEach(entity => {
//     viewer.entities.remove(entity)
//     entity.show = false;
//   });
//   // entities = []
// }
export function removeEntities(id) {
  entities.forEach((entity, index) => {
    if (entity.id === id) {
      viewer.entities.remove(entity);
    }
  });
  // entities = []
}
function removeHandler() {
  if (interativeHandler != null && Cesium.defined(interativeHandler)) {