guonan
2025-06-10 2280e8be717608bb36c3cf921f129db24349396d
src/components/menu/Device.vue
@@ -85,8 +85,9 @@
onMounted(async () => {
  try {
    await getData();
    await loadDeviceList(selectValue.value);
    if (simStore.devices && simStore.devices.length > 0) {
      await loadDeviceList(selectValue.value);
    }
    // initeWaterPrimitiveView();
  } finally {
    isLoading.value = false;
@@ -106,21 +107,20 @@
    clearAllPoints();
  }
});
watch(
  () => simStore.DeviceShowSwitch,
  (newValue, oldValue) => {
    if (newValue) {
      initializeDevicePoints();
    } else {
      clearAllPoints();
    }
  }
);
// watch(
//   () => simStore.DeviceShowSwitch,
//   (newValue, oldValue) => {
//     if (newValue) {
//       initializeDevicePoints();
//     } else {
//       clearAllPoints();
//     }
//   }
// );
const deviceListAll = ref([]);
const deviceEntities = ref([]);
// const initializeDevicePoints = (val) => {
const initializeDevicePoints = () => {
  const list = [];
  // val.forEach((item, index) => {
@@ -135,57 +135,38 @@
    // console.log(`设备名称: ${item.id}, 设备类型: ${item.name}`);
    createPoint(item);
  });
  deviceEntities.value = list;
};
const allDevices = ref([]);
const getData = async () => {
  const res = await getDeviceInfoShg();
  allDevices.value = res.data.pageData;
};
// 根据区域名称加载设备列表
const loadDeviceList = async (areaName) => {
  try {
    clearAllPoints();
    isLoading.value = true;
    // const res = await getDeviceInfoShg();
    // const allDevices = res.data.pageData;
    deviceListAll.value = allDevices.value.filter((item) =>
    deviceListAll.value = simStore.devices.filter((item) =>
      item.deviceName?.includes(areaName)
    );
    initializeDevicePoints();
    // 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);
    // });
    await initializeDevicePoints();
  } catch (error) {
    console.error("加载设备信息失败", error);
  } finally {
    isLoading.value = false;
  }
};
// 监听 simStore.devices 变化
watch(
  () => simStore.devices,
  (newVal) => {
    if (newVal && newVal.length > 0) {
      loadDeviceList(selectValue.value);
    } else {
      clearAllPoints();
      deviceListAll.value = [];
    }
  }
);
// 处理区域变化事件
const handleChange = (item) => {
@@ -195,6 +176,8 @@
  }
  // 根据新区域名重新加载设备列表
  loadDeviceList(item);
  initializeDevicePoints();
  // console.log(deviceListAll.value);
};
@@ -246,6 +229,7 @@
});
function handleTreeNodeClick(data) {
  initializeDevicePoints();
  // 只有设备节点才处理点击事件
  if (!data.children) {
    const entity = viewer.entities.getById(data.deviceId);