detail.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="detail">
  3. <nav-bar></nav-bar>
  4. <van-cell-group>
  5. <van-cell :title="info.deviceName" value-class="cell-title-value" title-style="width:100%;">
  6. <template #right-icon v-if="info.time">
  7. <van-tag v-if="info.endTime">告警结束</van-tag>
  8. <van-tag v-else type="danger">正在告警</van-tag>
  9. </template>
  10. </van-cell>
  11. <van-cell title="所属机构" :value="info.orgName" />
  12. <van-cell title="告警分类" :value="dataTypeText"></van-cell>
  13. <van-cell title="告警类型" :value="info.sourceTypeDes"></van-cell>
  14. <van-cell title="告警开始时间" :value="renderTime(info.time)"></van-cell>
  15. <van-cell title="告警结束时间" :value="renderTime(info.endTime)"></van-cell>
  16. <van-cell title="持续时长" :value="durationText" />
  17. <van-cell title="告警值" :value="valueText" />
  18. <van-cell title="告警内容" :value="info.content" />
  19. </van-cell-group>
  20. </div>
  21. </template>
  22. <script>
  23. import { detail } from '@/api/iot/alarmCenter.js'
  24. import NavBar from '@/components/NavBar'
  25. import dayjs from 'dayjs'
  26. import { durationText } from '@/utils/date.js'
  27. export default {
  28. data() {
  29. return {
  30. info: {},
  31. search: {
  32. sensorId: this.$route.query.id
  33. }
  34. }
  35. },
  36. components: { NavBar },
  37. computed: {
  38. stateUpdateTimeText() {
  39. if (this.info.stateUpdateTime == null) {
  40. return '未上报'
  41. }
  42. return dayjs(this.info.stateUpdateTime).format('YYYY年M月D日H时m分')
  43. },
  44. dataTypeText() {
  45. if (!this.info || this.info.dataType == null) {
  46. return ''
  47. }
  48. if (this.info.dataType == '0') {
  49. return '动环类告警'
  50. } else if (this.info.dataType == '1') {
  51. return '视频类告警'
  52. } else {
  53. return '未知'
  54. }
  55. },
  56. durationText() {
  57. let endTime = this.info.endTime ? this.info.endTime : new Date()
  58. let minutes = dayjs(endTime).diff(this.info.time, 'minute')
  59. if (minutes < 1) {
  60. return dayjs(endTime).diff(this.info.time, 'second') + '秒'
  61. } else {
  62. return durationText(minutes)
  63. }
  64. },
  65. valueText() {
  66. if (!this.info || this.info.valueText == null) {
  67. return ''
  68. }
  69. return `${this.info.valueText}${this.info.alarmValue ? this.info.alarmValue : ''}`
  70. }
  71. },
  72. mounted() {
  73. this.getInfo()
  74. },
  75. methods: {
  76. getInfo() {
  77. detail(this.search.sensorId).then(r => {
  78. this.info = r.data
  79. })
  80. },
  81. renderTime(dateTime) {
  82. if (!dateTime) {
  83. return ''
  84. }
  85. return dayjs(dateTime).format('YYYY年M月D日H时m分')
  86. },
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .cell-title-value {
  92. display: none;
  93. }
  94. .detail {
  95. margin: 15px;
  96. }
  97. .cell-gather-alarm-value {
  98. color: #ee0a24;
  99. }
  100. </style>