Преглед на файлове

Merge remote-tracking branch 'origin/visu_environment' into visu_environment

wangzhe преди 2 години
родител
ревизия
7e4c33ae06
променени са 1 файла, в които са добавени 104 реда и са изтрити 3 реда
  1. 104 3
      src/components/vBottomMenu.vue

+ 104 - 3
src/components/vBottomMenu.vue

@@ -394,7 +394,14 @@
 				filterchangList: [],
 				filterchangList: [],
 				filterchangListAll: [],
 				filterchangListAll: [],
 				eventId: null,
 				eventId: null,
-				eventCode: null,
+        websock: '',
+        wsuri:'ws://127.0.0.1:10012/messagePush/',
+        wsuri2:'ws://127.0.0.1:10005/taskPush/',
+        setIntervalWesocketPush: null,
+        websockSid: {
+          userId: ''
+        },
+        eventCode: null,
 				longitude: null,
 				longitude: null,
 				latitude: null,
 				latitude: null,
 				eventLogList: [], //事件详情日志
 				eventLogList: [], //事件详情日志
@@ -508,8 +515,100 @@
 				this.deptOptionsLiandong = response.data
 				this.deptOptionsLiandong = response.data
 			})
 			})
 		},
 		},
-		methods: {
-			filterbanNode(value, data) {
+    mounted() {
+      this.websockSid.userId=Cookies.get("userId")
+    },
+    methods: {
+      initWebSocket(wsurl,userId) {        //初始化weosocket
+        //const wsuri = 'ws://127.0.0.1:10003/eventPush/' + userId + '/' + eventTypeDl + '/' + eventType
+        const wsuri = wsurl+userId
+        // const wsuri = 'ws://172.28.20.82:10012/taskPush/'+userId
+        this.websock = new WebSocket(wsuri)
+        console.log('建立websocket连接'+wsuri)
+        this.websock.onopen = this.websocketonopen
+        this.websock.onmessage = this.websocketonmessage
+        this.websock.onerror = this.websocketonerror
+      },
+      websocketonopen() { //连接建立之后执行send方法发送数据
+        console.log('websocket连接成功')
+        this.weosocket = true
+        this.sendPing()
+      },
+      websocketonerror() { //连接建立失败重连
+        this.initWebSocket(this.wsuri,this.websockSid.userId)
+      },
+      websocketonmessage(e) { //数据接收
+        console.log('接收数据', e.data)
+        // let data = "{\"fromId\":\"farming\"}";
+        // 处理收到的消息
+        this.handleWebSoceketEvent(e.data)
+      },
+      handleWebSoceketEvent(val) {
+        let that = this
+        let data = JSON.parse(val)
+        console.log('数据数据数据数据',data)
+        /**
+         * that.markersList.filter( item => data.eventCode == item.parameter).length == 0 如果地图中不存在当前事件则添加
+         * eventPush: 事件列表消息
+         * */
+        let  message=data.centermessageTPushrecord
+        let message2=data.centertaskTTask
+        if (null!=message)
+        {
+          console.log(message)
+          this.messageList.push(message)
+          this.messageCount++
+        }else if (null!=message2)
+        {
+          this.taskList.push(message2)
+          this.taskCount ++
+        }
+
+
+
+        // if (data.tag == "eventPush" && that.markersList.filter( item => data.eventCode == item.parameter).length == 0) {
+        //   getEventPush({eventCode: data.eventCode}).then((res) => {
+        //     if (res.data != undefined) {
+        //       //插入到第一条
+        //       this.eventList.unshift(res.data)
+        //       // 插入后删除最后一条 保证列表中为10条数据
+        //       if (this.eventList.length > 9)
+        //         this.eventList.splice(10, 1)
+        //       // 将收到的数据在地图上添加
+        //       this.getWebSocketEvent(res.data)
+        //     }
+        //   })
+        // }
+
+        console.log(data)
+      },
+
+
+      websocketsend(Data) { //数据发送
+        this.websock.send(Data)
+      },
+      websocketclose(e) { //关闭
+        console.log('断开连接', e)
+        // clearInterval(this.setIntervalWesocketPush)
+        this.weosocket = false
+      },
+      /**发送心跳
+       * @param {number} time 心跳间隔毫秒 默认5000
+       * @param {string} ping 心跳名称 默认字符串ping
+       */
+      sendPing(time = 60000, ping = {
+        'fromId': 'farming'
+      }) {
+        clearInterval(this.setIntervalWesocketPush)
+        this.setIntervalWesocketPush = setInterval(() => {
+          if (this.weosocket) {
+            this.websock.send(JSON.stringify(ping))
+          } else {
+            // this.initWebSocket()
+          }
+        }, time)
+      },
+      filterbanNode(value, data) {
 				//树搜索
 				//树搜索
 				if (!value) return true
 				if (!value) return true
 				return data.label.indexOf(value) !== -1
 				return data.label.indexOf(value) !== -1
@@ -698,6 +797,7 @@
 					this.taskList = res.data
 					this.taskList = res.data
 					this.taskCount = res.data.length
 					this.taskCount = res.data.length
 				})
 				})
+        this.initWebSocket(this.wsuri2,this.websockSid.userId)
 			},
 			},
 
 
       selectMessageById(id) {
       selectMessageById(id) {
@@ -705,6 +805,7 @@
           /** 获取消息列表 */
           /** 获取消息列表 */
           this.selectMessageList();
           this.selectMessageList();
         });
         });
+        this.initWebSocket(this.wsuri,this.websockSid.userId)
       },
       },
       /** 获取消息列表 */
       /** 获取消息列表 */
       selectMessageList(){
       selectMessageList(){