LIJU 19 hours ago
parent
commit
aa594a2ed2
1 changed files with 33 additions and 8 deletions
  1. 33 8
      src/components/medical-advice/temperature/graphics.vue

+ 33 - 8
src/components/medical-advice/temperature/graphics.vue

@@ -883,15 +883,40 @@ export default {
       const date = new Date(admissionDateTime);
       const hour = date.getHours();
       
-      // 时间段映射:02:00, 06:00, 10:00, 14:00, 18:00, 22:00
-      if (hour >= 2 && hour < 6) return 0;   // 02:00
-      if (hour >= 6 && hour < 10) return 1;  // 06:00
-      if (hour >= 10 && hour < 14) return 2; // 10:00
-      if (hour >= 14 && hour < 18) return 3; // 14:00
-      if (hour >= 18 && hour < 22) return 4; // 18:00
-      if (hour >= 22 || hour < 2) return 5;  // 22:00
+      // 标准时间点:02:00, 06:00, 10:00, 14:00, 18:00, 22:00
+      const standardHours = [2, 6, 10, 14, 18, 22];
       
-      return -1;
+      // 计算到每个标准时间点的距离,选择最近的
+      let minDistance = Infinity;
+      let closestIndex = -1;
+      
+      for (let i = 0; i < standardHours.length; i++) {
+        const standardHour = standardHours[i];
+        let distance;
+        
+        // 计算距离,考虑跨天的情况
+        if (Math.abs(hour - standardHour) <= 12) {
+          // 同一天内或相邻天的情况
+          distance = Math.abs(hour - standardHour);
+        } else {
+          // 跨天的情况,需要计算最短距离
+          if (hour > standardHour) {
+            // 例如:23点到02点,距离是1小时
+            distance = Math.min(hour - standardHour, (24 - hour) + standardHour);
+          } else {
+            // 例如:1点到22点,距离是3小时
+            distance = Math.min(standardHour - hour, (24 - standardHour) + hour);
+          }
+        }
+        
+        // 更新最小距离和对应的索引
+        if (distance < minDistance) {
+          minDistance = distance;
+          closestIndex = i;
+        }
+      }
+      
+      return closestIndex;
     },
     
     getSymbolTextArr(index) {