|
@@ -1,5 +1,9 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div class="o-device has-padding">
|
|
|
|
|
|
|
+ <div
|
|
|
|
|
+ class="o-device has-padding"
|
|
|
|
|
+ :class="{ 'u-pointer': isActivated && isOnline }"
|
|
|
|
|
+ @click="askStatus"
|
|
|
|
|
+ >
|
|
|
<div class="l-flex__none l-flex--row o-device__header">
|
|
<div class="l-flex__none l-flex--row o-device__header">
|
|
|
<i
|
|
<i
|
|
|
class="l-flex__none o-device__status dark"
|
|
class="l-flex__none o-device__status dark"
|
|
@@ -43,10 +47,40 @@
|
|
|
class="l-flex__none o-device__footer"
|
|
class="l-flex__none o-device__footer"
|
|
|
:text="address"
|
|
:text="address"
|
|
|
/>
|
|
/>
|
|
|
|
|
+ <el-dialog
|
|
|
|
|
+ :title="name"
|
|
|
|
|
+ :visible.sync="show"
|
|
|
|
|
+ custom-class="c-dialog"
|
|
|
|
|
+ :before-close="handleClose"
|
|
|
|
|
+ append-to-body
|
|
|
|
|
+ >
|
|
|
|
|
+ <div class="u-text-center">
|
|
|
|
|
+ <i
|
|
|
|
|
+ v-if="loading"
|
|
|
|
|
+ class="el-icon-loading"
|
|
|
|
|
+ />
|
|
|
|
|
+ <template v-else>
|
|
|
|
|
+ <div class="has-bottom-padding">
|
|
|
|
|
+ <button
|
|
|
|
|
+ class="o-button"
|
|
|
|
|
+ @click="ask"
|
|
|
|
|
+ >
|
|
|
|
|
+ 检测状态
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>{{ message }}</div>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
+import {
|
|
|
|
|
+ subscribe,
|
|
|
|
|
+ unsubscribe,
|
|
|
|
|
+ publish
|
|
|
|
|
+} from '@/utils/mqtt'
|
|
|
import AutoText from '@/components/AutoText'
|
|
import AutoText from '@/components/AutoText'
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
@@ -56,7 +90,15 @@ export default {
|
|
|
},
|
|
},
|
|
|
props: {
|
|
props: {
|
|
|
device: {
|
|
device: {
|
|
|
- type: Object
|
|
|
|
|
|
|
+ type: Object,
|
|
|
|
|
+ default: null
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ data () {
|
|
|
|
|
+ return {
|
|
|
|
|
+ show: false,
|
|
|
|
|
+ loading: false,
|
|
|
|
|
+ message: ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
computed: {
|
|
computed: {
|
|
@@ -100,6 +142,54 @@ export default {
|
|
|
// return `位置:${this.device.address}`
|
|
// return `位置:${this.device.address}`
|
|
|
return `备注:${this.device.remark}`
|
|
return `备注:${this.device.remark}`
|
|
|
}
|
|
}
|
|
|
|
|
+ },
|
|
|
|
|
+ beforeDestroy () {
|
|
|
|
|
+ if (this.show) {
|
|
|
|
|
+ this.handleClose()
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ askStatus () {
|
|
|
|
|
+ if (!this.isActivated || !this.isOnline) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.show = true
|
|
|
|
|
+ subscribe(`${this.device.productId}/${this.device.id}/status/reply`, this.onMessage)
|
|
|
|
|
+ },
|
|
|
|
|
+ handleClose () {
|
|
|
|
|
+ this.loading = false
|
|
|
|
|
+ this.message = ''
|
|
|
|
|
+ this.show = false
|
|
|
|
|
+ unsubscribe(`${this.device.productId}/${this.device.id}/status/reply`, this.onMessage)
|
|
|
|
|
+ },
|
|
|
|
|
+ onMessage (topic, message) {
|
|
|
|
|
+ this.loading = false
|
|
|
|
|
+ if (message && new RegExp(`${this.device.productId}/${this.device.id}/status/reply`).test(topic)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ message = JSON.parse(message)
|
|
|
|
|
+ switch (message.status) {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ this.message = '未播放节目,处于默认状态'
|
|
|
|
|
+ break
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ this.message = '正在播放节目'
|
|
|
|
|
+ break
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ this.message = '解析节目异常,请重新发布'
|
|
|
|
|
+ break
|
|
|
|
|
+ default:
|
|
|
|
|
+ this.message = '未知'
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ this.message = '解析异常,请重试'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ ask () {
|
|
|
|
|
+ this.loading = true
|
|
|
|
|
+ publish(`${this.device.productId}/${this.device.id}/status/ask`, JSON.stringify({ timestamp: Date.now() }))
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|