فهرست منبع

fix(dashboard): the current program time is displayed as NaN

Casper Dai 3 سال پیش
والد
کامیت
34336dd28a
1فایلهای تغییر یافته به همراه17 افزوده شده و 10 حذف شده
  1. 17 10
      src/views/dashboard/components/Device.vue

+ 17 - 10
src/views/dashboard/components/Device.vue

@@ -249,19 +249,16 @@ export default {
       const now = new Date()
       let currentEndDate = null
       let next = null
-      if (current) {
-        currentEndDate = getFinishDate(current, now)
-      } else {
+      if (!current) {
         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)
+      currentEndDate = current && getFinishDate(current, now)
       let nextStartDate = null
       for (let i = 0; i < this.timeline.length; i++) {
         const event = this.timeline[i]
@@ -276,14 +273,24 @@ export default {
           }
         }
       }
+      console.log('current', current, currentEndDate)
+      console.log('next', next, nextStartDate)
+      if (nextStartDate && (!currentEndDate || currentEndDate > nextStartDate)) {
+        currentEndDate = nextStartDate
+      }
+      this.current = current && this.getEventInfo(current, getStartDate(current, now), currentEndDate)
+      this.next = next && this.getEventInfo(next, nextStartDate)
       clearTimeout(this.$timer)
       if (currentEndDate) {
-        this.$timer = setTimeout(() => {
-          this.checkTimeline(this.next)
-        }, Math.min(604800000, currentEndDate - now))
+        const delay = currentEndDate - now
+        // delay有最大限制2^31-1,超过后会直接执行
+        // 当前限制最多1天
+        if (delay > 86400000) {
+          this.$timer = setTimeout(this.checkTimeline, 86400000, current)
+        } else {
+          this.$timer = setTimeout(this.checkTimeline, delay, next)
+        }
       }
-      this.current = current && this.getEventInfo(current, getStartDate(current, now), nextStartDate > currentEndDate ? currentEndDate : nextStartDate)
-      this.next = next && this.getEventInfo(next, nextStartDate)
     },
     getEventInfo (event, startDate, endDate) {
       event.invoke?.()