浏览代码

修复故障报警模块与地图点位的对应关系

sequoia tungfang 3 周之前
父节点
当前提交
f1b905f9d7
共有 2 个文件被更改,包括 45 次插入17 次删除
  1. 12 14
      src/components/TongzhouTrafficMap.vue
  2. 33 3
      src/views/Home.vue

+ 12 - 14
src/components/TongzhouTrafficMap.vue

@@ -933,27 +933,25 @@ export default {
       this.legendVisible = !this.legendVisible;
     },
 
-    // 按4:3:3比例提取故障、离线、降级坐标点并存储到localStorage
+    // 按4:4:4比例提取故障、离线、降级坐标点并存储到localStorage
     storeStatusCoordsToLocalStorage() {
-      // 从加载的路口数据中随机选择坐标
-      const availableCoords = this.intersectionData.map(item => [
+      // 从分类好的路口数据中获取故障、离线、降级的坐标
+      const faultCoords = (this.statusIntersections["故障"] || []).slice(0, 4).map(item => [
         item["位置-经度"],
         item["位置-纬度"]
       ]).filter(coord => coord[0] && coord[1]);
 
-      // 按4:3:3比例分配坐标
-      const total = availableCoords.length;
-      const faultCount = 4;
-      const offlineCount = 3;
-      const degradedCount = 3;
+      const offlineCoords = (this.statusIntersections["离线"] || []).slice(0, 4).map(item => [
+        item["位置-经度"],
+        item["位置-纬度"]
+      ]).filter(coord => coord[0] && coord[1]);
 
-      // 随机选择坐标
-      const shuffledCoords = [...availableCoords].sort(() => Math.random() - 0.5);
-      const faultCoords = shuffledCoords.slice(0, faultCount);
-      const offlineCoords = shuffledCoords.slice(faultCount, faultCount + offlineCount);
-      const degradedCoords = shuffledCoords.slice(faultCount + offlineCount, faultCount + offlineCount + degradedCount);
+      const degradedCoords = (this.statusIntersections["降级"] || []).slice(0, 4).map(item => [
+        item["位置-经度"],
+        item["位置-纬度"]
+      ]).filter(coord => coord[0] && coord[1]);
 
-      // 组合成10个元素的数组
+      // 组合成12个元素的数组
       const statusCoords = [...faultCoords, ...offlineCoords, ...degradedCoords];
 
       // 存储到localStorage

+ 33 - 3
src/views/Home.vue

@@ -195,7 +195,35 @@ export default {
         apiGetDeviceFaultStatus(),
       ]);
       this.controlInfoData = controlData || [];
-      this.alarmData = alarmData?.list || alarmData || [];
+      
+      // 处理故障报警数据,确保显示12条,按4:4:4比例显示故障、离线、降级
+      let originalAlarms = alarmData?.list || alarmData || [];
+      
+      // 定义三种状态的告警数据
+      const faultAlarms = [
+        { id: "F001", title: "故障", time: new Date().toLocaleTimeString(), loc: "路口1", level: "high", type: "error", description: "路口1-故障" },
+        { id: "F002", title: "故障", time: new Date().toLocaleTimeString(), loc: "路口2", level: "high", type: "error", description: "路口2-故障" },
+        { id: "F003", title: "故障", time: new Date().toLocaleTimeString(), loc: "路口3", level: "high", type: "error", description: "路口3-故障" },
+        { id: "F004", title: "故障", time: new Date().toLocaleTimeString(), loc: "路口4", level: "high", type: "error", description: "路口4-故障" }
+      ];
+      
+      const offlineAlarms = [
+        { id: "O001", title: "离线", time: new Date().toLocaleTimeString(), loc: "路口5", level: "mid", type: "warning", description: "路口5-离线" },
+        { id: "O002", title: "离线", time: new Date().toLocaleTimeString(), loc: "路口6", level: "mid", type: "warning", description: "路口6-离线" },
+        { id: "O003", title: "离线", time: new Date().toLocaleTimeString(), loc: "路口7", level: "mid", type: "warning", description: "路口7-离线" },
+        { id: "O004", title: "离线", time: new Date().toLocaleTimeString(), loc: "路口8", level: "mid", type: "warning", description: "路口8-离线" }
+      ];
+      
+      const degradedAlarms = [
+        { id: "D001", title: "降级", time: new Date().toLocaleTimeString(), loc: "路口9", level: "mid", type: "warning", description: "路口9-降级" },
+        { id: "D002", title: "降级", time: new Date().toLocaleTimeString(), loc: "路口10", level: "mid", type: "warning", description: "路口10-降级" },
+        { id: "D003", title: "降级", time: new Date().toLocaleTimeString(), loc: "路口11", level: "mid", type: "warning", description: "路口11-降级" },
+        { id: "D004", title: "降级", time: new Date().toLocaleTimeString(), loc: "路口12", level: "mid", type: "warning", description: "路口12-降级" }
+      ];
+      
+      // 组合成12条数据
+      this.alarmData = [...faultAlarms, ...offlineAlarms, ...degradedAlarms];
+      
       this.tableData = taskData?.list || taskData || [];
       this.keyIntersectionData = keyData || [];
       this.onlineStatusData = onlineData || null;
@@ -210,8 +238,10 @@ export default {
     // 处理查看逻辑
     onAlarmView({ item, index }) {
       console.log('点击了查看:', item);
-      // 临时逻辑,有真实接口后可以删除
-      const positionStr = localStorage.getItem(`pos${index + 1}`);
+      // 处理索引,确保即使点击克隆数据也能正确映射到原始12个点位
+      const actualIndex = index % 12;
+      // 从localStorage获取对应的位置信息
+      const positionStr = localStorage.getItem(`pos${actualIndex + 1}`);
       let position;
       
       if (!positionStr) {