From d72bfc760302c524622e4484ad5175d03ca45ce7 Mon Sep 17 00:00:00 2001
From: wangjuncheng <1>
Date: 星期一, 19 五月 2025 12:08:24 +0800
Subject: [PATCH] change

---
 src/components/menu/Location.vue |  161 +++++++++++++++++++++--------------------------------
 1 files changed, 64 insertions(+), 97 deletions(-)

diff --git a/src/components/menu/Location.vue b/src/components/menu/Location.vue
index c239e71..61144ae 100644
--- a/src/components/menu/Location.vue
+++ b/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],
+  }));
+});
+
+// 鍋囪鍦ㄧ粍浠跺垵濮嬪寲涔嬪墠锛宒eviceListAll 宸茶濉厖浜嗘墍鏈夊尯鍩熺殑鏁版嵁
+// 濡傛灉涓嶆槸杩欐牱锛屽垯闇�瑕佷繚鐣欏 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;

--
Gitblit v1.9.3