index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. <div class="l-flex--row has-padding">
  9. <i
  10. class="l-flex__none o-icon medium o-icon--back el-icon-arrow-left u-bold u-pointer"
  11. @click="onBack"
  12. />
  13. <template v-if="device">
  14. <i
  15. v-if="useDashboard"
  16. class="c-sibling-item c-detail__dashboard el-icon-full-screen has-active u-pointer"
  17. @click="onDashboard"
  18. />
  19. <span
  20. class="c-sibling-item c-detail__status"
  21. :class="statusType"
  22. >
  23. {{ statusTip }}
  24. </span>
  25. <auto-text
  26. class="c-sibling-item c-detail__name u-bold"
  27. :text="deviceName"
  28. />
  29. </template>
  30. </div>
  31. <el-tabs
  32. v-if="device"
  33. v-model="active"
  34. class="c-tabs padding"
  35. >
  36. <el-tab-pane
  37. v-for="tab in tabs"
  38. :key="tab.key"
  39. :label="tab.label"
  40. :name="tab.key"
  41. />
  42. </el-tabs>
  43. <warning
  44. v-else-if="!loading"
  45. @click="getDevice"
  46. />
  47. </div>
  48. <div
  49. v-if="device"
  50. class="l-flex--col l-flex__fill has-padding"
  51. >
  52. <keep-alive include="DeviceInfo">
  53. <component
  54. :is="active"
  55. :key="active"
  56. class="l-flex__fill c-detail__wrapper has-padding u-overflow-y--auto"
  57. :device="device"
  58. :online="isOnline"
  59. />
  60. </keep-alive>
  61. </div>
  62. </wrapper>
  63. </template>
  64. <script>
  65. import { getDevice } from '@/api/device'
  66. import { Access } from '@/constant'
  67. import { ScreenshotCache } from '@/utils/cache'
  68. import {
  69. start,
  70. stop,
  71. addListener
  72. } from './monitor'
  73. import DeviceInfo from './components/DeviceInfo'
  74. import DeviceRuntime from './components/DeviceRuntime'
  75. import DeviceAlarm from './components/DeviceAlarm'
  76. import DeviceInvoke from './components/DeviceInvoke'
  77. import LinkState from './components/LinkState'
  78. import Sensors from './components/external/Sensors'
  79. import Transmitter from './components/external/Transmitter'
  80. import ReceivingCard from './components/external/ReceivingCard'
  81. import Camera from './components/external/Camera'
  82. import Gateway from './components/external/Gateway'
  83. export default {
  84. name: 'DeviceDetail',
  85. components: {
  86. DeviceInfo,
  87. DeviceRuntime,
  88. DeviceAlarm,
  89. DeviceInvoke,
  90. LinkState,
  91. Sensors,
  92. Transmitter,
  93. ReceivingCard,
  94. Camera,
  95. Gateway
  96. },
  97. data () {
  98. return {
  99. useDashboard: __DEVICE_DASHBARD__,
  100. loading: true,
  101. device: null,
  102. isActivated: false,
  103. isOnline: false,
  104. active: 'DeviceInfo',
  105. tabs: [
  106. { key: 'DeviceInfo', label: '设备信息' },
  107. { key: 'DeviceRuntime', label: '运行状态' },
  108. { key: 'DeviceAlarm', label: '设备告警' },
  109. this.accessSet.has(Access.MANAGE_DEVICE) ? { key: 'DeviceInvoke', label: '设备操控' } : null,
  110. __SENSOR__ ? { key: 'Sensors', label: '传感器' } : null,
  111. __STAGING__ ? { key: 'LinkState', label: '全链路监测' } : null,
  112. __STAGING__ ? { key: 'Transmitter', label: '发送控制设备' } : null,
  113. __STAGING__ ? { key: 'ReceivingCard', label: '接收卡' } : null,
  114. __STAGING__ ? { key: 'Camera', label: '摄像头' } : null,
  115. __STAGING__ ? { key: 'Gateway', label: '网关' } : null
  116. ].filter(Boolean)
  117. }
  118. },
  119. computed: {
  120. deviceId () {
  121. return this.$route.params.id
  122. },
  123. statusType () {
  124. return this.isActivated
  125. ? this.isOnline
  126. ? 'success'
  127. : 'error'
  128. : this.device.activate
  129. ? 'primary'
  130. : 'warning'
  131. },
  132. statusTip () {
  133. return this.isActivated
  134. ? this.isOnline
  135. ? '在线'
  136. : '离线'
  137. : this.device.activate
  138. ? '已激活'
  139. : '未激活'
  140. },
  141. deviceName () {
  142. return this.device?.name
  143. }
  144. },
  145. watch: {
  146. deviceId () {
  147. stop()
  148. this.active = 'DeviceInfo'
  149. this.device = null
  150. this.getDevice()
  151. }
  152. },
  153. created () {
  154. this.getDevice()
  155. },
  156. beforeDestroy () {
  157. stop()
  158. },
  159. methods: {
  160. onBack () {
  161. console.log(this.$route.name)
  162. switch (this.$route.name) {
  163. case 'device-management-detail':
  164. this.$router.replace({
  165. name: 'device-management'
  166. })
  167. break
  168. default:
  169. this.$router.replace({
  170. name: 'device-list'
  171. })
  172. break
  173. }
  174. },
  175. getDevice () {
  176. this.loading = true
  177. const id = this.deviceId
  178. getDevice(id).then(({ data }) => {
  179. if (this.deviceId === id) {
  180. if (data) {
  181. this.device = data
  182. this.isActivated = data.activate === 2
  183. this.isOnline = this.isActivated && data.onlineStatus === 1
  184. if (!this.isOnline) {
  185. ScreenshotCache.remove(id)
  186. }
  187. start(this.device)
  188. addListener('online', this.onUpdate)
  189. } else {
  190. this.$message({
  191. type: 'warning',
  192. message: '设备不存在'
  193. })
  194. this.onBack()
  195. }
  196. }
  197. }).finally(() => {
  198. if (this.deviceId === id) {
  199. this.loading = false
  200. }
  201. })
  202. },
  203. onUpdate (online) {
  204. this.isActivated = true
  205. this.isOnline = online
  206. if (!this.isOnline) {
  207. ScreenshotCache.remove(this.deviceId)
  208. }
  209. },
  210. onDashboard () {
  211. this.$router.push({
  212. name: 'device-dashboard',
  213. params: { id: this.deviceId }
  214. })
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .c-detail {
  221. &__header {
  222. background-color: #fff;
  223. }
  224. &__wrapper {
  225. border-radius: $radius;
  226. background-color: #fff;
  227. }
  228. &__dashboard {
  229. font-size: 24px;
  230. }
  231. &__status {
  232. display: inline-block;
  233. padding: 4px 8px;
  234. color: #fff;
  235. font-size: 16px;
  236. line-height: 1;
  237. border-radius: $radius--mini;
  238. background-color: $success--dark;
  239. &.primary {
  240. background-color: $primary;
  241. }
  242. &.error {
  243. background-color: $error;
  244. }
  245. &.warning {
  246. background: $warning;
  247. }
  248. }
  249. &__name {
  250. color: $black;
  251. font-size: 20px;
  252. line-height: 1;
  253. }
  254. }
  255. </style>
  256. <style lang="scss">
  257. .o-device-grid-item {
  258. height: 180px;
  259. padding: 12px 16px 16px;
  260. color: $info;
  261. font-size: 14px;
  262. line-height: 1;
  263. &__large {
  264. font-size: 18px;
  265. }
  266. &__largest {
  267. font-size: 32px;
  268. }
  269. &__icon {
  270. margin-right: 8px;
  271. }
  272. }
  273. </style>