wangjuncheng
2025-05-19 d72bfc760302c524622e4484ad5175d03ca45ce7
change
已添加1个文件
已修改6个文件
261 ■■■■ 文件已修改
public/images/poi/雨量计1.png 补丁 | 查看 | 原始文档 | blame | 历史
src/components/menu/Device.vue 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/menu/Location.vue 161 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/tools/LayerTree.vue 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/constant/dict.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/simulation.js 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/map.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
public/images/poi/ÓêÁ¿¼Æ1.png
src/components/menu/Device.vue
@@ -6,28 +6,12 @@
    <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> -->
@@ -43,30 +27,56 @@
</template>
<script setup>
import { ref, computed, onMounted } from "vue";
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()
});
watch(() => simStore.DeviceShowSwitch, (newValue, oldValue) => {
  if (newValue) {
    initializeDevicePoints();
  } else {
    removeEntities();
  }
});
const deviceEntities = ref([]);
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.deviceName}, è®¾å¤‡ç±»åž‹: ${item.dictDeviceType}`);
    createPoint(item);
  });
  deviceEntities.value = list;
};
// æ ¹æ®åŒºåŸŸåç§°åŠ è½½è®¾å¤‡åˆ—è¡¨
const loadDeviceList = async (areaName) => {
  try {
    const res = await getDeviceInfo(); // è°ƒæ•´getDeviceInfo以接受动态参数,如果需要的话
    deviceListAll.value = res.data.pageData.filter((item) =>
    const res = await getDeviceInfo();
    const allDevices = res.data.pageData;
    const devicesInArea = allDevices.filter((item) =>
      item.deviceName?.includes(areaName)
    );
    deviceListAll.value = devicesInArea;
    removeEntities();
    initializeDevicePoints();
  } catch (error) {
    console.error("加载设备信息失败", error);
  }
};
// å¤„理区域变化事件
const handleChange = (item) => {
  if (!item) {
@@ -75,7 +85,7 @@
  }
  // æ ¹æ®æ–°åŒºåŸŸåé‡æ–°åŠ è½½è®¾å¤‡åˆ—è¡¨
  loadDeviceList(item);
  console.log(deviceListAll.value);
  // console.log(deviceListAll.value);
};
const selectValue = ref("孙胡沟");
@@ -222,12 +232,14 @@
: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
@@ -7,19 +7,8 @@
    <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 @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>
@@ -29,13 +18,7 @@
        <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 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>
@@ -45,99 +28,78 @@
</template>
<script setup>
import { ref, onMounted, watch } from "vue";
import { createPoint } from "@/utils/map";
import { useSimStore } from "@/store/simulation";
import { ref, computed, onMounted } from "vue";
import { deviceDictList, getDictName } from "@/constant/dict.js";
const simStore = useSimStore();
// å®šä¹‰ä¸€ä¸ªå“åº”式引用存储设备列表
const deviceListAll = ref([]);
// å½“前选中的区域
const selectValue = ref("孙胡沟");
// åŒºåŸŸé€‰é¡¹
const options = ref([
  {
    value: "孙胡沟",
    label: "孙胡沟",
  },
  {
    value: "鱼水洞后沟",
    label: "鱼水洞后沟",
  },
  {
    value: "于家西沟",
    label: "于家西沟",
  },
  {
    value: "北河沟",
    label: "北河沟",
  },
  {
    value: "龙泉峪村",
    label: "龙泉峪村",
  },
  { value: "孙胡沟", label: "孙胡沟" },
  { value: "鱼水洞后沟", label: "鱼水洞后沟" },
  // å…¶ä»–选项...
]);
const districtList = ref([]);
const loading = ref(true); // æŽ§åˆ¶åŠ è½½çŠ¶æ€
function handleClick(district) {
  const entity = viewer.entities.getById(district.hdId);
  if (entity) {
    viewer.flyTo(entity, {
      offset: {
        heading: Cesium.Math.toRadians(0),
        pitch: Cesium.Math.toRadians(-45),
        range: 4000,
      },
    });
  }
}
// æ ¹æ®åŒºåŸŸåç§°è¿‡æ»¤æ•°æ®
const filterDataByArea = (areaName) => {
  if (!areaName || !simStore.DangerPoint || simStore.DangerPoint.length === 0) {
    districtList.value = [];
    return;
  }
  districtList.value = simStore.DangerPoint.filter((item) =>
    item.position?.includes(areaName)
  );
// æ ‘形结构属性配置
const treeProps = {
  label: "deviceName",
  children: "children",
};
// å¤„理区域变化事件
const handleChange = (item) => {
  const areaName = item;
const handleChange = (areaName) => {
  if (!areaName) {
    ElMessage.warning("请选择一个区域");
    console.error("请选择一个区域");
    return;
  }
  filterDataByArea(areaName);
  selectValue.value = areaName; // æ›´æ–°é€‰ä¸­çš„区域值
  console.log(deviceListAll.value); // è¿™é‡Œå·²åŒ…含所有区域的数据
};
// ç›‘听 simStore.DangerPoint å˜åŒ–
watch(
  () => simStore.DangerPoint,
  (newVal) => {
    if (newVal && newVal.length > 0) {
      filterDataByArea(selectValue.value);
      loading.value = false; // æ•°æ®åŠ è½½å®Œæˆ
    } else {
      districtList.value = [];
      loading.value = true; // æ•°æ®æœªå‡†å¤‡å°±ç»ª
    }
  },
  { immediate: true }
);
// è®¡ç®—属性:将设备列表转换为树形结构,依据当前选中的区域
const deviceTree = computed(() => {
  const typeMap = {};
  // è¿‡æ»¤å‡ºå±žäºŽå½“前选中区域的设备
  const filteredDevices = deviceListAll.value.filter(device =>
    device.deviceName.includes(selectValue.value)
  );
  // æŒ‰è®¾å¤‡ç±»åž‹åˆ†ç»„
  filteredDevices.forEach((device) => {
    const typeName = getDictName(deviceDictList, device.dictDeviceType);
    if (!typeName) {
      console.warn("未找到设备类型:", device);
      return;
    }
    if (!typeMap[typeName]) {
      typeMap[typeName] = [];
    }
    // ç›´æŽ¥ä½¿ç”¨åŽŸå§‹çš„è®¾å¤‡åç§°ï¼Œä¸è¿›è¡Œä»»ä½•æ›¿æ¢æ“ä½œ
    typeMap[typeName].push({
      ...device,
      deviceName: device.deviceName.trim(), // åªåŽ»é™¤é¦–å°¾ç©ºæ ¼
    });
  });
  // è½¬æ¢ä¸ºæ ‘形结构
  return Object.keys(typeMap).map((typeName) => ({
    deviceName: typeName,
    children: typeMap[typeName],
  }));
});
// å‡è®¾åœ¨ç»„件初始化之前,deviceListAll å·²è¢«å¡«å……了所有区域的数据
// å¦‚果不是这样,则需要保留对 loadDeviceList çš„调用,或者找到一种方法来预填充 deviceListAll
onMounted(() => {
  // é»˜è®¤å…ˆæ£€æŸ¥ä¸€éæ•°æ®
  if (simStore.DangerPoint && simStore.DangerPoint.length > 0) {
    filterDataByArea("孙胡沟");
    loading.value = false;
  } else {
    loading.value = true;
  }
  // å¦‚果需要在此处加载全部数据,请取消注释以下行并确保 getDeviceInfo è¿”回所有区域的数据
  // loadDeviceList("");
});
</script>
@@ -148,7 +110,8 @@
  left: 0px;
  right: 0px;
  bottom: 10px;
  background-color: rgba(236, 233, 233, 0.5); /* åŠé€æ˜Žé®ç½© */
  background-color: rgba(236, 233, 233, 0.5);
  /* åŠé€æ˜Žé®ç½© */
  display: flex;
  align-items: center;
  justify-content: center;
@@ -169,6 +132,7 @@
    transform: rotate(360deg);
  }
}
.district {
  position: absolute;
  width: 345px;
@@ -183,10 +147,12 @@
  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;
@@ -213,6 +179,7 @@
/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,6 +184,18 @@
    }
    return;
  }
  if (label === "综合监测设备信息") {
    simStore.DeviceShowSwitch = checked;
    if (checked) {
    if (!treeMap.get("综合监测设备信息")) {
    } else {
      toggleLayerVisible("综合监测设备信息", true);
    }
  } else {
    toggleLayerVisible("综合监测设备信息", false);
  }
  return;
}
  // å…¶ä»–图层的处理逻辑
  const list = treeMap.get(label);
@@ -219,7 +231,7 @@
  } else if (entityList && typeof entityList.show !== "undefined") {
    entityList.show = checked;
  } else {
    console.error(`无法设置图层 ${name} çš„可见性`);
    // console.error(`无法设置图层 ${name} çš„可见性`);
  }
}
@@ -233,7 +245,7 @@
    item.deviceName?.includes("孙胡沟")
  );
};
// é»˜è®¤åŠ è½½éƒ¨åˆ†å·²æ›¿æ¢è‡³Device.vue中,逻辑修改为根据当前选择地形切换设备点显示
async function initDevicePoint() {
  let list = [];
  await getDevicetList();
@@ -325,7 +337,7 @@
 * åˆå§‹åŒ–所有数据
 */
function getData() {
  initDevicePoint();
  // initDevicePoint();
  // initDistrictPoint();
  initDuanmianPoint();
  addTetrahedron();
src/constant/dict.js
@@ -8,6 +8,10 @@
        value: "1874719366287368194",
    },
    {
        label: "雨量计1",
        value: "1437295810",
    },
    {
        label: "摄像头",
        value: "1437295825",
    },
src/store/simulation.js
@@ -5,6 +5,7 @@
export const useSimStore = defineStore('simulation', () => {
    // é𐿂£ç‚¹åˆ—表
    const DeviceShowSwitch = ref(true)
    const DangerPoint = ref([])
    const navigationShow = ref(true)
    const leftShow = ref(false)
@@ -147,6 +148,7 @@
        backToHome,
        rainFalls,
        DangerPoint,
        DeviceShowSwitch,
        // æ–¹æ¡ˆç›¸å…³æ–¹æ³•
        setSchemCard,
src/utils/map.js
@@ -158,7 +158,7 @@
}
export function removeEntities() {
  entities.forEach(entity => {
    // viewer.entities.remove(entity)
    viewer.entities.remove(entity)
    entity.show = false;
  });
  // entities = []