guonan
2025-06-06 cf4ed06dea0076e518319de24c5120bb3fe0dae9
src/components/menu/Device.vue
@@ -74,7 +74,7 @@
import { useRoute, onBeforeRouteUpdate } from "vue-router";
import { createPoint, removeEntities } from "@/utils/map";
import { deviceDictList, getDictName } from "@/constant/dict.js";
import { getDeviceInfo } from "@/api/hpApi";
import { getDeviceInfoShg, getDeviceInfo } from "@/api/hpApi";
import { initeWaterPrimitiveView } from "@/utils/water"; //相机flyTo函数,后续options列表中有对应经纬度后弃用
import { useSimStore } from "@/store/simulation";
import { Loading } from "@element-plus/icons-vue";
@@ -87,7 +87,7 @@
  try {
    await getData();
    await loadDeviceList(selectValue.value);
    initeWaterPrimitiveView();
    // initeWaterPrimitiveView();
  } finally {
    isLoading.value = false;
  }
@@ -124,9 +124,9 @@
    removeEntities(item.deviceId);
  });
};
const initializeDevicePoints = () => {
const initializeDevicePoints = (val) => {
  const list = [];
  deviceListAll.value.forEach((item, index) => {
  val.forEach((item, index) => {
    // 根据需求可增删
    item.type = getDictName(deviceDictList, item.dictDeviceType);
    item.name = item.deviceName.split(selectValue.value)[1] || item.deviceName;
@@ -141,7 +141,7 @@
};
const allDevices = ref([]);
const getData = async () => {
  const res = await getDeviceInfo();
  const res = await getDeviceInfoShg();
  allDevices.value = res.data.pageData;
};
// 根据区域名称加载设备列表
@@ -149,14 +149,38 @@
  try {
    isLoading.value = true;
    handleCleanup();
    // const res = await getDeviceInfo();
    // const res = await getDeviceInfoShg();
    // const allDevices = res.data.pageData;
    const devicesInArea = allDevices.value.filter((item) =>
      item.deviceName?.includes(areaName)
    );
    deviceListAll.value = devicesInArea;
    deviceListAll.length = 0;
    initializeDevicePoints();
    // deviceListAll.value = devicesInArea;
    getDeviceInfo().then((res) => {
      const list = res.data.pageData;
      deviceListAll.value = [];
      let index = 0;
      const batchSize = 50; // 每次处理的数量
      const delay = 100; // 每隔多少毫秒处理一次
      const intervalId = setInterval(() => {
        // 取出当前批次的数据
        const batch = list.slice(index, index + batchSize);
        if (batch.length === 0) {
          clearInterval(intervalId); // 数据处理完了,停止定时器
          return;
        }
        // 把当前批次的数据 push 到 deviceListAll
        deviceListAll.value = [...deviceListAll.value, ...batch];
        // 对当前批次执行初始化方法
        initializeDevicePoints(batch);
        index += batchSize;
      }, delay);
    });
  } catch (error) {
    console.error("加载设备信息失败", error);
  } finally {