index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <wrapper
  3. v-loading="loading"
  4. class="c-detail"
  5. fill
  6. >
  7. <div class="l-flex__none c-detail__header">
  8. <template v-if="device">
  9. <div class="l-flex--row has-padding">
  10. <span
  11. class="c-sibling-item o-status"
  12. :class="statusType"
  13. >
  14. {{ statusTip }}
  15. </span>
  16. <auto-text
  17. class="c-sibling-item o-name"
  18. :text="deviceName"
  19. />
  20. </div>
  21. <el-tabs
  22. v-model="active"
  23. class="c-tabs"
  24. >
  25. <el-tab-pane
  26. v-for="tab in tabs"
  27. :key="tab.key"
  28. :label="tab.label"
  29. :name="tab.key"
  30. />
  31. </el-tabs>
  32. </template>
  33. <warning
  34. v-if="!loading && !device"
  35. @retry="getDevice"
  36. />
  37. </div>
  38. <div
  39. v-if="device"
  40. class="l-flex--col l-flex__fill has-padding"
  41. >
  42. <keep-alive>
  43. <component
  44. :is="activeComponent"
  45. class="l-flex__fill c-detail__wrapper has-padding u-overflow-y--auto"
  46. :device="device"
  47. :online="isOnline"
  48. />
  49. </keep-alive>
  50. </div>
  51. </wrapper>
  52. </template>
  53. <script>
  54. import { getDevice } from '@/api/device'
  55. import { ScreenshotCache } from '@/utils/cache'
  56. import {
  57. start,
  58. stop,
  59. addListener
  60. } from './monitor'
  61. import DeviceInfo from './components/DeviceInfo'
  62. import DeviceStatus from './components/DeviceStatus'
  63. import DeviceAlarm from './components/DeviceAlarm'
  64. import DeviceInvoke from './components/DeviceInvoke'
  65. import ReceivingCard from './components/external/ReceivingCard'
  66. export default {
  67. name: 'DeviceDetail',
  68. components: {
  69. DeviceInfo,
  70. DeviceStatus,
  71. DeviceAlarm,
  72. DeviceInvoke,
  73. ReceivingCard
  74. },
  75. data () {
  76. const canEdit = this.accessSet.has(this.Access.MANAGE_DEVICES) || this.accessSet.has(this.Access.MANAGE_DEVICE)
  77. return {
  78. loading: true,
  79. device: null,
  80. isActivated: false,
  81. isOnline: false,
  82. active: 'info',
  83. tabs: [
  84. { key: 'info', label: '设备信息' },
  85. { key: 'status', label: '运行状态' },
  86. { key: 'alarm', label: '设备告警' },
  87. canEdit ? { key: 'invoke', label: '设备操控' } : null,
  88. { key: 'screen', label: '屏体状态监测' }
  89. ].filter(val => val)
  90. }
  91. },
  92. computed: {
  93. deviceId () {
  94. return this.$route.params.id
  95. },
  96. statusType () {
  97. return this.isActivated
  98. ? this.isOnline
  99. ? 'success'
  100. : 'error'
  101. : this.device.activate
  102. ? 'primary'
  103. : 'warning'
  104. },
  105. statusTip () {
  106. return this.isActivated
  107. ? this.isOnline
  108. ? '在线'
  109. : '离线'
  110. : this.device.activate
  111. ? '已激活'
  112. : '未激活'
  113. },
  114. deviceName () {
  115. return this.device?.name
  116. },
  117. activeComponent () {
  118. switch (this.active) {
  119. case 'info':
  120. return 'DeviceInfo'
  121. case 'status':
  122. return 'DeviceStatus'
  123. case 'alarm':
  124. return 'DeviceAlarm'
  125. case 'invoke':
  126. return 'DeviceInvoke'
  127. case 'screen':
  128. return 'ReceivingCard'
  129. default:
  130. return ''
  131. }
  132. }
  133. },
  134. watch: {
  135. deviceId () {
  136. stop()
  137. this.active = 'info'
  138. this.device = null
  139. this.getDevice()
  140. }
  141. },
  142. created () {
  143. this.getDevice()
  144. },
  145. beforeDestroy () {
  146. stop()
  147. },
  148. methods: {
  149. getDevice () {
  150. this.loading = true
  151. const id = this.deviceId
  152. getDevice(id).then(({ data }) => {
  153. if (this.deviceId === id) {
  154. if (data) {
  155. this.device = data
  156. this.isActivated = data.activate === 2
  157. this.isOnline = this.isActivated && data.onlineStatus === 1
  158. if (!this.isOnline) {
  159. ScreenshotCache.remove(id)
  160. }
  161. start(this.device)
  162. addListener('online', this.onUpdate)
  163. } else {
  164. // this.error = false
  165. this.$message({
  166. type: 'warning',
  167. message: '设备不存在'
  168. })
  169. this.$router.replace({
  170. name: 'device-list'
  171. })
  172. }
  173. }
  174. }).finally(() => {
  175. if (this.deviceId === id) {
  176. this.loading = false
  177. }
  178. })
  179. },
  180. onUpdate (online) {
  181. this.isActivated = true
  182. this.isOnline = online
  183. if (!this.isOnline) {
  184. ScreenshotCache.remove(this.deviceId)
  185. }
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .c-detail {
  192. &__header {
  193. background-color: #fff;
  194. }
  195. &__wrapper {
  196. border-radius: $radius;
  197. background-color: #fff;
  198. }
  199. }
  200. .o-name {
  201. color: $black;
  202. font-size: 20px;
  203. font-weight: bold;
  204. }
  205. .o-status {
  206. display: inline-block;
  207. padding: 4px 8px;
  208. color: #fff;
  209. font-size: 16px;
  210. line-height: 1;
  211. border-radius: 4px;
  212. background-color: $success--dark;
  213. &.primary {
  214. background-color: $primary;
  215. }
  216. &.error {
  217. background-color: $error;
  218. }
  219. &.warning {
  220. background: $warning;
  221. }
  222. }
  223. </style>