Browse Source

客服消息

chenjj 3 months ago
parent
commit
428f28586f
2 changed files with 516 additions and 509 deletions
  1. 6 1
      src/views/message/WebSocketClient.js
  2. 510 508
      src/views/message/index.vue

+ 6 - 1
src/views/message/WebSocketClient.js

@@ -3,6 +3,7 @@ class WebSocketClient {
     constructor(userId, options = {}) {
       this.system = '3';
       this.userId = userId;
+      // import.meta.env.VITE_APP_BASE_API
       const baseURL = 'http://192.168.100.128:9527';
       // const baseURL = 'https://goldshulin.com/prod-api';
       const url = baseURL.split('/')[2];
@@ -22,6 +23,8 @@ class WebSocketClient {
       this.messageCallbacks = new Map()
       this.isConnected = false
       this.isReconnecting = false
+
+      this.reconnectCount = 0;
     }
   
     // 连接WebSocket
@@ -76,10 +79,12 @@ class WebSocketClient {
     reconnect() {
       if (this.isReconnecting) return
       
+      
       this.isReconnecting = true
       this.reconnectTimer = setTimeout(() => {
         console.log('尝试重新连接...')
-        this.connect()
+        this.reconnectCount = this.reconnectCount + 1;
+        this.reconnectCount <3 && this.connect()
       }, this.options.reconnectInterval)
     }
   

File diff suppressed because it is too large
+ 510 - 508
src/views/message/index.vue