فهرست منبع

webSocket修改

王通 2 سال پیش
والد
کامیت
af06ab4bdc
1فایلهای تغییر یافته به همراه20 افزوده شده و 15 حذف شده
  1. 20 15
      src/components/vBottomMenu.vue

+ 20 - 15
src/components/vBottomMenu.vue

@@ -364,6 +364,7 @@ import {
 import supermapTaskDialog from '@/components/supermap' //超图
 import TcPlayer from '@/components/TcPlayer' //视频预览
 import Cookies from 'js-cookie'
+import { selectConfigKey } from '@/api/system/config'
 
 export default {
   components: {
@@ -495,10 +496,9 @@ export default {
 
       messageCount: 0, //消息数量
       messageList: 0,//消息列表
-
       websock: '',
-      wsuri:'ws://127.0.0.1:10012/messagePush/',
-      wsuri2:'ws://127.0.0.1:10005/taskPush/',
+      wsurl:'',
+      postName:'',
       setIntervalWesocketPush: null,
       websockSid: {
         userId: ''
@@ -518,15 +518,20 @@ export default {
         this.deptChangOptionsLiandong = response.data
       })
     },
-    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连接成功')
@@ -534,7 +539,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)
@@ -631,7 +636,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)
     },
     filterbanNode(value, data) {
       //树搜索
@@ -888,7 +893,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)
     },
     handleCheckedCitiesChangeBan(value) {
       this.choseLayerSwitchingList(this.banCheckList)