|
|
@@ -85,6 +85,10 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import {
|
|
|
+ subscribe,
|
|
|
+ unsubscribe
|
|
|
+} from '@/utils/mqtt'
|
|
|
import { getDevicesByTenant } from '@/api/device'
|
|
|
import {
|
|
|
getApks,
|
|
|
@@ -100,6 +104,11 @@ export default {
|
|
|
components: {
|
|
|
DeviceTypeTree
|
|
|
},
|
|
|
+ provide () {
|
|
|
+ return {
|
|
|
+ monitor: this
|
|
|
+ }
|
|
|
+ },
|
|
|
data () {
|
|
|
return {
|
|
|
version: {},
|
|
|
@@ -166,7 +175,54 @@ export default {
|
|
|
tenant: null
|
|
|
}
|
|
|
},
|
|
|
+ created () {
|
|
|
+ this.$timer = -1
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ this.$map = new Map()
|
|
|
+ subscribe(['+/+/apk/upgrade/progress'], this.onMessage)
|
|
|
+ },
|
|
|
+ beforeDestroy () {
|
|
|
+ this.$map.clear()
|
|
|
+ unsubscribe(['+/+/apk/upgrade/progress'], this.onMessage)
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ addListener (deviceId, component) {
|
|
|
+ let data = this.$map.get(deviceId)
|
|
|
+ if (data) {
|
|
|
+ component.onMessage(data.progress, data.timestamp)
|
|
|
+ } else {
|
|
|
+ this.$map.set(deviceId, data = {
|
|
|
+ progress: 0,
|
|
|
+ timestamp: Date.now(),
|
|
|
+ listeners: new Set()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ data.listeners.add(component)
|
|
|
+ },
|
|
|
+ removeListener (deviceId, component) {
|
|
|
+ const data = this.$map.get(deviceId)
|
|
|
+ if (data) {
|
|
|
+ data.listeners.delete(component)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onMessage (topic, message) {
|
|
|
+ const result = /^\d+\/(\d+)\/apk\/upgrade\/progress$/.exec(topic)
|
|
|
+ if (!result) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const deviceId = result[1]
|
|
|
+ const data = this.$map.get(deviceId)
|
|
|
+ if (data) {
|
|
|
+ const progress = JSON.parse(message).progress
|
|
|
+ const timestamp = Date.now()
|
|
|
+ data.progress = progress
|
|
|
+ data.timestamp = timestamp
|
|
|
+ data.listeners.forEach(component => {
|
|
|
+ component.onMessage(progress)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
onAdd () {
|
|
|
this.version = {
|
|
|
name: '',
|