Bladeren bron

fix: device schedule display and refresh exception

Casper Dai 3 jaren geleden
bovenliggende
commit
bb0f23ce2d
1 gewijzigde bestanden met toevoegingen van 10 en 3 verwijderingen
  1. 10 3
      src/views/dashboard/components/Device.vue

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

@@ -128,6 +128,8 @@ import {
   publish
 } from '@/utils/mqtt'
 
+const deviceCache = {}
+
 export default {
   name: 'DeviceCard',
   props: {
@@ -315,7 +317,6 @@ export default {
       clearTimeout(this.$timer)
       try {
         message = JSON.parse(message)
-        console.log(message)
         this.timeline = (message.eventDetail || []).map(this.createItem)
         this.checkTimeline()
       } catch {
@@ -353,7 +354,7 @@ export default {
         return now >= startDateTime && (!endDateTime || now <= endDateTime)
       })
       this.current = this.timeline[current]
-      this.next = this.timeline[current + 1]
+      this.next = this.current && this.timeline[current + 1]
       this.next && this.getName(this.next).then(name => {
         this.next.name = name
       })
@@ -372,7 +373,13 @@ export default {
         if (item.name) {
           return Promise.resolve(item.name)
         }
-        return (item.type === 1 ? getProgram : getSchedule)(item.id, { custom: true }).then(({ name }) => name)
+        if (deviceCache[item.id]) {
+          return Promise.resolve(deviceCache[item.id])
+        }
+        return (item.type === 1 ? getProgram : getSchedule)(item.id, { custom: true }).then(({ name }) => {
+          deviceCache[item.id] = name
+          return name
+        })
       }
       return Promise.resolve('未知')
     },