|
|
@@ -4,11 +4,15 @@ import {
|
|
|
subscribe,
|
|
|
unsubscribe
|
|
|
} from '@/utils/mqtt'
|
|
|
-import { parseByte } from '@/utils'
|
|
|
+import {
|
|
|
+ parseTime,
|
|
|
+ parseByte
|
|
|
+} from '@/utils'
|
|
|
|
|
|
let productId = null
|
|
|
let deviceId = null
|
|
|
let cbs = null
|
|
|
+
|
|
|
let download = null
|
|
|
let screenshotPic = null
|
|
|
let sensor = null
|
|
|
@@ -22,6 +26,8 @@ export function start (device) {
|
|
|
productId = device.productId
|
|
|
deviceId = device.id
|
|
|
subscribe([
|
|
|
+ `${productId}/${deviceId}/online`,
|
|
|
+ `${productId}/${deviceId}/offline`,
|
|
|
`${productId}/${deviceId}/resource/progress`,
|
|
|
`${productId}/${deviceId}/screenshot/reply`
|
|
|
], onMessage)
|
|
|
@@ -33,6 +39,8 @@ export function start (device) {
|
|
|
export function stop () {
|
|
|
if (productId) {
|
|
|
unsubscribe([
|
|
|
+ `${productId}/${deviceId}/online`,
|
|
|
+ `${productId}/${deviceId}/offline`,
|
|
|
`${productId}/${deviceId}/resource/progress`,
|
|
|
`${productId}/${deviceId}/screenshot/reply`
|
|
|
], onMessage)
|
|
|
@@ -87,9 +95,13 @@ function invoke (type, cb) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function emit (type) {
|
|
|
+function emit (type, val) {
|
|
|
if (cbs && cbs[type]) {
|
|
|
- cbs && cbs[type].forEach(cb => invoke(type, cb))
|
|
|
+ if (val == null) {
|
|
|
+ cbs[type].forEach(cb => invoke(type, cb))
|
|
|
+ } else {
|
|
|
+ cbs[type].forEach(cb => cb(val))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -104,6 +116,12 @@ function onMessage (topic, message) {
|
|
|
|
|
|
function onUpdate (invoke, message) {
|
|
|
switch (invoke) {
|
|
|
+ case 'online':
|
|
|
+ emit('online', true)
|
|
|
+ break
|
|
|
+ case 'offline':
|
|
|
+ emit('online', false)
|
|
|
+ break
|
|
|
case 'resource/progress':
|
|
|
onUpdateFile(message)
|
|
|
break
|
|
|
@@ -164,10 +182,11 @@ function transformValue (type, value, unit) {
|
|
|
}
|
|
|
|
|
|
function transform (type, arr) {
|
|
|
- return arr.sort((a, b) => b.sensorValue - a.sensorValue).map(({ sensorAddr, sensorValue, sensorValueUnit }) => {
|
|
|
+ return arr.sort((a, b) => b.sensorValue - a.sensorValue).map(({ sensorAddr, sensorValue, sensorValueUnit, logDate }) => {
|
|
|
return {
|
|
|
key: sensorAddr,
|
|
|
- value: transformValue(type, sensorValue, sensorValueUnit)
|
|
|
+ value: transformValue(type, sensorValue, sensorValueUnit),
|
|
|
+ time: parseTime(logDate * 1000, '{y}.{m}.{d} {h}:{i}:{s}')
|
|
|
}
|
|
|
})
|
|
|
}
|