Browse Source

Merge branch 'master' of http://git.dashitech.com/seimin/zy-pc

maotao 4 months ago
parent
commit
c10fe29b59

+ 3 - 3
src/app/services/websocket-incoming.service.ts

@@ -2,7 +2,7 @@
2 2
  * @Author: seimin
3 3
  * @Date: 2024-09-24 16:34:47
4 4
  * @LastEditors: seimin
5
- * @LastEditTime: 2024-09-29 15:41:54
5
+ * @LastEditTime: 2024-11-28 03:12:59
6 6
  * @Description: 来电弹屏websocket服务
7 7
  */
8 8
 import { Injectable } from "@angular/core";
@@ -24,8 +24,8 @@ export class WebsocketIncomingService {
24 24
 
25 25
   // 连接websocket { userCount }
26 26
   private user = JSON.parse(localStorage.getItem("user")); //用户信息
27
-  connectWs(): Observable<any> {
28
-    let userCount = this.user.user.account + "|" + this.getPhoneNumber();
27
+  connectWs(phoneNumber): Observable<any> {
28
+    let userCount = this.user.user.account + "|" + phoneNumber;
29 29
     if(this.getSign() === 'box'){
30 30
       return this.phoneService.connectWs(http.phoneWs, { userCount });
31 31
     }

+ 18 - 3
src/app/services/websocket-phone.service.ts

@@ -2,7 +2,7 @@
2 2
  * @Author: seimin
3 3
  * @Date: 2024-03-11 11:11:09
4 4
  * @LastEditors: seimin
5
- * @LastEditTime: 2024-09-24 16:38:23
5
+ * @LastEditTime: 2024-11-28 03:03:38
6 6
  * @Description: 录音盒websocket服务
7 7
  */
8 8
 import { Injectable } from "@angular/core";
@@ -60,15 +60,17 @@ export class WebsocketPhoneService {
60 60
       console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
61 61
       this.ws = null;
62 62
       console.log(response)
63
-      if (!this.isHandler && response.status === 408) {
63
+      if (!this.isHandler && response.status === 408 && sessionStorage.getItem('phoneNumber')) {
64 64
         this.reconnect(this.url, this.urlParams);
65
+      }else{
66
+        this.updateProperty(false);
65 67
       }
66 68
     };
67 69
 
68 70
     request.onError = (response) => {
69 71
       console.log("ws连接错误", this.isHandler);
70 72
       this.ws = null;
71
-      if (response.status === 0) {
73
+      if (response.status === 0 && sessionStorage.getItem('phoneNumber')) {
72 74
         this.reconnect(this.url, this.urlParams);
73 75
       }
74 76
     };
@@ -119,4 +121,17 @@ export class WebsocketPhoneService {
119 121
       this.ws.close();
120 122
     }
121 123
   }
124
+
125
+  // 创建一个Subject来发送和接收数据
126
+  private updateData = new Subject<any>();
127
+
128
+  // 提供一个方法来发送数据
129
+  updateProperty(data: any) {
130
+    this.updateData.next(data);
131
+  }
132
+
133
+  // 提供一个方法来订阅数据
134
+  getDataUpdate(): Subject<any> {
135
+    return this.updateData;
136
+  }
122 137
 }

+ 1 - 1
src/app/views/fuwutai/fuwutai.component.html

@@ -926,7 +926,7 @@
926 926
           </button>
927 927
         </div>
928 928
       </div>
929
-      <div class="fixedMenu" *ngIf="!websocketLoading && !incomingService.getPhoneNumber()">
929
+      <div class="fixedMenu" *ngIf="!incomingService.getPhoneNumber()">
930 930
         <div class="menuItems">
931 931
           <button nz-button nzType="link" class="item itemLink" (click)="showBindExtensionNumber()">
932 932
             绑定分机

+ 26 - 12
src/app/views/fuwutai/fuwutai.component.ts

@@ -116,7 +116,12 @@ export class FuwutaiComponent implements OnInit {
116 116
     private http: HttpClient,
117 117
     public route: ActivatedRoute,
118 118
     public incomingService: WebsocketIncomingService,
119
-  ) {}
119
+  ) {
120
+    // 在组件中订阅服务的Observable
121
+    this.phones.getDataUpdate().subscribe(data => {
122
+      this.websocketLoading = data;
123
+    });
124
+  }
120 125
   validateFormZy!: FormGroup;
121 126
   validateFormQt!: FormGroup;
122 127
   // ---------------------------------------
@@ -804,6 +809,7 @@ export class FuwutaiComponent implements OnInit {
804 809
     TLWSA.onOpenreturn = (err) => {
805 810
       err = Number(err);
806 811
       if (!err) {
812
+        _this.incomingService.setPhoneNumber(TLWSA.phoneNumber);
807 813
         _this.websocketLoading = false;
808 814
         _this.cancelBindExtensionNumber();
809 815
         console.log('呼叫中心连接成功-----seimin');
@@ -888,12 +894,17 @@ export class FuwutaiComponent implements OnInit {
888 894
       clearTimeout(timer);
889 895
       if(location.hash === '#/dispatchingDesk'){
890 896
         console.log('与服务器网络连接中断-----seimin');
891
-        _this.msg.info('与服务器网络连接中断,2分钟后重连')
892
-        console.log('2分钟后自动重连-----seimin')
893
-        timer = setTimeout(function () {
894
-          //连接
895
-          tlwsa.tlaOpen(_this.incomingService.getSocketUrl());
896
-        }, 120000)
897
+        if(this.incomingService.getPhoneNumber()){
898
+          _this.msg.info('与服务器网络连接中断,2分钟后重连')
899
+          console.log('2分钟后自动重连-----seimin')
900
+          timer = setTimeout(function () {
901
+            //连接
902
+            TLWSA.phoneNumber = _this.incomingService.getPhoneNumber();
903
+            tlwsa.tlaOpen(_this.incomingService.getSocketUrl());
904
+          }, 120000)
905
+        }else{
906
+          _this.websocketLoading = false;
907
+        }
897 908
       }
898 909
     }
899 910
     //签入回调函数
@@ -1349,14 +1360,15 @@ export class FuwutaiComponent implements OnInit {
1349 1360
 
1350 1361
   showBindExtensionNumber() {
1351 1362
     this.showBindExtensionNumberModal = true;
1363
+    this.websocketLoading = false;
1352 1364
   }
1353 1365
 
1354 1366
   // 保存绑定分机-签入
1355 1367
   checkIn(phoneNumber){
1356 1368
     this.websocketLoading = true;
1357
-    this.incomingService.setPhoneNumber(phoneNumber);
1369
+    // this.incomingService.setPhoneNumber(phoneNumber);
1358 1370
     this.incomingService.closeWs(true);
1359
-    this.getWebsocketPhone();
1371
+    this.getWebsocketPhone(phoneNumber);
1360 1372
   }
1361 1373
 
1362 1374
   // 签出
@@ -1385,11 +1397,11 @@ export class FuwutaiComponent implements OnInit {
1385 1397
     // tel1: '',//目的号码对象
1386 1398
     // tel2: '',//转接坐席对象
1387 1399
   }
1388
-  getWebsocketPhone() {
1400
+  getWebsocketPhone(phoneNumber) {
1389 1401
     const sign = this.incomingService.getSign();
1390 1402
     if(sign === 'box'){
1391 1403
       // 录音盒
1392
-      this.incomingService.connectWs().subscribe((data) => {
1404
+      this.incomingService.connectWs(phoneNumber).subscribe((data) => {
1393 1405
         // data = { status: 201, phone: '013581394341' };//ceshi
1394 1406
         console.log(data);
1395 1407
         console.log(this.incidentModel);
@@ -1397,6 +1409,7 @@ export class FuwutaiComponent implements OnInit {
1397 1409
 
1398 1410
         // 200签入 201摘机 202来电
1399 1411
         if (data.status == 200 && data.phone) {
1412
+          this.incomingService.setPhoneNumber(phoneNumber);
1400 1413
           this.incidentModel = {};
1401 1414
           this.incidentMsg = {};
1402 1415
           this.incidentModel.callID = data.callId || undefined;
@@ -1426,6 +1439,7 @@ export class FuwutaiComponent implements OnInit {
1426 1439
       // 呼叫中心----start
1427 1440
       this.preState = '';
1428 1441
       //连接
1442
+      TLWSA.phoneNumber = phoneNumber;
1429 1443
       tlwsa.tlaOpen(this.incomingService.getSocketUrl());
1430 1444
     }else{
1431 1445
       this.websocketLoading = false;
@@ -2485,7 +2499,7 @@ export class FuwutaiComponent implements OnInit {
2485 2499
       this.incomingService.removePhoneNumber();
2486 2500
     }
2487 2501
     if (this.incomingService.getPhoneNumber()) {
2488
-      this.getWebsocketPhone();
2502
+      this.getWebsocketPhone(this.incomingService.getPhoneNumber());
2489 2503
     }else{
2490 2504
       this.websocketLoading = false;
2491 2505
     }