Explorar el Código

fix(dashboard): statistics not refreshed when device online status changes

Casper Dai hace 2 años
padre
commit
4469d1be65

+ 4 - 0
src/views/dashboard/Dashboard.vue

@@ -4,6 +4,7 @@
     margin
   >
     <device-dashboard
+      ref="dashboard"
       class="l-flex__none c-sibling-item--v"
       @group-change="onGroupChange"
       @status-change="onStatusChange"
@@ -53,6 +54,9 @@ export default {
     },
     onLoaded (total) {
       this.total = total
+    },
+    onDeviceStatusChanged (val) {
+      this.$refs.dashboard.onDeviceStatusChanged(val)
     }
   }
 }

+ 6 - 0
src/views/dashboard/components/DeviceDashboard.vue

@@ -165,6 +165,12 @@ export default {
       ).finally(() => {
         options.loading = false
       })
+    },
+    onDeviceStatusChanged (val) {
+      if (this.options.loaded) {
+        this.options.online += val
+        this.options.offline -= val
+      }
     }
   }
 }

+ 0 - 1
src/views/dashboard/components/DeviceGroupLevel.vue

@@ -34,7 +34,6 @@ export default {
     VolumeDialog
   },
   mixins: [groupMixin],
-  inject: ['dashboard'],
   props: {
     path: {
       type: String,

+ 0 - 1
src/views/dashboard/components/DeviceGroupTile.vue

@@ -32,7 +32,6 @@ import groupListMixin from './mixins/group-list.js'
 export default {
   name: 'DeviceGroupTile',
   mixins: [groupMixin, groupListMixin],
-  inject: ['dashboard'],
   props: {
     path: {
       type: String,

+ 2 - 2
src/views/dashboard/components/mixins/group.js

@@ -5,6 +5,7 @@ import {
 } from '@/utils/mqtt'
 
 export default {
+  inject: ['dashboard'],
   data () {
     return {
       groupOptions: this.createGroupOptions({ ignore: true })
@@ -88,8 +89,7 @@ export default {
       }
     },
     onStatusChanged (topicKey) {
-      // todo
-      console.log(topicKey)
+      this.dashboard?.onDeviceStatusChanged(topicKey === 'online' ? 1 : -1)
     },
     transformDevice ({ id, name, productId, onlineStatus, lastOnline, address }) {
       return {