Ver Fonte

fix: device statistics do not match device list

Casper Dai há 3 anos atrás
pai
commit
a1c9999d71
1 ficheiros alterados com 6 adições e 2 exclusões
  1. 6 2
      src/views/dashboard/index.vue

+ 6 - 2
src/views/dashboard/index.vue

@@ -161,13 +161,17 @@ export default {
   },
   methods: {
     onMessage (topic) {
-      if (!this.deviceOptions.loaded || !this.deviceOptions.list.length) {
+      if (this.deviceOptions.loaded && !this.deviceOptions.list.length) {
         return
       }
       const result = /^[^/]+\/(.+)\/(online|offline)$/.exec(topic)
       if (result) {
+        if (!this.deviceOptions.loaded) {
+          this.refreshDevices()
+          return
+        }
         const deviceId = result[1]
-        const device = this.deviceOptions.list.find(({ id, onlineStatus }) => id === deviceId)
+        const device = this.deviceOptions.list.find(({ id }) => id === deviceId)
         if (device && (result[2] === 'online' && device.onlineStatus !== 1 || result[2] === 'offline' && device.onlineStatus === 1)) {
           this.refreshDevices()
         }