index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 DeviceExternal from './components/DeviceExternal'
  78. import Sensors from './components/external/Sensors'
  79. import DeviceTakeOver from './components/DeviceTakeOver'
  80. export default {
  81. name: 'DeviceDetail',
  82. components: {
  83. DeviceInfo,
  84. DeviceRuntime,
  85. DeviceAlarm,
  86. DeviceInvoke,
  87. DeviceExternal,
  88. Sensors,
  89. DeviceTakeOver
  90. },
  91. data () {
  92. return {
  93. useDashboard: __DEVICE_DASHBARD__,
  94. loading: true,
  95. device: null,
  96. isActivated: false,
  97. isOnline: false,
  98. active: 'DeviceInfo',
  99. tabs: [
  100. { key: 'DeviceInfo', label: '设备信息' },
  101. { key: 'DeviceRuntime', label: '运行状态' },
  102. { key: 'DeviceAlarm', label: '设备告警' },
  103. this.accessSet.has(Access.MANAGE_DEVICE) ? { key: 'DeviceInvoke', label: '设备操控' } : null,
  104. __SENSOR__ ? { key: 'Sensors', label: '传感器' } : null,
  105. { key: 'DeviceExternal', label: '全链路监测' },
  106. this.accessSet.has(Access.MANAGE_GROUP) ? { key: 'DeviceTakeOver', label: '接管' } : null
  107. ].filter(Boolean)
  108. }
  109. },
  110. computed: {
  111. deviceId () {
  112. return this.$route.params.id
  113. },
  114. statusType () {
  115. return this.isActivated
  116. ? this.isOnline
  117. ? 'success'
  118. : 'error'
  119. : this.device.activate
  120. ? 'primary'
  121. : 'warning'
  122. },
  123. statusTip () {
  124. return this.isActivated
  125. ? this.isOnline
  126. ? '在线'
  127. : '离线'
  128. : this.device.activate
  129. ? '已激活'
  130. : '未激活'
  131. },
  132. deviceName () {
  133. return this.device?.name
  134. }
  135. },
  136. watch: {
  137. deviceId () {
  138. stop()
  139. this.active = 'DeviceInfo'
  140. this.device = null
  141. this.getDevice()
  142. }
  143. },
  144. created () {
  145. this.getDevice()
  146. },
  147. beforeDestroy () {
  148. stop()
  149. },
  150. methods: {
  151. onBack () {
  152. console.log(this.$route.name)
  153. switch (this.$route.name) {
  154. case 'device-management-detail':
  155. this.$router.replace({
  156. name: 'device-management'
  157. })
  158. break
  159. default:
  160. this.$router.replace({
  161. name: 'device-list'
  162. })
  163. break
  164. }
  165. },
  166. getDevice () {
  167. this.loading = true
  168. const id = this.deviceId
  169. getDevice(id).then(({ data }) => {
  170. if (this.deviceId === id) {
  171. if (data) {
  172. this.device = data
  173. this.isActivated = data.activate === 2
  174. this.isOnline = this.isActivated && data.onlineStatus === 1
  175. if (!this.isOnline) {
  176. ScreenshotCache.remove(id)
  177. }
  178. start(this.device)
  179. addListener('online', this.onUpdate)
  180. } else {
  181. this.$message({
  182. type: 'warning',
  183. message: '设备不存在'
  184. })
  185. this.onBack()
  186. }
  187. }
  188. }).finally(() => {
  189. if (this.deviceId === id) {
  190. this.loading = false
  191. }
  192. })
  193. },
  194. onUpdate (online) {
  195. this.isActivated = true
  196. this.isOnline = online
  197. if (!this.isOnline) {
  198. ScreenshotCache.remove(this.deviceId)
  199. }
  200. },
  201. onDashboard () {
  202. this.$router.push({
  203. name: 'device-dashboard',
  204. params: { id: this.deviceId }
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .c-detail {
  212. &__header {
  213. background-color: #fff;
  214. }
  215. &__wrapper {
  216. border-radius: $radius;
  217. background-color: #fff;
  218. }
  219. &__dashboard {
  220. font-size: 24px;
  221. }
  222. &__status {
  223. display: inline-block;
  224. padding: 4px 8px;
  225. color: #fff;
  226. font-size: 16px;
  227. line-height: 1;
  228. border-radius: $radius--mini;
  229. background-color: $success--dark;
  230. &.primary {
  231. background-color: $primary;
  232. }
  233. &.error {
  234. background-color: $error;
  235. }
  236. &.warning {
  237. background: $warning;
  238. }
  239. }
  240. &__name {
  241. color: $black;
  242. font-size: 20px;
  243. line-height: 1;
  244. }
  245. }
  246. </style>
  247. <style lang="scss">
  248. .o-device-grid-item {
  249. height: 180px;
  250. padding: 12px 16px 16px;
  251. color: $info;
  252. font-size: 14px;
  253. line-height: 1;
  254. &__large {
  255. font-size: 18px;
  256. }
  257. &__largest {
  258. font-size: 32px;
  259. }
  260. &__icon {
  261. margin-right: 8px;
  262. }
  263. }
  264. </style>