guonan
2025-05-20 a0967df707a547428df9fc80256877c26e061c4a
还原目录树功能
已修改3个文件
312 ■■■■■ 文件已修改
src/components/menu/Device.vue 97 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/menu/Location.vue 141 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/tools/LayerTree.vue 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/menu/Device.vue
@@ -6,12 +6,28 @@
    <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
          @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">
      <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> -->
@@ -27,77 +43,30 @@
</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 } 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 {
    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) => {
    // 根据需求可增删
    item.type = getDictName(deviceDictList, item.dictDeviceType);
    item.name = item.deviceName.split(selectValue.value)[1] || item.deviceName;
    item.id = item.deviceId;
    item.className = "device";
    item.showLabel = true;
    // 打印每个设备的名称和设备类型
    // console.log(`设备名称: ${item.id}, 设备类型: ${item.name}`);
    createPoint(item);
  });
  deviceEntities.value = list;
};
// 根据区域名称加载设备列表
const loadDeviceList = async (areaName) => {
  try {
    handleCleanup()
    const res = await getDeviceInfo();
    const allDevices = res.data.pageData;
    const devicesInArea = allDevices.filter((item) =>
    const res = await getDeviceInfo(); // 调整getDeviceInfo以接受动态参数,如果需要的话
    deviceListAll.value = res.data.pageData.filter((item) =>
      item.deviceName?.includes(areaName)
    );
    deviceListAll.value = devicesInArea;
    deviceListAll.length = 0;
    initializeDevicePoints();
  } catch (error) {
    console.error("加载设备信息失败", error);
  }
};
// 处理区域变化事件
const handleChange = (item) => {
  if (!item) {
@@ -106,7 +75,7 @@
  }
  // 根据新区域名重新加载设备列表
  loadDeviceList(item);
  // console.log(deviceListAll.value);
  console.log(deviceListAll.value);
};
const selectValue = ref("孙胡沟");
@@ -146,10 +115,12 @@
  // 先按设备类型分组
  deviceListAll.value.forEach((device) => {
    const typeName = getDictName(deviceDictList, device.dictDeviceType);
    if (!typeName) {
      console.warn("未找到设备类型:", device);
      return;
    }
    if (!typeMap[typeName]) {
      typeMap[typeName] = [];
    }
@@ -251,14 +222,12 @@
: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;
  padding-left: 0px !important ;
}
</style>
src/components/menu/Location.vue
@@ -1,53 +1,57 @@
  <template>
    <div class="district">
      <div class="left-top">
        <span>监测位置</span>
<template>
  <div class="district">
    <div class="left-top">
      <span>监测位置</span>
    </div>
    <div class="left-content district-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>
      <div class="left-content district-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 style="overflow-y: auto; height: 95%">
        <!-- 加载遮罩层 -->
        <div v-if="loading" class="loading-overlay">
          <div class="spinner"></div>
        </div>
        <!-- 滚动区域 -->
        <div style="overflow-y: auto; height: 95%">
          <!-- 加载遮罩层 -->
          <div v-if="loading" class="loading-overlay">
            <div class="spinner"></div>
          </div>
          <div v-else v-for="(item, key) in districtList" :key="key" class="district-item" @click="handleClick(item)">
            <div class="district-item-icon"></div>
            <div class="district-item-text">{{ item.hdName }}</div>
          </div>
        <div
          v-else
          v-for="(item, key) in districtList"
          :key="key"
          class="district-item"
          @click="handleClick(item)"
        >
          <div class="district-item-icon"></div>
          <div class="district-item-text">{{ item.hdName }}</div>
        </div>
      </div>
    </div>
  </template>
  </div>
</template>
<script setup>
import { ref, onMounted, watch, onBeforeUnmount } from "vue";
import { createPoint, removeEntities } from "@/utils/map";
import { ref, onMounted, watch } from "vue";
import { createPoint } from "@/utils/map";
import { useSimStore } from "@/store/simulation";
import { initeWaterPrimitiveView } from "@/utils/water"; //相机flyTo函数,后续options列表中有对应经纬度后弃用
import { useRoute, onBeforeRouteUpdate } from 'vue-router';
const simStore = useSimStore();
onBeforeRouteUpdate((to, from, next) => {
  if (to.path !== '/yhgl') {
    handleCleanup();
  }
  next();
});
const route = useRoute();
onBeforeUnmount(() => {
  if (route.path !== '/yhgl') {
    handleCleanup();
  }
});
const simStore = useSimStore();
const selectValue = ref("孙胡沟");
const options = ref([
@@ -88,39 +92,17 @@
    });
  }
}
const handleCleanup = async () => {
  await Promise.all(districtList.value.map(item => removeEntities(item.hdId)));
}
const initializeDevicePoints = async () => {
  await Promise.all(districtList.value.map(async (item, index) => {
    // 根据需求可增删
    item.id = item.hdId;
    item.name = item.hdName;
    item.latitude = item.lat;
    item.longitude = item.lon;
    item.showBillboard = true;
    item.type = item.disasterType;
    item.className = "district";
    await createPoint(item);
    // 打印每个设备的名称和设备类型
    // console.log(`设备名称: ${item.id}, 设备类型: ${item.name}`);
  }));
};
// 根据区域名称过滤数据
const filterDataByArea = async (areaName) => {
  handleCleanup();
const filterDataByArea = (areaName) => {
  if (!areaName || !simStore.DangerPoint || simStore.DangerPoint.length === 0) {
    districtList.value = [];
    return;
  }
  const filteredData = simStore.DangerPoint.filter((item) =>
  districtList.value = simStore.DangerPoint.filter((item) =>
    item.position?.includes(areaName)
  );
  if (JSON.stringify(districtList.value) !== JSON.stringify(filteredData)) {
    districtList.value = filteredData;
    await initializeDevicePoints();
  }
};
// 处理区域变化事件
@@ -130,23 +112,10 @@
    ElMessage.warning("请选择一个区域");
    return;
  }
  filterDataByArea(areaName);
};
let isInitialized = false;
watch(() => simStore.DangerShowSwitch, async (newValue, oldValue) => {
  console.log('当前状态:', newValue);
  if (newValue) {
    if (!isInitialized) {
      await initializeDevicePoints();
      isInitialized = true;
    }
  } else {
    handleCleanup();
    isInitialized = false;
  }
});
// 监听 simStore.DangerPoint 变化
watch(
  () => simStore.DangerPoint,
@@ -155,16 +124,15 @@
      filterDataByArea(selectValue.value);
      loading.value = false; // 数据加载完成
    } else {
      handleCleanup();
      districtList.value = [];
      loading.value = true; // 数据未准备就绪
    }
  }
  },
  { immediate: true }
);
onMounted(() => {
  handleCleanup()
  initeWaterPrimitiveView()
  initeWaterPrimitiveView();
  // 默认先检查一遍数据
  if (simStore.DangerPoint && simStore.DangerPoint.length > 0) {
    filterDataByArea("孙胡沟");
@@ -182,8 +150,7 @@
  left: 0px;
  right: 0px;
  bottom: 10px;
  background-color: rgba(236, 233, 233, 0.5);
  /* 半透明遮罩 */
  background-color: rgba(43, 43, 43, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
@@ -204,7 +171,6 @@
    transform: rotate(360deg);
  }
}
.district {
  position: absolute;
  width: 345px;
@@ -219,12 +185,10 @@
  cursor: pointer;
  margin-top: 10px;
}
.district-content {
  padding: 10px;
  box-sizing: border-box;
}
.district-item-icon {
  background: url("@/assets/img/menu/locationicon.png") no-repeat;
  background-position: 5px 5px;
@@ -251,7 +215,6 @@
/deep/ .el-select__placeholder {
  color: white;
}
/deep/ .el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
  color: white !important;
src/components/tools/LayerTree.vue
@@ -184,30 +184,6 @@
    }
    return;
  }
  if (label === "综合监测设备信息") {
    simStore.DeviceShowSwitch = checked;
    if (checked) {
    if (!treeMap.get("综合监测设备信息")) {
    } else {
      toggleLayerVisible("综合监测设备信息", true);
    }
  } else {
    toggleLayerVisible("综合监测设备信息", false);
  }
  return;
}
if (label === "孙胡沟隐患点") {
    simStore.DangerShowSwitch = checked;
    if (checked) {
    if (!treeMap.get("孙胡沟隐患点")) {
    } else {
      toggleLayerVisible("孙胡沟隐患点", true);
    }
  } else {
    toggleLayerVisible("孙胡沟隐患点", false);
  }
  return;
}
  // 其他图层的处理逻辑
  const list = treeMap.get(label);
@@ -243,7 +219,7 @@
  } else if (entityList && typeof entityList.show !== "undefined") {
    entityList.show = checked;
  } else {
    // console.error(`无法设置图层 ${name} 的可见性`);
    console.error(`无法设置图层 ${name} 的可见性`);
  }
}
@@ -257,7 +233,7 @@
    item.deviceName?.includes("孙胡沟")
  );
};
// 默认加载部分已替换至Device.vue中,逻辑修改为根据当前选择地形切换设备点显示
async function initDevicePoint() {
  let list = [];
  await getDevicetList();
@@ -276,31 +252,31 @@
}
// 隐患点列表
// watchEffect(() => {
//   const dangerPoints = simStore.DangerPoint.filter((item) =>
//     item.position?.includes("孙胡沟")
//   );
watchEffect(() => {
  const dangerPoints = simStore.DangerPoint.filter((item) =>
    item.position?.includes("孙胡沟")
  );
//   if (dangerPoints && dangerPoints.length > 0) {
//     const list = [];
  if (dangerPoints && dangerPoints.length > 0) {
    const list = [];
//     dangerPoints.forEach((item) => {
//       // console.log(item, "item");
//       item.id = item.hdId;
//       item.name = item.hdName;
//       item.latitude = item.lat;
//       item.longitude = item.lon;
//       item.showBillboard = true;
//       item.type = item.disasterType;
//       item.className = "district";
//       const entity = createPoint(item);
//       entity.show = false;
//       list.push(entity);
//     });
    dangerPoints.forEach((item) => {
      // console.log(item, "item");
      item.id = item.hdId;
      item.name = item.hdName;
      item.latitude = item.lat;
      item.longitude = item.lon;
      item.showBillboard = true;
      item.type = item.disasterType;
      item.className = "district";
      const entity = createPoint(item);
      entity.show = false;
      list.push(entity);
    });
//     treeMap.set("孙胡沟隐患点", list);
//   }
// });
    treeMap.set("孙胡沟隐患点", list);
  }
});
let divPointList = [];
/**
@@ -349,7 +325,7 @@
 * 初始化所有数据
 */
function getData() {
  // initDevicePoint();
  initDevicePoint();
  // initDistrictPoint();
  initDuanmianPoint();
  addTetrahedron();