DeviceInfo.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="wrapper">
  3. <div class="info">
  4. <div
  5. v-for="item in items"
  6. :key="item.id"
  7. class="item"
  8. >
  9. <div class="label">{{ item.label }}</div>
  10. <div class="value">{{ device[item.key] }}</div>
  11. </div>
  12. </div>
  13. <div class="buttons">
  14. <el-button
  15. class="o-button"
  16. icon="el-icon-switch-button"
  17. @click="onSwitch(true)"
  18. >开机</el-button>
  19. <el-button
  20. class="o-button"
  21. icon="el-icon-switch-button"
  22. @click="onSwitch(false)"
  23. >关机</el-button>
  24. <el-button
  25. :loading="rebooting"
  26. class="o-button"
  27. icon="el-icon-refresh-right"
  28. @click="invoke"
  29. >重启</el-button>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import { publish } from '@/utils/mqtt'
  35. import { send } from '../../monitor'
  36. export default {
  37. props: {
  38. device: {
  39. type: Object,
  40. required: true
  41. },
  42. online: {
  43. type: Boolean,
  44. required: true
  45. }
  46. },
  47. data () {
  48. return {
  49. rebooting: false,
  50. openFunctionKey: 'bootDevice',
  51. closeFunctionKey: 'shutdownDevice',
  52. items: [
  53. {
  54. label: '名称',
  55. key: 'name'
  56. },
  57. {
  58. label: 'MAC',
  59. key: 'mac'
  60. },
  61. {
  62. label: '序列号',
  63. key: 'serialNumber'
  64. },
  65. {
  66. label: '分辨率',
  67. key: 'resolutionRatio'
  68. }
  69. ]
  70. }
  71. },
  72. watch: {
  73. online () {
  74. this.rebooting = false
  75. }
  76. },
  77. methods: {
  78. onSwitch (open) {
  79. if (!this.online) {
  80. this.$message({
  81. type: 'warning',
  82. message: '设备未上线,请稍后再试'
  83. })
  84. return
  85. }
  86. this.$confirm(`立即${open ? '开机' : '关机'}?`, {
  87. type: 'warning'
  88. }).then(() => {
  89. this.sendTopic(open ? this.openFunctionKey : this.closeFunctionKey)
  90. })
  91. },
  92. invoke () {
  93. if (this.rebooting) {
  94. return
  95. }
  96. if (!this.online) {
  97. this.$message({
  98. type: 'warning',
  99. message: '设备未上线,请稍后再试'
  100. })
  101. return
  102. }
  103. this.$confirm(`重启 ${this.device.name} ?`, { type: 'warning' }).then(
  104. () => {
  105. send('/restart/ask').then(
  106. () => {
  107. this.rebooting = true
  108. },
  109. () => {
  110. this.$message({
  111. type: 'warning',
  112. message: '正在连接,请稍后再试'
  113. })
  114. }
  115. )
  116. }
  117. )
  118. },
  119. sendTopic (invoke, inputs = []) {
  120. console.log(invoke, inputs)
  121. publish(
  122. `${this.device.productId}/${this.deviceId}/function/invoke`,
  123. JSON.stringify({
  124. timestamp: Date.now(),
  125. function: invoke,
  126. inputs
  127. }),
  128. true
  129. ).then(
  130. () => {
  131. this.$message({
  132. type: 'success',
  133. message: '执行成功'
  134. })
  135. },
  136. () => {
  137. this.$message({
  138. type: 'warning',
  139. message: '正在连接,请稍后再试'
  140. })
  141. }
  142. )
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .wrapper {
  149. width: 100%;
  150. display: flex;
  151. align-items: center;
  152. .info {
  153. display: flex;
  154. align-items: center;
  155. background-color: #232b45;
  156. line-height: 40px;
  157. margin-right: 16px;
  158. flex: 1;
  159. .item {
  160. display: flex;
  161. flex: 1;
  162. align-items: center;
  163. .label {
  164. text-align: center;
  165. flex: 1;
  166. color: #9ea9cd;
  167. }
  168. .value {
  169. text-align: center;
  170. flex: 1;
  171. color: #fff;
  172. }
  173. }
  174. }
  175. .buttons {
  176. ::v-deep.el-button+.el-button{
  177. margin-left: 16px;
  178. }
  179. }
  180. }
  181. </style>