RealtimeData.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div v-loading="loading">
  3. <div style="font-size: 26px;font-weight: bolder;padding: 8px 0">实时数据展示</div>
  4. <div id="aaa">
  5. <el-table
  6. :data="points"
  7. style="width: 100%">
  8. <!--{ mqtt: '', type: '开关量输入', desc: '电动调节阀停', value: null, datetime: '', dataType: '' }-->
  9. <el-table-column
  10. type="index"
  11. :index="index => index + 1"/>
  12. <el-table-column
  13. prop="mqtt"
  14. label="标签"
  15. width="130"
  16. align="center"
  17. />
  18. <el-table-column
  19. prop="type"
  20. label="类型"
  21. width="130"
  22. align="center"
  23. />
  24. <el-table-column
  25. prop="desc"
  26. label="中文"
  27. width="180"
  28. align="center"
  29. />
  30. <el-table-column
  31. prop="value"
  32. label="值"
  33. align="center"
  34. >
  35. <template slot-scope="scope">
  36. <div class="tag-value">{{ scope.row.value }}</div>
  37. </template>
  38. </el-table-column>
  39. <el-table-column
  40. prop="datetime"
  41. label="时间"
  42. align="center"
  43. />
  44. <el-table-column
  45. prop="dataType"
  46. label="数据类型"
  47. align="center"
  48. />
  49. </el-table>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import { mapState, mapMutations } from 'vuex'
  55. export default {
  56. name: 'RealtimeData',
  57. data () {
  58. return {
  59. loading: false,
  60. logs: [],
  61. }
  62. },
  63. computed: {
  64. ...mapState({
  65. test: (state, getter) => {
  66. return state.tag.test
  67. },
  68. count: (state, getter) => state.tag.count,
  69. points: (state, getter) => {
  70. const arr = []
  71. for (const key in state.tag.points) {
  72. arr.push({
  73. tag: key,
  74. ...state.tag.points[key]
  75. })
  76. }
  77. return arr
  78. },
  79. }),
  80. },
  81. mounted () {
  82. this.tagValueChange()
  83. },
  84. methods: {
  85. ...mapMutations(['SET_POINT_VALUE']),
  86. tagValueChange() {
  87. //选择一个需要观察的节点
  88. const mqtt = document.getElementById('aaa')
  89. // 设置observer的配置选项
  90. const config = { childList: true, subtree: true, attributes: true, characterData: true }
  91. const observer = new MutationObserver((mutationRecords, observer) => {
  92. mutationRecords.forEach(mutation => {
  93. const data = Number(mutation.target.data)
  94. if (mutation.type === 'characterData' && data + '' !== 'NaN') {
  95. // console.log('mutation change in ', mutation.type, ' name: ', mutation.target.data)
  96. mutation.target.parentNode.style.color = 'red'
  97. const timeout = setTimeout(() => {
  98. mutation.target.parentNode.style.color = '#606266'
  99. clearTimeout(timeout)
  100. }, 1500)
  101. }
  102. })
  103. })
  104. //使用配置文件对目标节点进行观测
  105. observer.observe(tag, config)
  106. // 停止观测
  107. // observer.disconnect()
  108. }
  109. },
  110. }
  111. </script>
  112. <style lang="less" scoped>
  113. </style>