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 |  225 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 196 insertions(+), 29 deletions(-)

diff --git a/src/components/monifangzhen/schemeCard.vue b/src/components/monifangzhen/schemeCard.vue
index a25acd1..b3d1b9d 100644
--- a/src/components/monifangzhen/schemeCard.vue
+++ b/src/components/monifangzhen/schemeCard.vue
@@ -23,7 +23,15 @@
           <el-button size="small" @click="setSchemClick(item)"
             >鏂规璇︽儏</el-button
           >
-          <el-button size="small" @click="startPlay(item)">杩涘叆妯℃嫙</el-button>
+          <el-button
+            size="small"
+            v-show="item.type !== 2"
+            @click="startPlay(item)"
+            >杩涘叆妯℃嫙</el-button
+          >
+          <el-button size="small" v-show="item.type == 2" @click="rePlay(item)"
+            >鍘嗗彶鍥炴斁</el-button
+          >
           <!--  :disabled="item.status !== 2" -->
         </div>
       </div>
@@ -45,7 +53,15 @@
 
 <script setup>
 import { EventBus } from "@/eventBus"; // 寮曞叆浜嬩欢鎬荤嚎
-import { onMounted, ref, watch, defineEmits, onUnmounted } from "vue";
+import {
+  nextTick,
+  onMounted,
+  ref,
+  watch,
+  defineEmits,
+  onUnmounted,
+  inject,
+} from "vue";
 import dayjs from "dayjs";
 import { initeWaterPrimitiveView } from "@/utils/water";
 import Message from "@/components/tools/Message.vue";
@@ -56,12 +72,16 @@
 import { ElMessage, ElMessageBox } from "element-plus";
 const emit = defineEmits(["start", "end", "reset", "closeBtn"]);
 import {
-  getRegionData,
   getSimData,
   deleteSimData,
   getSimStart,
   getSimDataById,
+  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();
@@ -73,7 +93,6 @@
 function selectScheme(id) {
   selectedId.value = id;
 }
-
 
 function formatTime(time) {
   return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
@@ -94,7 +113,149 @@
   messageShow.value = false;
 }
 
+// 瀹炴椂妯℃嫙浜斿垎閽熻姹備竴娆$殑瀹氭椂鍣�
+const realTimeSimInterval = ref(null);
+
+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;
@@ -123,11 +284,11 @@
     currentScheme.value = item;
     schemeInfoShow.value = true;
     emit("closeBtn", false);
-    emit("start");
+    startSimulate();
     return;
   }
 
-  // 璋冪敤姹傝В鍣紙涓嶅湪瀹炴椂妯℃嫙鐨勬儏鍐典笅锛�
+  // 鏂板缓鏂规锛屾病鏈� status 鍜� serviceName 涓� type != 2
   if (!item.status && !item.serviceName && item.type !== 2) {
     try {
       await getSimStart(item.id);
@@ -143,31 +304,36 @@
     return;
   }
 
-  // 瀹炴椂妯℃嫙
-  if (item.type === 2) {
-    try {
-      // 瀹炴椂妯℃嫙璋冪敤姹傝В鍣ㄤ細鐩存帴鍦ㄦ帴鍙d腑杩斿洖缁撴灉
-      const ress = await getSimStart(item.id);
-      const res = await getSimDataById(item.id);
-      item.serviceName = res.data[0]?.serviceName || null;
-      simStore.setSelectedScheme(item);
-      getScheme();
-
-      if (ress.code === 200) {
-        initeWaterPrimitiveView();
-        emit("start");
-      }
-    } catch (e) {
-      console.error("瀹炴椂妯℃嫙鑾峰彇妯℃嫙鏁版嵁澶辫触锛�", e);
-    }
-    return;
-  }
-
   // 榛樿鎯呭喌锛氭湁鏈嶅姟鍚嶇О
   simStore.setSelectedScheme(item);
 }
 
-
+// 瀹炴椂妯℃嫙鍘嗗彶鍥炴斁
+function rePlay(item) {
+  // 褰撳墠閫変腑鐨勬柟妗�
+  simStore.setSelectedScheme(item);
+  // 鎷縤d鍘昏姹俽esults鎺ュ彛锛屽鏋滈暱搴︿笉涓�0锛屽垯鍙互杩涜鍘嗗彶鍥炴斁
+  getSimresult(item.id)
+    .then((res) => {
+      if (res.code == 500) {
+        // 濡傛灉闀垮害涓�0锛屾彁绀虹敤鎴峰苟涓斾笉杩涜鍚庣画鎿嶄綔
+        ElMessage.warning("鎻愮ず锛氭病鏈夊彲鍥炴斁鐨勬暟鎹紒");
+        return; // 闃绘鍚庣画鎿嶄綔
+      } else {
+        simStore.rePlayList = res.data;
+        console.log(simStore.rePlayList, "瀹炴椂妯℃嫙鍘嗗彶鍥炴斁鍒楄〃");
+      }
+      // 浣跨敤 nextTick 纭繚 DOM 鏇存柊鍚庡啀鎵ц鍚庣画鎿嶄綔
+      nextTick(() => {
+        initeWaterPrimitiveView();
+        startSimulate();
+      });
+    })
+    .catch((error) => {
+      console.log("璇锋眰澶辫触锛�", error);
+      // 閿欒澶勭悊
+    });
+}
 
 function handleBack(value) {
   if (value === false) {
@@ -195,7 +361,9 @@
       (item) =>
         item.result == "鍒涘缓浠跨湡" ||
         item.result == "瀹屾垚" ||
-        item.result == "-1"
+        item.result == "-1" ||
+        item.result == "宸插仠姝�" ||
+        item.result == "杩愯涓�"
     );
     simAPIStore.shouldPoll = !shouldStop; // 淇敼 Pinia 鐘舵��
     // 3. 濡傛灉闇�瑕佸仠姝�
@@ -216,7 +384,6 @@
 watch(
   () => simAPIStore.shouldPoll,
   (isStarted) => {
-    console.log(isStarted, "瀹氭椂鍣�");
     if (isStarted) {
       getScheme(); // 棣栨绔嬪嵆鑾峰彇涓�娆�
       intervalId = setInterval(getScheme, 60 * 1000); // 姣忛殧涓�鍒嗛挓鎵ц

--
Gitblit v1.9.3