index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. label="设备信息"
  27. name="info"
  28. />
  29. <!-- <el-tab-pane
  30. label="运行状态"
  31. name="status"
  32. /> -->
  33. </el-tabs>
  34. </template>
  35. <el-result
  36. v-if="!loading && !device"
  37. icon="warning"
  38. >
  39. <template #extra>
  40. <el-link
  41. class="u-pointer"
  42. type="warning"
  43. @click="getDevice"
  44. >
  45. 出错了,点击重试
  46. </el-link>
  47. </template>
  48. </el-result>
  49. </div>
  50. <div class="l-flex--col l-flex__fill has-padding">
  51. <div class="l-flex__fill c-detail__wrapper has-padding u-overflow-y--auto">
  52. <component
  53. :is="activeComponent"
  54. v-if="device"
  55. :device="device"
  56. />
  57. </div>
  58. </div>
  59. </wrapper>
  60. </template>
  61. <script>
  62. import {
  63. getDevice
  64. } from '@/api/device'
  65. import DeviceInfo from './components/DeviceInfo'
  66. export default {
  67. name: 'DeviceDetail',
  68. components: {
  69. DeviceInfo
  70. },
  71. data () {
  72. return {
  73. loading: true,
  74. device: null,
  75. active: 'info'
  76. }
  77. },
  78. computed: {
  79. isActivated () {
  80. return this.device?.activate === 2
  81. },
  82. isOnline () {
  83. return this.device?.onlineStatus === 1
  84. },
  85. statusType () {
  86. return this.isActivated
  87. ? this.isOnline
  88. ? 'success'
  89. : 'error'
  90. : this.device.activate
  91. ? 'primary'
  92. : 'warning'
  93. },
  94. statusTip () {
  95. return this.isActivated
  96. ? this.isOnline
  97. ? '在线'
  98. : '离线'
  99. : this.device.activate
  100. ? '已激活'
  101. : '未激活'
  102. },
  103. deviceName () {
  104. return this.device?.name
  105. },
  106. activeComponent () {
  107. switch (this.active) {
  108. case 'info':
  109. return 'DeviceInfo'
  110. default:
  111. return ''
  112. }
  113. }
  114. },
  115. created () {
  116. this.getDevice()
  117. },
  118. beforeRouteUpdate (to, from, next) {
  119. this.getDevice()
  120. next()
  121. },
  122. methods: {
  123. getDevice () {
  124. this.loading = true
  125. getDevice(this.$route.params.id).then(({ data }) => {
  126. this.device = data
  127. }).finally(() => {
  128. this.loading = false
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .c-detail {
  136. &__header {
  137. background-color: #fff;
  138. }
  139. &__wrapper {
  140. border-radius: $radius;
  141. background-color: #fff;
  142. }
  143. }
  144. .o-name {
  145. color: $black;
  146. font-size: 20px;
  147. font-weight: bold;
  148. }
  149. .o-status {
  150. display: inline-block;
  151. padding: 4px 8px;
  152. color: #fff;
  153. font-size: 16px;
  154. line-height: 1;
  155. border-radius: 4px;
  156. background-color: $success--dark;
  157. &.primary {
  158. background-color: $primary;
  159. }
  160. &.error {
  161. background-color: $error;
  162. }
  163. &.warning {
  164. background: $warning;
  165. }
  166. }
  167. </style>