Sensor.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="l-flex--col o-status o-senser">
  3. <div class="l-flex--row l-flex__none">
  4. <i
  5. class="l-flex__none o-status__icon"
  6. :class="type"
  7. />
  8. <span class="l-flex__fill o-status__title u-ellipsis">{{ title }}</span>
  9. </div>
  10. <div class="l-flex--row center l-flex__fill large u-color--black u-bold">
  11. <div
  12. class="u-text-center"
  13. :style="{ color: tipColor }"
  14. >
  15. {{ tip }}
  16. <div
  17. v-if="sensor"
  18. class="o-senser__current"
  19. >
  20. {{ sensor }}
  21. </div>
  22. </div>
  23. </div>
  24. <div
  25. v-for="item in more"
  26. :key="item.key"
  27. class="l-flex__none l-flex--row o-senser__more"
  28. >
  29. <div class="l-flex__none">{{ item.time }}</div>
  30. <div class="l-flex__none o-senser__name">传感器{{ item.key }}</div>
  31. <div class="l-flex__fill o-senser__value">{{ item.value }}</div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import {
  37. addListener,
  38. removeListener
  39. } from '../monitor'
  40. export default {
  41. props: {
  42. type: {
  43. type: String,
  44. default: ''
  45. },
  46. title: {
  47. type: String,
  48. default: ''
  49. },
  50. color: {
  51. type: String,
  52. default: ''
  53. }
  54. },
  55. data () {
  56. return {
  57. list: []
  58. }
  59. },
  60. computed: {
  61. tipColor () {
  62. return this.list.length ? this.color : ''
  63. },
  64. tip () {
  65. return this.list.length ? this.list[0].value : '未知'
  66. },
  67. sensor () {
  68. return this.list.length
  69. ? this.list.length === 1
  70. ? this.list[0].time
  71. : `${this.list[0].time} 传感器${this.list[0].key}`
  72. : null
  73. },
  74. more () {
  75. return this.list.length > 1 ? this.list.slice(1, 3) : []
  76. }
  77. },
  78. created () {
  79. addListener(this.type, this.onUpdate)
  80. },
  81. beforeDestroy () {
  82. removeListener(this.type, this.onUpdate)
  83. },
  84. methods: {
  85. onUpdate (list) {
  86. this.list = list
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .o-senser {
  93. padding: 12px 16px 16px;
  94. line-height: 1;
  95. &__current {
  96. margin-top: 6px;
  97. color: #d5d9e4;
  98. font-size: 12px;
  99. }
  100. &__more {
  101. padding: 8px 0;
  102. color: #8e929c;
  103. font-size: 14px;
  104. border-bottom: 1px solid #edf0f6;
  105. }
  106. &__name {
  107. margin: 0 16px 0 24px;
  108. }
  109. &__value {
  110. text-align: right;
  111. }
  112. }
  113. </style>