index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <van-row class="recordList">
  3. <van-row class="titleWrap">
  4. <span class="line"></span>
  5. <span class="title">设备告警信息</span>
  6. </van-row>
  7. <el-table ref="initList" :data="initList" height="180px" highlight-current-row :header-cell-style="{background:'#F5F5F5',color:'#000','font-weight':'400'}" class="table">
  8. <el-table-column label="告警时间" prop="alarmTime" show-overflow-tooltip min-width="35%" />
  9. <el-table-column label="告警内容" prop="property" show-overflow-tooltip min-width="25%" />
  10. <el-table-column label="告警类型" prop="deviceTypeName" show-overflow-tooltip min-width="25%" />
  11. <!-- <el-table-column label="状态" prop="alarmStatus" show-overflow-tooltip min-width="15%" >
  12. <template slot-scope="scope">
  13. <span :class="scope.row.alarmStatus == '1' ? 'color8' : 'color1'">{{scope.row.alarmStatus == "1" ? "已处理" : "未处理"}}</span>
  14. </template>
  15. </el-table-column> -->
  16. </el-table>
  17. </van-row>
  18. </template>
  19. <script>
  20. import axios from 'axios'
  21. import { YearMonthDate } from "@/assets/js/dataFormate.js";
  22. export default {
  23. data() {
  24. return {
  25. initList:[
  26. // {alarmTime:'2022-05-10 12:33:53',property:'故障',deviceType:1,deviceTypeName:'1层监控室用户信息传输装置',deviceId:'74869'},
  27. // {alarmTime:'2022-05-08 00:30:40',property:'故障',deviceType:1,deviceTypeName:'1层监控室用户信息传输装置',deviceId:'74869'},
  28. // {alarmTime:'2022-03-13 08:06:01',property:'故障',deviceType:1,deviceTypeName:'1层监控室用户信息传输装置',deviceId:'74869'},
  29. // {alarmTime:'2022-03-10 19:41:23',property:'故障',deviceType:1,deviceTypeName:'1层监控室用户信息传输装置',deviceId:'74869'},
  30. // {alarmTime:'2022-03-05 03:12:21',property:'故障',deviceType:1,deviceTypeName:'1层监控室用户信息传输装置',deviceId:'74869'}
  31. ],
  32. table_interval:null,
  33. };
  34. },
  35. created(){
  36. this.initData();
  37. },
  38. mounted() {},
  39. methods: {
  40. //初始化数据
  41. initData() {
  42. //
  43. axios({
  44. method: 'post',
  45. url: 'https://smartpark.caih.com/dmapi/tbAlarm/page',
  46. timeout: 3000,
  47. data:{
  48. startTime:YearMonthDate().split(" ")[0] + " 00:00:00",
  49. endTime:YearMonthDate(),
  50. current:1,
  51. size:500,
  52. type:1
  53. }
  54. }).then(res =>{
  55. this.initList = res.data.data.records
  56. })
  57. let that = this
  58. let num = 0
  59. if ("WebSocket" in window) {
  60. this.ws = new WebSocket("ws://10.21.39.1:8084/dm/alarmPush");
  61. this.ws.onopen = ()=> {
  62. // console.log("websocket连接成功");
  63. this.sendWs({agentid:'admin'});
  64. };
  65. this.ws.onmessage = (res) => { //接收websocket消息
  66. let warningInfo = JSON.parse(res.data)
  67. if(warningInfo.property != "火警" && warningInfo.property != "故障"){
  68. that.initList.push(warningInfo)
  69. }
  70. if(num == '0'){
  71. if(that.initList.length>2){
  72. that.dataScrolling();
  73. num = 1
  74. }
  75. }
  76. };
  77. this.ws.onclose = ()=> { //关闭websocket
  78. // 关闭 websocket
  79. //console.log("连接已关闭...");
  80. //断线重新连接
  81. setTimeout(() => {
  82. this.initData();
  83. }, 2000);
  84. }
  85. } else {
  86. // 浏览器不支持 WebSocket
  87. alert("您的浏览器不支持 WebSocket!");
  88. }
  89. // that.dataScrolling();
  90. },
  91. sendWs(val){
  92. if (this.ws && this.ws.readyState == 1) {
  93. this.ws.send(JSON.stringify(val));
  94. // console.log('发送成功')
  95. } else {
  96. setTimeout(() => {
  97. this.sendWs(val);
  98. }, 100);
  99. }
  100. },
  101. //数据滚动
  102. dataScrolling:function(){
  103. let top=this.$refs.initList.bodyWrapper;
  104. this.table_interval=setInterval(() => {
  105. top.scrollTop+=1;
  106. if(top.clientHeight+top.scrollTop==top.scrollHeight){
  107. top.scrollTop=0;
  108. }
  109. }, 100);
  110. },
  111. //鼠标进入,停止滚动
  112. mouseEnter:function(){
  113. clearInterval(this.table_interval);
  114. this.table_interval=null;
  115. },
  116. timing(){
  117. setInterval(() =>{
  118. this.initList = []
  119. },1000 * 60 * 10)
  120. },
  121. },
  122. };
  123. </script>
  124. <style lang="scss" scoped></style>