浏览代码

websocket修改

王通 2 年之前
父节点
当前提交
06a9002213
共有 1 个文件被更改,包括 19 次插入14 次删除
  1. 19 14
      src/components/vBottomMenu.vue

+ 19 - 14
src/components/vBottomMenu.vue

@@ -498,8 +498,8 @@ export default {
       filterchang: '', //林场搜索
       btmCurrent: '',
       websock: '',
-      wsuri:'ws://127.0.0.1:10012/messagePush/',
-      wsuri2:'ws://127.0.0.1:10005/taskPush/',
+      wsurl:'',
+      postName:'',
       setIntervalWesocketPush: null,
       websockSid: {
         userId: ''
@@ -517,15 +517,20 @@ export default {
     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
+    initWebSocket(wsurl,postName,userId) {
+      this.postName=postName
+      this.wsurl=wsurl
+      selectConfigKey(wsurl).then(res => {
+        //初始化weosocket
+        //const wsuri = 'ws://127.0.0.1:10003/eventPush/' + userId + '/' + eventTypeDl + '/' + eventType
+        const wsuri = res.data + userId +postName+ 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连接成功')
@@ -533,7 +538,7 @@ export default {
       this.sendPing()
     },
     websocketonerror() { //连接建立失败重连
-      this.initWebSocket(this.wsuri,this.websockSid.userId)
+      this.initWebSocket(this.wsurl,this.postName,this.websockSid.userId)
     },
     websocketonmessage(e) { //数据接收
       console.log('接收数据', e.data)
@@ -795,7 +800,7 @@ export default {
         this.taskList = res.data
         this.taskCount = res.data.length
       })
-      this.initWebSocket(this.wsuri2,this.websockSid.userId)
+      this.initWebSocket('TASK_SOCKET','/taskPush/',this.websockSid.userId)
     },
     selectMessageById(id) {
       selectMessageById(id).then(response => {
@@ -815,7 +820,7 @@ export default {
         this.messageList = response.data
         this.messageCount = response.data.length
       });
-      this.initWebSocket(this.wsuri,this.websockSid.userId)
+      this.initWebSocket('MESSAGE_SOCKET','/messagePush/',this.websockSid.userId)
     },
     handleCheckedCitiesChangeBan(value) {
       this.choseLayerSwitchingList(this.banCheckList)