瀏覽代碼

jeecg式websocket

yuhan 1 年之前
父節點
當前提交
d913bad1c7
共有 1 個文件被更改,包括 18 次插入4 次删除
  1. 18 4
      src/views/modules_guAn/visualization/index.vue

+ 18 - 4
src/views/modules_guAn/visualization/index.vue

@@ -80,6 +80,8 @@ import TestStatusInfo from './modules/TestStatusInfo.vue'
 
 import { getAction } from '@/api/manage'
 import store from '@/store'
+import Vue from 'vue'
+  import { ACCESS_TOKEN } from '@/store/mutation-types'
 
 export default {
   name: '',
@@ -98,7 +100,8 @@ export default {
   },
   data () {
     return {
-      dataAll: []
+      dataAll: [],
+      websock: null,
     }
   },
   destroyed () {
@@ -130,10 +133,21 @@ export default {
     // websocket
     initWebSocket () { // 初始化weosocket(必须)
       // 请根据实际项目需要进行修改
-      var userId = store.getters.userInfo.id
-      const wsuri = `ws://192.168.2.247:8866/websocket/${userId}`
+      // var userId = store.getters.userInfo.id
+      // const wsuri = 'ws://127.0.0.1:8866/websocket'
+      // const wsuri = `ws://192.168.2.216:8866/websocket/${userId}`
+      // const wsuri = `ws://192.168.2.247:8866/websocket/${userId}`
+      // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
+      var userId = store.getters.userInfo.id;
+      var url = window._CONFIG['domianURL'].replace("https://","wss://").replace("http://","ws://")+"/websocket/"+userId;
+      // var wsuri = 'ws://192.168.2.247:8866/websocket';
+      // console.log(wsuri);
+      //update-begin-author:taoyan date:2022-4-22 for:  v2.4.6 的 websocket 服务端,存在性能和安全问题。 #3278
+      let token = Vue.ls.get(ACCESS_TOKEN)
+      this.websock = new WebSocket(url, [token]);
+      // this.websock = new WebSocket(wsuri, [token]);
       // 新建一个webstock对象
-      this.websock = new WebSocket(wsuri)
+      // this.websock = new WebSocket(wsuri)
       this.websock.onmessage = this.websocketonmessage
       this.websock.onopen = this.websocketonopen
       this.websock.onerror = this.websocketonerror