index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 padding"
  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. @click="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="active"
  45. :key="active"
  46. class="l-flex__fill c-detail__wrapper has-padding u-overflow-y--auto"
  47. :device="device"
  48. :online="isOnline"
  49. />
  50. </keep-alive>
  51. </div>
  52. </wrapper>
  53. </template>
  54. <script>
  55. import { getDevice } from '@/api/device'
  56. import { Access } from '@/constant'
  57. import { ScreenshotCache } from '@/utils/cache'
  58. import {
  59. start,
  60. stop,
  61. addListener
  62. } from './monitor'
  63. import DeviceInfo from './components/DeviceInfo'
  64. import DeviceRuntime from './components/DeviceRuntime'
  65. import DeviceAlarm from './components/DeviceAlarm'
  66. import DeviceInvoke from './components/DeviceInvoke'
  67. import LinkState from './components/LinkState'
  68. import Sensors from './components/external/Sensors'
  69. import Transmitter from './components/external/Transmitter'
  70. import ReceivingCard from './components/external/ReceivingCard'
  71. import camera from './../../external/camera'
  72. export default {
  73. name: 'DeviceDetail',
  74. components: {
  75. DeviceInfo,
  76. DeviceRuntime,
  77. DeviceAlarm,
  78. DeviceInvoke,
  79. LinkState,
  80. Sensors,
  81. Transmitter,
  82. ReceivingCard,
  83. camera
  84. },
  85. data () {
  86. return {
  87. loading: true,
  88. device: null,
  89. isActivated: false,
  90. isOnline: false,
  91. active: 'DeviceInfo',
  92. tabs: [
  93. { key: 'DeviceInfo', label: '设备信息' },
  94. { key: 'DeviceRuntime', label: '运行状态' },
  95. { key: 'DeviceAlarm', label: '设备告警' },
  96. this.accessSet.has(Access.MANAGE_DEVICE) ? { key: 'DeviceInvoke', label: '设备操控' } : null,
  97. this.accessSet.has(Access.VIEW_SENSORS) ? { key: 'Sensors', label: '传感器' } : null,
  98. __STAGING__ ? { key: 'Transmitter', label: '发送控制设备' } : null,
  99. __STAGING__ ? { key: 'ReceivingCard', label: '接收卡' } : null,
  100. __STAGING__ ? { key: 'LinkState', label: '全链路监测状态' } : null,
  101. __STAGING__ ? { key: 'camera', label: '摄像头' } : null
  102. ].filter(val => val)
  103. }
  104. },
  105. computed: {
  106. deviceId () {
  107. return this.$route.params.id
  108. },
  109. statusType () {
  110. return this.isActivated
  111. ? this.isOnline
  112. ? 'success'
  113. : 'error'
  114. : this.device.activate
  115. ? 'primary'
  116. : 'warning'
  117. },
  118. statusTip () {
  119. return this.isActivated
  120. ? this.isOnline
  121. ? '在线'
  122. : '离线'
  123. : this.device.activate
  124. ? '已激活'
  125. : '未激活'
  126. },
  127. deviceName () {
  128. return this.device?.name
  129. }
  130. },
  131. watch: {
  132. deviceId () {
  133. stop()
  134. this.active = 'info'
  135. this.device = null
  136. this.getDevice()
  137. }
  138. },
  139. created () {
  140. this.getDevice()
  141. },
  142. beforeDestroy () {
  143. stop()
  144. },
  145. methods: {
  146. getDevice () {
  147. this.loading = true
  148. const id = this.deviceId
  149. getDevice(id).then(({ data }) => {
  150. if (this.deviceId === id) {
  151. if (data) {
  152. this.device = data
  153. this.isActivated = data.activate === 2
  154. this.isOnline = this.isActivated && data.onlineStatus === 1
  155. if (!this.isOnline) {
  156. ScreenshotCache.remove(id)
  157. }
  158. start(this.device)
  159. addListener('online', this.onUpdate)
  160. } else {
  161. this.$message({
  162. type: 'warning',
  163. message: '设备不存在'
  164. })
  165. this.$router.replace({
  166. name: 'device-list'
  167. })
  168. }
  169. }
  170. }).finally(() => {
  171. if (this.deviceId === id) {
  172. this.loading = false
  173. }
  174. })
  175. },
  176. onUpdate (online) {
  177. this.isActivated = true
  178. this.isOnline = online
  179. if (!this.isOnline) {
  180. ScreenshotCache.remove(this.deviceId)
  181. }
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .c-detail {
  188. &__header {
  189. background-color: #fff;
  190. }
  191. &__wrapper {
  192. border-radius: $radius;
  193. background-color: #fff;
  194. }
  195. }
  196. .o-name {
  197. color: $black;
  198. font-size: 20px;
  199. font-weight: bold;
  200. }
  201. .o-status {
  202. display: inline-block;
  203. padding: 4px 8px;
  204. color: #fff;
  205. font-size: 16px;
  206. line-height: 1;
  207. border-radius: 4px;
  208. background-color: $success--dark;
  209. &.primary {
  210. background-color: $primary;
  211. }
  212. &.error {
  213. background-color: $error;
  214. }
  215. &.warning {
  216. background: $warning;
  217. }
  218. }
  219. </style>
  220. <style lang="scss">
  221. .o-device-grid-item {
  222. height: 180px;
  223. padding: 12px 16px 16px;
  224. color: $info;
  225. font-size: 14px;
  226. line-height: 1;
  227. &__large {
  228. font-size: 18px;
  229. }
  230. &__largest {
  231. font-size: 32px;
  232. }
  233. &__icon {
  234. margin-right: 8px;
  235. }
  236. }
  237. </style>