From a57caa72a54efe9de3fe26a6c36d3e8038267377 Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期四, 17 七月 2025 09:09:49 +0800
Subject: [PATCH] 修改x按钮

---
 src/components/monifangzhen/schemeCard.vue |  147 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 144 insertions(+), 3 deletions(-)

diff --git a/src/components/monifangzhen/schemeCard.vue b/src/components/monifangzhen/schemeCard.vue
index 413b52c..b3d1b9d 100644
--- a/src/components/monifangzhen/schemeCard.vue
+++ b/src/components/monifangzhen/schemeCard.vue
@@ -79,6 +79,10 @@
   getSimresult,
 } from "@/api/trApi.js";
 
+import { getAeraTownCode, getDeviceNWJ } from "@/api/hpApi";
+import { createPoint, removeEntities, clearAllPoints } from "@/utils/map";
+import { deviceDictList, getDictName } from "@/constant/dict.js";
+
 const simStore = useSimStore();
 const simAPIStore = SimAPIStore();
 // 閫変腑鐨勬柟妗� ID
@@ -114,7 +118,144 @@
 
 const { startSimulate, endSimulate } = inject("simulateActions");
 
+const BJCode = ref([
+  { label: "瀵嗕簯鍖�", value: "110118000000" },
+  { label: "鎴垮北鍖�", value: "110111000000" },
+  { label: "闂ㄥご娌熷尯", value: "110109000000" },
+  { label: "寤跺簡鍖�", value: "110119000000" },
+  { label: "鎬�鏌斿尯", value: "110116000000" },
+  { label: "鏄屽钩鍖�", value: "110114000000" },
+  { label: "骞宠胺鍖�", value: "110117000000" },
+  { label: "娴锋穩鍖�", value: "110108000000" },
+  { label: "鐭虫櫙灞卞尯", value: "110107000000" },
+  { label: "涓板彴鍖�", value: "110106000000" },
+]);
+
 async function startPlay(item) {
+  simStore.openDia = false;
+  clearAllPoints();
+  const areaName = item.areaName;
+
+  let districtCode;
+
+  // 1. 鍒ゆ柇鏄惁鍖呭惈 鈥滃尯鈥�
+  if (!areaName.includes("鍖�")) {
+    console.log(
+      `鏂规涓ā鎷熴��${areaName}銆戜笉鍖呭惈鈥滃尯鈥濓紝浣跨敤榛樿缂栫爜锛氭��鏌斿尯(110116000000)`
+    );
+    districtCode = "110116000000"; // 鎵嬪姩鎸囧畾涓烘��鏌斿尯缂栫爜
+  } else {
+    // 2. 鍦� BJCode 涓煡鎵惧尮閰嶇殑鍖哄煙 value
+    const matchedArea = BJCode.value.find((area) => area.label === areaName);
+
+    if (!matchedArea) {
+      console.warn(`鏈壘鍒� ${areaName} 瀵瑰簲鐨勫尯鍩熺紪鐮乣);
+      return;
+    }
+
+    districtCode = matchedArea.value;
+  }
+
+  // 1. 鑾峰彇涔¢晣鍖哄煙缂栫爜
+  const areaRes = await getAeraTownCode(districtCode);
+  const districtCodes = areaRes.data.map((item) => item.districtCode);
+
+  // 2. 娉ヤ綅璁$被鍨婭D
+  const ids = "1437295811";
+
+  // 3. 骞惰璇锋眰鎵�鏈夎澶囨暟鎹�
+  const requests = districtCodes.map((code) =>
+    getDeviceNWJ(ids, code)
+      .then((res) => res.data?.pageData || []) // 瀹夊叏鎻愬彇 pageData
+      .catch((err) => {
+        console.error(`璇锋眰澶辫触 (code: ${code})`, err);
+        return []; // 鍑洪敊鏃朵篃杩斿洖绌烘暟缁勶紝閬垮厤 Promise.all 涓柇
+      })
+  );
+
+  // 4. 绛夊緟鎵�鏈夎姹傚畬鎴�
+  const allPageDataArrays = await Promise.all(requests);
+
+  // 5. 鍚堝苟浜岀淮鏁扮粍涓轰竴缁存暟缁�
+  const mergedPageData = allPageDataArrays.flat();
+
+  // 6. 濡傛灉涓嶆槸鈥滃尯鈥濓紝鍒欒繃婊ゅ嚭 deviceName 鍖呭惈 "瀛欒儭娌�" 鐨勮澶�
+  const filteredPageData = areaName.includes("鍖�")
+    ? mergedPageData
+    : mergedPageData.filter((device) => device.deviceName.includes("瀛欒儭娌�"));
+
+  // 瀛欒儭娌熻澶囩粡绾害鏄犲皠
+  const deviceMapping = {
+    鎬�鏌斿尯鐞夌拑搴欓晣瀛欒儭娌熸ご鏍戝簳涓嬩笢娌熸偿浣嶈5007: {
+      lon: 116.598891,
+      lat: 40.554979,
+    },
+    鎬�鏌斿尯鐞夌拑搴欓晣瀛欒儭娌熸潙涓婂彴瀛愭渤涓滃崡娌熸偿浣嶈5006: {
+      lon: 116.593215,
+      lat: 40.554399,
+    },
+  };
+
+  let displayedData = filteredPageData;
+
+  if (!areaName.includes("鍖�")) {
+    // 娣诲姞 lon 鍜� lan 瀛楁
+    displayedData = filteredPageData.map((device) => {
+      const mapping = deviceMapping[device.deviceName];
+      return {
+        ...device,
+        ...(mapping && { lon: mapping.lon, lat: mapping.lat }), // 濡傛灉 mapping 瀛樺湪锛屾墠娣诲姞
+      };
+    });
+
+    // 娣诲姞棰濆鐨勪袱涓偣浣�
+    const extraPoint1 = {
+      deviceName: "寮矡1",
+      longitude: 116.597836,
+      latitude: 40.564962,
+      // height: 530.14,
+      type: "娉ヤ綅璁�",
+      lon: 116.597836,
+      lat: 40.564962,
+      dictDeviceType: "1437295811",
+      deviceId: "custom_extraPoint1", // 鎵嬪姩鍔犱竴涓敮涓� ID
+    };
+
+    const extraPoint2 = {
+      deviceName: "寮矡2",
+      longitude: 116.591571,
+      latitude: 40.573093,
+      // height: 483.89,
+      type: "娉ヤ綅璁�",
+      lon: 116.591571,
+      lat: 40.573093,
+      dictDeviceType: "1437295811",
+      deviceId: "custom_extraPoint2", // 鎵嬪姩鍔犱竴涓敮涓� ID
+    };
+
+    displayedData = [...displayedData, extraPoint1, extraPoint2];
+    // displayedData = [...displayedData, extraPoint1];
+  }
+
+  console.log(
+    displayedData,
+    areaName.includes("鍖�")
+      ? "鍏ㄩ儴娉ヤ綅璁¤澶囧垪琛�"
+      : "瀛欒儭娌熸偿浣嶈 + 棰濆鐐逛綅鍒楄〃"
+  );
+
+  // 7. 鍒涘缓鐐�
+  displayedData.forEach((item) => {
+    // 鏍规嵁闇�姹傚彲澧炲垹
+    item.type = getDictName(deviceDictList, item.dictDeviceType);
+    item.name = item.deviceName;
+    item.id = item.deviceId;
+    item.className = "device";
+    item.showLabel = true;
+
+    createPoint(item);
+  });
+
   if (item.status === 2) {
     ElMessage.warning("褰撳墠鏂规姝e湪鍒嗘瀽涓�,鏃犳硶杩涘叆妯℃嫙锛�");
     return;
@@ -180,7 +321,7 @@
         return; // 闃绘鍚庣画鎿嶄綔
       } else {
         simStore.rePlayList = res.data;
-        console.log(simStore.rePlayList, "lisi");
+        console.log(simStore.rePlayList, "瀹炴椂妯℃嫙鍘嗗彶鍥炴斁鍒楄〃");
       }
       // 浣跨敤 nextTick 纭繚 DOM 鏇存柊鍚庡啀鎵ц鍚庣画鎿嶄綔
       nextTick(() => {
@@ -221,8 +362,8 @@
         item.result == "鍒涘缓浠跨湡" ||
         item.result == "瀹屾垚" ||
         item.result == "-1" ||
-        item.result == "鍋滄" ||
-        item.result == "杩涜涓�"
+        item.result == "宸插仠姝�" ||
+        item.result == "杩愯涓�"
     );
     simAPIStore.shouldPoll = !shouldStop; // 淇敼 Pinia 鐘舵��
     // 3. 濡傛灉闇�瑕佸仠姝�

--
Gitblit v1.9.3