guonan
2025-07-09 d8134b8a3c3e0b481bf447e5e8b0c022a3996d8f
优化目录树以及实时模拟最后弹窗的问题
已修改2个文件
91 ■■■■ 文件已修改
src/components/menu/TimeLine.vue 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/tools/LayerTree.vue 80 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/menu/TimeLine.vue
@@ -340,8 +340,9 @@
      }
      // 触发进度更新
      const progress = currentTime.value / totalDuration;
      emit("timeUpdate", progress * 100);
      // const progress = currentTime.value / totalDuration;
      // 实时模拟应该不用显示弹窗吧
      // emit("timeUpdate", progress * 100);
      // 如果需要触发某些更新函数,也可以保留
      updateWaterColorByTime();
@@ -1076,7 +1077,11 @@
watch(
  () => finishPlay.value,
  (newVal) => {
    if (newVal && selectedScheme.value.type === 2) {
    if (
      newVal &&
      selectedScheme.value.type === 2 &&
      simStore.rePlayList.length > 0
    ) {
      handlePlayFinished();
    }
  }
src/components/tools/LayerTree.vue
@@ -239,22 +239,61 @@
 * 清除图层实体
 * @param {String} layerName - 图层名称
 */
function clearLayerEntities(layerName) {
// 暂且保留
// async function clearLayerEntities(layerName) {
//   const list = treeMap.get(layerName);
//   if (list && Array.isArray(list)) {
//     for (const item of list) {
//       const entity = await item;
//       if (layerName == "综合监测设备信息") {
//         removeEntities(entity.deviceId);
//       } else if (layerName == "孙胡沟隐患点") {
//         removeEntities(entity.hdId);
//       }
//     }
//   }
//   treeMap.delete(layerName);
// }
/**
 * 清除图层实体
 * @param {String} layerName - 图层名称
 */
// 此函数优化了在模拟仿真页面,如果点击目录树选中取消,泥位计仍显示
async function clearLayerEntities(layerName) {
  const isMnfzPage = route.path === "/mnfz"; // 判断是否为 /mnfz 页面
  const list = treeMap.get(layerName);
  if (list && Array.isArray(list)) {
    list.forEach((entity) => {
      clearAllPoints();
    });
    for (const item of list) {
      const entity = await item;
      let shouldRemove = true; // 默认要删除
      // 如果是 /mnfz 页面,并且是“泥位计”,则不删除
      if (isMnfzPage && entity.type === "泥位计") {
        shouldRemove = false;
      }
      if (shouldRemove) {
        if (layerName === "综合监测设备信息") {
          removeEntities(entity.deviceId);
        } else if (layerName === "孙胡沟隐患点") {
          removeEntities(entity.hdId);
        }
      }
    }
  }
  treeMap.delete(layerName);
}
// 监控设备开关变化
watchEffect(() => {
watchEffect(async () => {
  clearLayerEntities("综合监测设备信息");
  if (simStore.DeviceShowSwitch) {
    const deviceList = simStore.devices
    // 使用 Promise.all 等待所有异步操作完成
    const deviceListPromises = simStore.devices
      .filter((item) => item.deviceName?.includes("孙胡沟"))
      .map(async (item) => {
        const entity = viewer.entities.getById(item.deviceId);
@@ -263,8 +302,12 @@
        item.id = item.deviceId;
        item.className = "device";
        item.showLabel = true;
        await createPoint(item);
        await createPoint(item); // 确保 createPoint 返回一个 Promise 或者本身就是异步函数
        return item; // 返回处理后的 item
      });
    // 等待所有异步操作完成
    const deviceList = await Promise.all(deviceListPromises);
    if (deviceList.length) {
      treeMap.set("综合监测设备信息", deviceList);
@@ -273,13 +316,15 @@
});
// 监控隐患点开关变化
watchEffect(() => {
watchEffect(async () => {
  clearLayerEntities("孙胡沟隐患点");
  if (simStore.DangerShowSwitch) {
    const dangerPoints = simStore.DangerPoint.filter((item) =>
    const filteredPoints = simStore.DangerPoint.filter((item) =>
      item.position?.includes("孙胡沟")
    ).map(async (item) => {
    );
    const dangerPointPromises = filteredPoints.map(async (item) => {
      const entity = viewer.entities.getById(item.hdId);
      item.id = item.hdId;
      item.name = item.hdName;
@@ -288,11 +333,18 @@
      item.showBillboard = true;
      item.type = item.disasterType;
      item.className = "district";
      await createPoint(item);
      await createPoint(item); // 确保 createPoint 是异步函数
      return item; // 返回处理好的 item
    });
    if (dangerPoints.length) {
      treeMap.set("孙胡沟隐患点", dangerPoints);
    try {
      const resolvedPoints = await Promise.all(dangerPointPromises);
      if (resolvedPoints.length) {
        treeMap.set("孙胡沟隐患点", resolvedPoints);
      }
    } catch (error) {
      console.error("创建隐患点时发生错误:", error);
    }
  }
});