Sfoglia il codice sorgente

refactor: dashboard device refresh strategy

Casper Dai 3 anni fa
parent
commit
3a7861c733
1 ha cambiato i file con 7 aggiunte e 15 eliminazioni
  1. 7 15
      src/views/dashboard/index.vue

+ 7 - 15
src/views/dashboard/index.vue

@@ -161,20 +161,9 @@ export default {
   },
   methods: {
     onMessage (topic) {
-      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 }) => id === deviceId)
-        if (device && (result[2] === 'online' && device.onlineStatus !== 1 || result[2] === 'offline' && device.onlineStatus === 1)) {
-          this.refreshDevices()
-        }
+      const result = /^(\d+)\/\d+\/(online|offline)$/.exec(topic)
+      if (result && (!this.product || this.product === result[1])) {
+        this.refreshDevices(true)
       }
     },
     _getProducts () {
@@ -225,9 +214,12 @@ export default {
         monitor.online = onLineTotal
         monitor.offline = offLineTotal
         monitor.inactive = notEnabledTotal
-        this._getDevices(total)
       }).finally(() => {
         monitor.loading = false
+      }).then(() => {
+        if (!this.monitor.loading) {
+          this._getDevices(this.monitor.total)
+        }
       })
     },
     sort (a, b) {