scorpio il y a 2 ans
Parent
commit
ca59bad284
2 fichiers modifiés avec 30 ajouts et 7 suppressions
  1. 3 0
      src/config/website.js
  2. 27 7
      src/layout/top.vue

+ 3 - 0
src/config/website.js

@@ -7,6 +7,9 @@ export default {
   clientId: 'project_web', // 客户端id
   clientSecret: 'project_web_key', // 客户端密钥
   statusWhiteList: [],
+  wss: import.meta.env.DEV
+    ? 'ws://dev.wutongshucloud.com/ws/websocket/'
+    : 'wss://prod.wutongshucloud.com/ws/websocket/',
   reportTypes: [
     {
       label: '未备案/批复',

+ 27 - 7
src/layout/top.vue

@@ -27,9 +27,22 @@
           <div
             class="padding flex flex-align-center pointer"
             :class="dataType === 'project' ? 'black' : 'white'"
-            @click="show = true"
           >
-            <el-button icon="Search" circle color="#C1C4CB" />
+            <el-button
+              icon="Search"
+              circle
+              color="#C1C4CB"
+              @click="show = true"
+            />
+
+            <el-badge :value="2" :max="99" class="ml-20">
+              <el-button
+                icon="Bell"
+                circle
+                color="#C1C4CB"
+                @click="$router.push('/msg')"
+              />
+            </el-badge>
           </div>
           <div class="padding flex flex-align-center pointer">
             <el-avatar
@@ -87,6 +100,11 @@ export default {
   },
   data() {
     return {
+      lockReconnect: false, // 是否真正建立连接
+      timeout: 58 * 1000, // 58秒一次心跳
+      timeoutObj: null, // 心跳心跳倒计时
+      serverTimeoutObj: null, // 心跳倒计时
+      timeoutnum: null, // 断开 重连倒计时
       dataType: 'project',
       showImage: false,
       imgList: [],
@@ -142,14 +160,14 @@ export default {
         this.mini = false
       }
     })
-    // this.initWebSocket()
+    this.initWebSocket()
   },
   unmounted() {
     this.websock.close() // 离开路由之后断开websocket连接
   },
   methods: {
     initWebSocket() {
-      const wsuri = 'ws:192.168.31.83:8200/websocket/' + this.user.info.userId
+      const wsuri = config.wss + this.user.info.userId
       this.websock = new WebSocket(wsuri)
       this.websock.onmessage = this.websocketonmessage
       // 连接建立时触发
@@ -162,6 +180,7 @@ export default {
     websocketonopen() {
       // 开启心跳
       this.start()
+
       // 连接建立之后执行send方法发送数据
       // let actions = {"room":"007854ce7b93476487c7ca8826d17eba","info":"1121212"};
       // this.websocketsend(JSON.stringify(actions));
@@ -220,16 +239,17 @@ export default {
       self.serverTimeoutObj && clearTimeout(self.serverTimeoutObj)
       self.timeoutObj = setTimeout(function () {
         // 这里发送一个心跳,后端收到后,返回一个心跳消息,
-        if (self.ws.readyState === 1) {
+        console.log(self.websock)
+        if (self.websock.readyState === 1) {
           // 如果连接正常
-          // self.ws.send("heartCheck"); //这里可以自己跟后端约定
+          self.websock.send('heartCheck') // 这里可以自己跟后端约定
         } else {
           // 否则重连
           self.reconnect()
         }
         self.serverTimeoutObj = setTimeout(function () {
           // 超时关闭
-          self.ws.close()
+          self.websock.close()
         }, self.timeout)
       }, self.timeout)
     },