Selaa lähdekoodia

fix: timer invalid

the delay exceeds the maximum
Casper Dai 3 vuotta sitten
vanhempi
sitoutus
b745d4e14a
1 muutettua tiedostoa jossa 14 lisäystä ja 12 poistoa
  1. 14 12
      src/views/dashboard/components/Device.vue

+ 14 - 12
src/views/dashboard/components/Device.vue

@@ -227,7 +227,7 @@ export default {
           }
           return b.priority - a.priority
         })
-        this.checkComplexTimeline()
+        this.checkTimeline()
       } else {
         clearTimeout(this.$timer)
         this.timeline = null
@@ -244,18 +244,21 @@ export default {
         }
       })
     },
-    checkComplexTimeline () {
+    checkTimeline (current) {
       this.loadingTimeline = false
       const now = new Date()
-      let current = null
       let currentEndDate = null
       let next = null
-      for (let i = 0; i < this.timeline.length; i++) {
-        const event = this.timeline[i]
-        if (!current && isHit(event, now)) {
-          current = event
-          currentEndDate = getFinishDate(current, now)
-          break
+      if (current) {
+        currentEndDate = getFinishDate(current, now)
+      } else {
+        for (let i = 0; i < this.timeline.length; i++) {
+          const event = this.timeline[i]
+          if (!current && isHit(event, now)) {
+            current = event
+            currentEndDate = getFinishDate(current, now)
+            break
+          }
         }
       }
       console.log('currentEndDate', currentEndDate)
@@ -276,9 +279,8 @@ export default {
       clearTimeout(this.$timer)
       if (currentEndDate) {
         this.$timer = setTimeout(() => {
-          this.next = null
-          this.checkComplexTimeline()
-        }, currentEndDate - now)
+          this.checkTimeline(this.next)
+        }, Math.min(604800000, currentEndDate - now))
       }
       this.current = current && this.getEventInfo(current, getStartDate(current, now), nextStartDate > currentEndDate ? currentEndDate : nextStartDate)
       this.next = next && this.getEventInfo(next, nextStartDate)