| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <template>
- <box
- title="信息"
- can-full-screen
- fullscreen
- v-on="$listeners"
- >
- <div
- v-for="(row, index) in rows"
- :key="index"
- class="l-flex--row c-sibling-item--v far c-info__row"
- >
- <div
- v-for="item in row"
- :key="item.key"
- class="l-flex--row l-flex__fill"
- >
- <div class="l-flex__fill l-flex--row center row__label">
- {{ item.label }}
- </div>
- <div class="l-flex__fill">{{ device[item.key] }}</div>
- </div>
- </div>
- <div class="l-flex--row l-flex__fill center">
- <button
- class="l-flex__none o-button"
- @click="onSwitch(true)"
- >
- <i class="o-button__icon el-icon-switch-button" />
- 开机
- </button>
- <button
- class="l-flex__none o-button"
- @click="onSwitch(false)"
- >
- <i class="o-button__icon el-icon-switch-button" />
- 关机
- </button>
- <button
- class="l-flex__none o-button"
- @click="onReboot"
- >
- <i
- class="o-button__icon"
- :class="{
- 'el-icon-loading': rebooting,
- 'el-icon-refresh-right': !rebooting,
- }"
- />
- 重启
- </button>
- </div>
- </box>
- </template>
- <script>
- import {
- publish,
- subscribe,
- unsubscribe
- } from '@/utils/mqtt'
- import Box from './Box'
- export default {
- name: 'DeviceInfo',
- components: {
- Box
- },
- props: {
- device: {
- type: Object,
- required: true
- }
- },
- data () {
- return {
- online: this.device.activate && this.device.onlineStatus === 1,
- rebooting: false,
- rows: [
- [
- {
- label: '名称',
- key: 'name'
- },
- {
- label: 'MAC',
- key: 'mac'
- }
- ],
- [
- {
- label: '序列号',
- key: 'serialNumber'
- },
- {
- label: '分辨率',
- key: 'resolutionRatio'
- }
- ],
- [
- {
- label: '产品',
- key: 'productName'
- },
- {
- label: '位置',
- key: 'address'
- }
- ]
- ]
- }
- },
- created () {
- subscribe([
- `${this.device.productId}/${this.device.id}/online`,
- `${this.device.productId}/${this.device.id}/offline`
- ], this.onMessage)
- },
- beforeDestroy () {
- unsubscribe([
- `${this.device.productId}/${this.device.id}/online`,
- `${this.device.productId}/${this.device.id}/offline`
- ], this.onMessage)
- },
- methods: {
- onMessage (topic) {
- const result = topic.match(/^(\d+)\/(\d+)\/(online|offline)$/)
- if (result && this.device.productId === result[1] && this.device.id === result[2]) {
- this.rebooting = false
- this.online = result[3] === 'online'
- }
- },
- onSwitch (open) {
- if (!this.online) {
- this.$message({
- type: 'warning',
- message: '设备未上线,请稍后再试'
- })
- return
- }
- this.$confirm(
- `立即${open ? '开机' : '关机'}?`,
- { type: 'warning' }
- ).then(() => {
- this.sendTopic(open ? 'bootDevice' : 'shutdownDevice')
- })
- },
- onReboot () {
- if (!this.online) {
- this.$message({
- type: 'warning',
- message: '设备未上线,请稍后再试'
- })
- return
- }
- if (this.rebooting) {
- return
- }
- this.$confirm(
- `立即重启?`,
- { type: 'warning' }
- ).then(() => {
- publish(
- `${this.device.productId}/${this.deviceId}/restart/ask`,
- JSON.stringify({ timestamp: `${Date.now()}` })
- ).then(
- () => {
- this.rebooting = true
- this.$message({
- type: 'success',
- message: '执行成功'
- })
- },
- () => {
- this.$message({
- type: 'warning',
- message: '正在连接,请稍后再试'
- })
- }
- )
- })
- },
- sendTopic (invoke, inputs = []) {
- publish(
- `${this.device.productId}/${this.deviceId}/function/invoke`,
- JSON.stringify({
- timestamp: `${Date.now()}`,
- function: invoke,
- inputs
- }),
- true
- ).then(
- () => {
- this.$message({
- type: 'success',
- message: '执行成功'
- })
- },
- () => {
- this.$message({
- type: 'warning',
- message: '正在连接,请稍后再试'
- })
- }
- )
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .c-info {
- &__row {
- height: 80px;
- background: #313a5a;
- .row__label {
- color: #9ea9cd;
- }
- }
- }
- .o-button {
- width: 200px;
- height: 80px;
- font-size: 36px;
- & ~ & {
- margin-left: 150px;
- }
- &__icon {
- font-size: 36px;
- }
- }
- </style>
|