소스 검색

Merge branch 'develop' into lmm

seimin 3 년 전
부모
커밋
267b72cf64

+ 24 - 15
src/app/services/websocket-index.service.ts

@@ -6,29 +6,32 @@ import * as Atmosphere from "atmosphere.js";
6 6
   providedIn: "root",
7 7
 })
8 8
 export class WebsocketIndexService {
9
-  constructor() {}
9
+  constructor() { }
10 10
   private lockReconnect = false; //避免ws重复连接
11
-  ws; //定义websocket
11
+  ws = null; //定义websocket
12 12
   private url = ""; //ws连接地址
13 13
   private urlParams; //ws连接传参
14 14
   private isHandler = false; //是否手动
15 15
   private subject;
16
+  private reconnectTimer = null;//重连的计时器
16 17
   // 连接websocket
17 18
   connectWs(url, data): Observable<any> {
18 19
     this.url = url;
19 20
     this.urlParams = data;
20 21
     this.subject = new Subject<any>();
21 22
     let request: any = {
22
-      url,
23
-      contentType: "application/json",
24
-      shared: true, // 标签共享
23
+      webSocketUrl: url,
25 24
       trackMessageLength: true, //校验数据完整性
26 25
       transport: "websocket",
26
+      handleOnlineOffline: false,
27
+      suspend: false,
28
+      maxReconnectOnClose: 0,
27 29
     };
28 30
 
29 31
     request.onOpen = (response) => {
30 32
       console.log("ws连接成功" + new Date().toLocaleString());
31 33
       this.heartCheck.reset().start(this);
34
+      console.log(response);
32 35
       this.ws.push(JSON.stringify(data));
33 36
     };
34 37
 
@@ -36,7 +39,6 @@ export class WebsocketIndexService {
36 39
       this.heartCheck.reset().start(this);
37 40
       let message = response.responseBody;
38 41
       try {
39
-        // alert(message);
40 42
         console.log("收到消息" + message);
41 43
         if (message !== "pong") {
42 44
           this.subject.next(JSON.parse(message));
@@ -49,20 +51,20 @@ export class WebsocketIndexService {
49 51
 
50 52
     request.onClose = (response) => {
51 53
       console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
52
-      this.heartCheck.reset();
53
-      if (!this.isHandler) {
54
+      this.ws = null;
55
+      console.log(response)
56
+      if (!this.isHandler && response.status === 408) {
54 57
         this.reconnect(this.url, this.urlParams);
55 58
       }
56 59
     };
57 60
 
58 61
     request.onError = (response) => {
59 62
       console.log("ws连接错误", this.isHandler);
60
-      this.heartCheck.reset();
61
-      if (!this.isHandler) {
63
+      this.ws = null;
64
+      if (response.status === 0) {
62 65
         this.reconnect(this.url, this.urlParams);
63 66
       }
64 67
     };
65
-
66 68
     this.ws = Atmosphere.subscribe(request);
67 69
     return this.subject.asObservable();
68 70
   }
@@ -70,14 +72,14 @@ export class WebsocketIndexService {
70 72
   private reconnect(url, data) {
71 73
     if (this.lockReconnect) return;
72 74
     this.lockReconnect = true;
73
-    setTimeout(() => {
75
+    this.reconnectTimer = setTimeout(() => {
74 76
       //没连接上会一直重连,设置延迟避免请求过多
75 77
       this.connectWs(url, data);
76 78
       this.lockReconnect = false;
77 79
     }, 15000);
78 80
   }
79 81
   private heartCheck = {
80
-    timeout: 60000, //1分钟发一次心跳
82
+    timeout: 30000, //发一次心跳的间隔时间
81 83
     timeoutObj: null,
82 84
     serverTimeoutObj: null,
83 85
     reset: function () {
@@ -89,7 +91,9 @@ export class WebsocketIndexService {
89 91
       this.timeoutObj = setTimeout(() => {
90 92
         //这里发送一个心跳,后端收到后,返回一个心跳消息,
91 93
         //onmessage拿到返回的心跳就说明连接正常
92
-        _this.ws.push("ping");
94
+        if (_this.ws) {
95
+          _this.ws.push("ping");
96
+        }
93 97
         this.serverTimeoutObj = setTimeout(() => {
94 98
           //如果超过一定时间还没重置,说明后端主动断开了
95 99
           _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
@@ -101,6 +105,11 @@ export class WebsocketIndexService {
101 105
   // 断开websocket
102 106
   closeWs(flag: boolean = false) {
103 107
     this.isHandler = flag;
104
-    this.ws.close();
108
+    if (flag) {
109
+      clearTimeout(this.reconnectTimer);
110
+    }
111
+    if (this.ws) {
112
+      this.ws.close();
113
+    }
105 114
   }
106 115
 }

+ 26 - 17
src/app/services/websocket-main.service.ts

@@ -6,29 +6,32 @@ import * as Atmosphere from "atmosphere.js";
6 6
   providedIn: "root",
7 7
 })
8 8
 export class WebsocketMainService {
9
-  constructor() {}
9
+  constructor() { }
10 10
   private lockReconnect = false; //避免ws重复连接
11
-  ws; //定义websocket
11
+  ws = null; //定义websocket
12 12
   private url = ""; //ws连接地址
13 13
   private urlParams; //ws连接传参
14 14
   private isHandler = false; //是否手动
15 15
   private subject;
16
+  private reconnectTimer = null;//重连的计时器
16 17
   // 连接websocket
17 18
   connectWs(url, data): Observable<any> {
18 19
     this.url = url;
19 20
     this.urlParams = data;
20 21
     this.subject = new Subject<any>();
21 22
     let request: any = {
22
-      url,
23
-      contentType: "application/json",
24
-      shared: true, // 标签共享
23
+      webSocketUrl: url,
25 24
       trackMessageLength: true, //校验数据完整性
26 25
       transport: "websocket",
26
+      handleOnlineOffline: false,
27
+      suspend: false,
28
+      maxReconnectOnClose: 0,
27 29
     };
28 30
 
29 31
     request.onOpen = (response) => {
30 32
       console.log("ws连接成功" + new Date().toLocaleString());
31 33
       this.heartCheck.reset().start(this);
34
+      console.log(response);
32 35
       this.ws.push(JSON.stringify(data));
33 36
     };
34 37
 
@@ -36,7 +39,6 @@ export class WebsocketMainService {
36 39
       this.heartCheck.reset().start(this);
37 40
       let message = response.responseBody;
38 41
       try {
39
-        // alert(message);
40 42
         console.log("收到消息" + message);
41 43
         if (message !== "pong") {
42 44
           this.subject.next(JSON.parse(message));
@@ -48,21 +50,21 @@ export class WebsocketMainService {
48 50
     };
49 51
 
50 52
     request.onClose = (response) => {
51
-      console.log("ws连接关闭" + new Date().toLocaleString(),this.isHandler);
52
-      this.heartCheck.reset();
53
-      if (!this.isHandler) {
53
+      console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
54
+      this.ws = null;
55
+      console.log(response)
56
+      if (!this.isHandler && response.status === 408) {
54 57
         this.reconnect(this.url, this.urlParams);
55 58
       }
56 59
     };
57 60
 
58 61
     request.onError = (response) => {
59
-      console.log("ws连接错误",this.isHandler);
60
-      this.heartCheck.reset();
61
-      if (!this.isHandler) {
62
+      console.log("ws连接错误", this.isHandler);
63
+      this.ws = null;
64
+      if (response.status === 0) {
62 65
         this.reconnect(this.url, this.urlParams);
63 66
       }
64 67
     };
65
-
66 68
     this.ws = Atmosphere.subscribe(request);
67 69
     return this.subject.asObservable();
68 70
   }
@@ -70,14 +72,14 @@ export class WebsocketMainService {
70 72
   private reconnect(url, data) {
71 73
     if (this.lockReconnect) return;
72 74
     this.lockReconnect = true;
73
-    setTimeout(() => {
75
+    this.reconnectTimer = setTimeout(() => {
74 76
       //没连接上会一直重连,设置延迟避免请求过多
75 77
       this.connectWs(url, data);
76 78
       this.lockReconnect = false;
77 79
     }, 15000);
78 80
   }
79 81
   private heartCheck = {
80
-    timeout: 60000, //1分钟发一次心跳
82
+    timeout: 30000, //发一次心跳的间隔时间
81 83
     timeoutObj: null,
82 84
     serverTimeoutObj: null,
83 85
     reset: function () {
@@ -89,7 +91,9 @@ export class WebsocketMainService {
89 91
       this.timeoutObj = setTimeout(() => {
90 92
         //这里发送一个心跳,后端收到后,返回一个心跳消息,
91 93
         //onmessage拿到返回的心跳就说明连接正常
92
-        _this.ws.push("ping");
94
+        if (_this.ws) {
95
+          _this.ws.push("ping");
96
+        }
93 97
         this.serverTimeoutObj = setTimeout(() => {
94 98
           //如果超过一定时间还没重置,说明后端主动断开了
95 99
           _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
@@ -101,6 +105,11 @@ export class WebsocketMainService {
101 105
   // 断开websocket
102 106
   closeWs(flag: boolean = false) {
103 107
     this.isHandler = flag;
104
-    this.ws.close();
108
+    if (flag) {
109
+      clearTimeout(this.reconnectTimer);
110
+    }
111
+    if (this.ws) {
112
+      this.ws.close();
113
+    }
105 114
   }
106 115
 }

+ 26 - 17
src/app/services/websocket-nurse.service.ts

@@ -6,29 +6,32 @@ import * as Atmosphere from "atmosphere.js";
6 6
   providedIn: "root",
7 7
 })
8 8
 export class WebsocketNurseService {
9
-  constructor() {}
9
+  constructor() { }
10 10
   private lockReconnect = false; //避免ws重复连接
11
-  ws; //定义websocket
11
+  ws = null; //定义websocket
12 12
   private url = ""; //ws连接地址
13 13
   private urlParams; //ws连接传参
14 14
   private isHandler = false; //是否手动
15 15
   private subject;
16
+  private reconnectTimer = null;//重连的计时器
16 17
   // 连接websocket
17 18
   connectWs(url, data): Observable<any> {
18 19
     this.url = url;
19 20
     this.urlParams = data;
20 21
     this.subject = new Subject<any>();
21 22
     let request: any = {
22
-      url,
23
-      contentType: "application/json",
24
-      shared: true, // 标签共享
23
+      webSocketUrl: url,
25 24
       trackMessageLength: true, //校验数据完整性
26 25
       transport: "websocket",
26
+      handleOnlineOffline: false,
27
+      suspend: false,
28
+      maxReconnectOnClose: 0,
27 29
     };
28 30
 
29 31
     request.onOpen = (response) => {
30 32
       console.log("ws连接成功" + new Date().toLocaleString());
31 33
       this.heartCheck.reset().start(this);
34
+      console.log(response);
32 35
       this.ws.push(JSON.stringify(data));
33 36
     };
34 37
 
@@ -36,7 +39,6 @@ export class WebsocketNurseService {
36 39
       this.heartCheck.reset().start(this);
37 40
       let message = response.responseBody;
38 41
       try {
39
-        // alert(message);
40 42
         console.log("收到消息" + message);
41 43
         if (message !== "pong") {
42 44
           this.subject.next(JSON.parse(message));
@@ -48,21 +50,21 @@ export class WebsocketNurseService {
48 50
     };
49 51
 
50 52
     request.onClose = (response) => {
51
-      console.log("ws连接关闭" + new Date().toLocaleString(),this.isHandler);
52
-      this.heartCheck.reset();
53
-      if (!this.isHandler) {
53
+      console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
54
+      this.ws = null;
55
+      console.log(response)
56
+      if (!this.isHandler && response.status === 408) {
54 57
         this.reconnect(this.url, this.urlParams);
55 58
       }
56 59
     };
57 60
 
58 61
     request.onError = (response) => {
59
-      console.log("ws连接错误",this.isHandler);
60
-      this.heartCheck.reset();
61
-      if (!this.isHandler) {
62
+      console.log("ws连接错误", this.isHandler);
63
+      this.ws = null;
64
+      if (response.status === 0) {
62 65
         this.reconnect(this.url, this.urlParams);
63 66
       }
64 67
     };
65
-
66 68
     this.ws = Atmosphere.subscribe(request);
67 69
     return this.subject.asObservable();
68 70
   }
@@ -70,14 +72,14 @@ export class WebsocketNurseService {
70 72
   private reconnect(url, data) {
71 73
     if (this.lockReconnect) return;
72 74
     this.lockReconnect = true;
73
-    setTimeout(() => {
75
+    this.reconnectTimer = setTimeout(() => {
74 76
       //没连接上会一直重连,设置延迟避免请求过多
75 77
       this.connectWs(url, data);
76 78
       this.lockReconnect = false;
77 79
     }, 15000);
78 80
   }
79 81
   private heartCheck = {
80
-    timeout: 60000, //1分钟发一次心跳
82
+    timeout: 30000, //发一次心跳的间隔时间
81 83
     timeoutObj: null,
82 84
     serverTimeoutObj: null,
83 85
     reset: function () {
@@ -89,7 +91,9 @@ export class WebsocketNurseService {
89 91
       this.timeoutObj = setTimeout(() => {
90 92
         //这里发送一个心跳,后端收到后,返回一个心跳消息,
91 93
         //onmessage拿到返回的心跳就说明连接正常
92
-        _this.ws.push("ping");
94
+        if (_this.ws) {
95
+          _this.ws.push("ping");
96
+        }
93 97
         this.serverTimeoutObj = setTimeout(() => {
94 98
           //如果超过一定时间还没重置,说明后端主动断开了
95 99
           _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
@@ -101,6 +105,11 @@ export class WebsocketNurseService {
101 105
   // 断开websocket
102 106
   closeWs(flag: boolean = false) {
103 107
     this.isHandler = flag;
104
-    this.ws.close();
108
+    if (flag) {
109
+      clearTimeout(this.reconnectTimer);
110
+    }
111
+    if (this.ws) {
112
+      this.ws.close();
113
+    }
105 114
   }
106 115
 }

+ 26 - 17
src/app/services/websocket-phone.service.ts

@@ -6,29 +6,32 @@ import * as Atmosphere from "atmosphere.js";
6 6
   providedIn: "root",
7 7
 })
8 8
 export class WebsocketPhoneService {
9
-  constructor() {}
9
+  constructor() { }
10 10
   private lockReconnect = false; //避免ws重复连接
11
-  ws; //定义websocket
11
+  ws = null; //定义websocket
12 12
   private url = ""; //ws连接地址
13 13
   private urlParams; //ws连接传参
14 14
   private isHandler = false; //是否手动
15 15
   private subject;
16
+  private reconnectTimer = null;//重连的计时器
16 17
   // 连接websocket
17 18
   connectWs(url, data): Observable<any> {
18 19
     this.url = url;
19 20
     this.urlParams = data;
20 21
     this.subject = new Subject<any>();
21 22
     let request: any = {
22
-      url,
23
-      contentType: "application/json",
24
-      shared: true, // 标签共享
23
+      webSocketUrl: url,
25 24
       trackMessageLength: true, //校验数据完整性
26 25
       transport: "websocket",
26
+      handleOnlineOffline: false,
27
+      suspend: false,
28
+      maxReconnectOnClose: 0,
27 29
     };
28 30
 
29 31
     request.onOpen = (response) => {
30 32
       console.log("ws连接成功" + new Date().toLocaleString());
31 33
       this.heartCheck.reset().start(this);
34
+      console.log(response);
32 35
       this.ws.push(JSON.stringify(data));
33 36
     };
34 37
 
@@ -36,7 +39,6 @@ export class WebsocketPhoneService {
36 39
       this.heartCheck.reset().start(this);
37 40
       let message = response.responseBody;
38 41
       try {
39
-        // alert(message);
40 42
         console.log("收到消息" + message);
41 43
         if (message !== "pong") {
42 44
           this.subject.next(JSON.parse(message));
@@ -48,21 +50,21 @@ export class WebsocketPhoneService {
48 50
     };
49 51
 
50 52
     request.onClose = (response) => {
51
-      console.log("ws连接关闭" + new Date().toLocaleString(),this.isHandler);
52
-      this.heartCheck.reset();
53
-      if (!this.isHandler) {
53
+      console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
54
+      this.ws = null;
55
+      console.log(response)
56
+      if (!this.isHandler && response.status === 408) {
54 57
         this.reconnect(this.url, this.urlParams);
55 58
       }
56 59
     };
57 60
 
58 61
     request.onError = (response) => {
59
-      console.log("ws连接错误",this.isHandler);
60
-      this.heartCheck.reset();
61
-      if (!this.isHandler) {
62
+      console.log("ws连接错误", this.isHandler);
63
+      this.ws = null;
64
+      if (response.status === 0) {
62 65
         this.reconnect(this.url, this.urlParams);
63 66
       }
64 67
     };
65
-
66 68
     this.ws = Atmosphere.subscribe(request);
67 69
     return this.subject.asObservable();
68 70
   }
@@ -70,14 +72,14 @@ export class WebsocketPhoneService {
70 72
   private reconnect(url, data) {
71 73
     if (this.lockReconnect) return;
72 74
     this.lockReconnect = true;
73
-    setTimeout(() => {
75
+    this.reconnectTimer = setTimeout(() => {
74 76
       //没连接上会一直重连,设置延迟避免请求过多
75 77
       this.connectWs(url, data);
76 78
       this.lockReconnect = false;
77 79
     }, 15000);
78 80
   }
79 81
   private heartCheck = {
80
-    timeout: 60000, //1分钟发一次心跳
82
+    timeout: 30000, //发一次心跳的间隔时间
81 83
     timeoutObj: null,
82 84
     serverTimeoutObj: null,
83 85
     reset: function () {
@@ -89,7 +91,9 @@ export class WebsocketPhoneService {
89 91
       this.timeoutObj = setTimeout(() => {
90 92
         //这里发送一个心跳,后端收到后,返回一个心跳消息,
91 93
         //onmessage拿到返回的心跳就说明连接正常
92
-        _this.ws.push("ping");
94
+        if (_this.ws) {
95
+          _this.ws.push("ping");
96
+        }
93 97
         this.serverTimeoutObj = setTimeout(() => {
94 98
           //如果超过一定时间还没重置,说明后端主动断开了
95 99
           _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
@@ -101,6 +105,11 @@ export class WebsocketPhoneService {
101 105
   // 断开websocket
102 106
   closeWs(flag: boolean = false) {
103 107
     this.isHandler = flag;
104
-    this.ws.close();
108
+    if (flag) {
109
+      clearTimeout(this.reconnectTimer);
110
+    }
111
+    if (this.ws) {
112
+      this.ws.close();
113
+    }
105 114
   }
106 115
 }

+ 26 - 17
src/app/services/websocket-ser.service.ts

@@ -6,29 +6,32 @@ import * as Atmosphere from "atmosphere.js";
6 6
   providedIn: "root",
7 7
 })
8 8
 export class WebsocketSerService {
9
-  constructor() {}
9
+  constructor() { }
10 10
   private lockReconnect = false; //避免ws重复连接
11
-  ws; //定义websocket
11
+  ws = null; //定义websocket
12 12
   private url = ""; //ws连接地址
13 13
   private urlParams; //ws连接传参
14 14
   private isHandler = false; //是否手动
15 15
   private subject;
16
+  private reconnectTimer = null;//重连的计时器
16 17
   // 连接websocket
17 18
   connectWs(url, data): Observable<any> {
18 19
     this.url = url;
19 20
     this.urlParams = data;
20 21
     this.subject = new Subject<any>();
21 22
     let request: any = {
22
-      url,
23
-      contentType: "application/json",
24
-      shared: true, // 标签共享
23
+      webSocketUrl: url,
25 24
       trackMessageLength: true, //校验数据完整性
26 25
       transport: "websocket",
26
+      handleOnlineOffline: false,
27
+      suspend: false,
28
+      maxReconnectOnClose: 0,
27 29
     };
28 30
 
29 31
     request.onOpen = (response) => {
30 32
       console.log("ws连接成功" + new Date().toLocaleString());
31 33
       this.heartCheck.reset().start(this);
34
+      console.log(response);
32 35
       this.ws.push(JSON.stringify(data));
33 36
     };
34 37
 
@@ -36,7 +39,6 @@ export class WebsocketSerService {
36 39
       this.heartCheck.reset().start(this);
37 40
       let message = response.responseBody;
38 41
       try {
39
-        // alert(message);
40 42
         console.log("收到消息" + message);
41 43
         if (message !== "pong") {
42 44
           this.subject.next(JSON.parse(message));
@@ -48,21 +50,21 @@ export class WebsocketSerService {
48 50
     };
49 51
 
50 52
     request.onClose = (response) => {
51
-      console.log("ws连接关闭" + new Date().toLocaleString(),this.isHandler);
52
-      this.heartCheck.reset();
53
-      if (!this.isHandler) {
53
+      console.log("ws连接关闭" + new Date().toLocaleString(), this.isHandler);
54
+      this.ws = null;
55
+      console.log(response)
56
+      if (!this.isHandler && response.status === 408) {
54 57
         this.reconnect(this.url, this.urlParams);
55 58
       }
56 59
     };
57 60
 
58 61
     request.onError = (response) => {
59
-      console.log("ws连接错误",this.isHandler);
60
-      this.heartCheck.reset();
61
-      if (!this.isHandler) {
62
+      console.log("ws连接错误", this.isHandler);
63
+      this.ws = null;
64
+      if (response.status === 0) {
62 65
         this.reconnect(this.url, this.urlParams);
63 66
       }
64 67
     };
65
-
66 68
     this.ws = Atmosphere.subscribe(request);
67 69
     return this.subject.asObservable();
68 70
   }
@@ -70,14 +72,14 @@ export class WebsocketSerService {
70 72
   private reconnect(url, data) {
71 73
     if (this.lockReconnect) return;
72 74
     this.lockReconnect = true;
73
-    setTimeout(() => {
75
+    this.reconnectTimer = setTimeout(() => {
74 76
       //没连接上会一直重连,设置延迟避免请求过多
75 77
       this.connectWs(url, data);
76 78
       this.lockReconnect = false;
77 79
     }, 15000);
78 80
   }
79 81
   private heartCheck = {
80
-    timeout: 60000, //1分钟发一次心跳
82
+    timeout: 30000, //发一次心跳的间隔时间
81 83
     timeoutObj: null,
82 84
     serverTimeoutObj: null,
83 85
     reset: function () {
@@ -89,7 +91,9 @@ export class WebsocketSerService {
89 91
       this.timeoutObj = setTimeout(() => {
90 92
         //这里发送一个心跳,后端收到后,返回一个心跳消息,
91 93
         //onmessage拿到返回的心跳就说明连接正常
92
-        _this.ws.push("ping");
94
+        if (_this.ws) {
95
+          _this.ws.push("ping");
96
+        }
93 97
         this.serverTimeoutObj = setTimeout(() => {
94 98
           //如果超过一定时间还没重置,说明后端主动断开了
95 99
           _this.closeWs(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
@@ -101,6 +105,11 @@ export class WebsocketSerService {
101 105
   // 断开websocket
102 106
   closeWs(flag: boolean = false) {
103 107
     this.isHandler = flag;
104
-    this.ws.close();
108
+    if (flag) {
109
+      clearTimeout(this.reconnectTimer);
110
+    }
111
+    if (this.ws) {
112
+      this.ws.close();
113
+    }
105 114
   }
106 115
 }

+ 12 - 3
src/app/views/fuwutai/fuwutai.component.html

@@ -579,7 +579,7 @@
579 579
     <div class="left"
580 580
       *ngIf="fixedTab!=''&&showLastItems&&fixedTab!='newOrder'&&fixedTab!='toSystem'&&fixedTab!='logout'">
581 581
       <!-- 绑定分机 -->
582
-      <div class="con bindingExtension" *ngIf="(fixedTab=='bindingExtension'&&fixedTab!='newOrder')">
582
+      <div class="con bindingExtension" *ngIf="(fixedTab=='bindingExtension'&&fixedTab!='newOrder'&&!phoneNumLoading)">
583 583
         <div class="title">绑定分机</div>
584 584
         <overlay-scrollbars #osComponentRef7 [ngStyle]="{ height:'152px' }" class="conditions">
585 585
           <div nz-row *ngIf="binding === 1">
@@ -618,7 +618,16 @@
618 618
             *ngIf="binding === 3">绑定分机</button>
619 619
           <button nz-button nzType="primary" nzValue="small" (click)="bindingHandle()"
620 620
             *ngIf="binding === 2">重新绑定</button>
621
-          <button nz-button nzType="primary" nzValue="small" *ngIf="binding === 1" (click)="bindingOk()">确定绑定</button>
621
+          <button nz-button nzType="primary" nzValue="small" *ngIf="binding === 1" (click)="bindingOk()" [nzLoading]="bindOkLoading">确定绑定</button>
622
+        </div>
623
+      </div>
624
+      <div class="con bindingExtension display_flex justify-content_flex-center align-items_center"
625
+        *ngIf="(fixedTab=='bindingExtension'&&fixedTab!='newOrder'&&phoneNumLoading)">
626
+        <div class="loadingFull display_flex justify-content_flex-center align-items_center">
627
+          <div class="loadingFullInner">
628
+            <img src="../../../assets/images/loading.gif" alt="">
629
+            <div>加载中...</div>
630
+          </div>
622 631
         </div>
623 632
       </div>
624 633
       <!-- 工单范围 -->
@@ -1446,4 +1455,4 @@
1446 1455
 <app-select-dept [createLoading]="createLoading" [deptFlag]="deptFlag" (submitFormHand)="submitFormHand($event)"
1447 1456
   (deptFlagHand)="deptFlagHand($event)" [hosId]="checkedHos" *ngIf="deptFlag"></app-select-dept>
1448 1457
 
1449
-<router-outlet (deactivate)="refreshList($event)"></router-outlet>
1458
+<router-outlet (deactivate)="refreshList($event)"></router-outlet>

+ 65 - 50
src/app/views/fuwutai/fuwutai.component.ts

@@ -106,7 +106,7 @@ export class FuwutaiComponent implements OnInit {
106 106
     private notification: NzNotificationService,
107 107
     private phones: WebsocketPhoneService,
108 108
     private sers: WebsocketSerService
109
-  ) {}
109
+  ) { }
110 110
   validateFormZy!: FormGroup;
111 111
   validateFormQt!: FormGroup;
112 112
   // ---------------------------------------
@@ -267,11 +267,11 @@ export class FuwutaiComponent implements OnInit {
267 267
     });
268 268
     this.router.navigateByUrl(
269 269
       "dispatchingDesk/allotWorker/" +
270
-        ids_types.join("-") +
271
-        "/" +
272
-        stateIds.join("-") +
273
-        "/2/" +
274
-        this.checkedHos
270
+      ids_types.join("-") +
271
+      "/" +
272
+      stateIds.join("-") +
273
+      "/2/" +
274
+      this.checkedHos
275 275
     );
276 276
   }
277 277
   // 批量撤回
@@ -355,8 +355,8 @@ export class FuwutaiComponent implements OnInit {
355 355
     if (newOrderShowFlag) {
356 356
       let goods = this.validateFormZy.controls.goods.value
357 357
         ? this.validateFormZy.controls.goods.value.filter(
358
-            (item) => item.checked === true
359
-          )
358
+          (item) => item.checked === true
359
+        )
360 360
         : [];
361 361
       goods = goods.map((current) => current.value).join();
362 362
       let postData = {
@@ -540,12 +540,8 @@ export class FuwutaiComponent implements OnInit {
540 540
   }
541 541
   ngOnDestroy() {
542 542
     clearInterval(this.refreshTimerId);
543
-    if (this.phones.ws) {
544
-      this.phones.closeWs(true);
545
-    }
546
-    if (this.sers.ws) {
547
-      this.sers.closeWs(true);
548
-    }
543
+    this.phones.closeWs(true);
544
+    this.sers.closeWs(true);
549 545
   }
550 546
   unassignedSearchCon: string = ""; //未分派搜索框内容
551 547
   arriveSearchCon: string = ""; //待到达搜索框内容
@@ -620,18 +616,23 @@ export class FuwutaiComponent implements OnInit {
620 616
       });
621 617
   }
622 618
   // 连接websocket---phone
619
+  bindOkLoading = false;
623 620
   getWebsocketPhone() {
621
+    this.bindOkLoading = true;
624 622
     let userCount =
625 623
       this.user.user.account + "|" + this.phoneNumListSelected.join("_");
626 624
     this.phones.connectWs(http.phoneWs, { userCount }).subscribe((data) => {
627 625
       // data = { status: 201, phone: '013581394341' };//ceshi
628 626
       console.log(data);
627
+      this.bindOkLoading = false;
629 628
       if (data.status == 200 && data.phone) {
630 629
         localStorage.setItem("phones", data.phone);
631 630
         this.phoneNumListBind = data.phone.split("_");
632 631
         this.phoneNumListBind.forEach((item) => {
633
-          this.phoneNumList.find((item1) => item1.value === item).checked =
634
-            true;
632
+          let obj = this.phoneNumList.find((item1) => item1.value === item);
633
+          if (obj) {
634
+            obj.checked = true;
635
+          }
635 636
         });
636 637
         this.binding = 2;
637 638
       } else if (data.status == 201 && data.phone) {
@@ -683,19 +684,16 @@ export class FuwutaiComponent implements OnInit {
683 684
   //确定绑定
684 685
   bindingOk() {
685 686
     if (this.phoneNumListSelected.length > 0) {
686
-      if (this.phones.ws) {
687
-        this.phones.closeWs(true);
688
-      }
687
+      this.phones.closeWs(true);
689 688
       this.getWebsocketPhone();
690 689
     } else {
691 690
       localStorage.removeItem("phones");
692 691
       this.binding = 3;
692
+      this.phoneNumListBind = [];
693 693
       this.phoneNumList.forEach((item) => {
694 694
         item.checked = false;
695 695
       });
696
-      if (this.phones.ws) {
697
-        this.phones.closeWs(true);
698
-      }
696
+      this.phones.closeWs(true);
699 697
     }
700 698
   }
701 699
   // 选择分机
@@ -1072,20 +1070,20 @@ export class FuwutaiComponent implements OnInit {
1072 1070
     if (flag == 1) {
1073 1071
       this.router.navigateByUrl(
1074 1072
         "dispatchingDesk/allotWorker/" +
1075
-          id +
1076
-          "/" +
1077
-          stateId +
1078
-          "/1/" +
1079
-          this.checkedHos
1073
+        id +
1074
+        "/" +
1075
+        stateId +
1076
+        "/1/" +
1077
+        this.checkedHos
1080 1078
       );
1081 1079
     } else {
1082 1080
       this.router.navigateByUrl(
1083 1081
         "dispatchingDesk/allotWorker/" +
1084
-          id +
1085
-          "/" +
1086
-          stateId +
1087
-          "/0/" +
1088
-          this.checkedHos
1082
+        id +
1083
+        "/" +
1084
+        stateId +
1085
+        "/0/" +
1086
+        this.checkedHos
1089 1087
       );
1090 1088
     }
1091 1089
   }
@@ -1277,9 +1275,10 @@ export class FuwutaiComponent implements OnInit {
1277 1275
     } else {
1278 1276
       this.binding = 3; //绑定分机
1279 1277
     }
1278
+    this.getPhoneNumList();
1280 1279
   }
1281
-  //获取所有分机号码列表,flag表示不自动连接
1282
-  getPhoneNum(flag = true) {
1280
+  //获取所有分机号码列表
1281
+  getPhoneNumList() {
1283 1282
     this.phoneNumLoading = true;
1284 1283
     let postData = {
1285 1284
       idx: 0,
@@ -1296,24 +1295,42 @@ export class FuwutaiComponent implements OnInit {
1296 1295
         this.phoneNumList.map((item) => {
1297 1296
           return { ...item, checked: false };
1298 1297
         });
1299
-        if (!flag) {
1300
-          //切换院区的时候清除掉缓存中的号码
1301
-          localStorage.removeItem("phones");
1302
-        }
1303
-        this.phoneNumListBind = localStorage.getItem("phones")
1304
-          ? localStorage.getItem("phones").split("_")
1305
-          : [];
1306
-        this.phoneNumListSelected = localStorage.getItem("phones")
1307
-          ? localStorage.getItem("phones").split("_")
1308
-          : [];
1309
-        if (this.phoneNumListBind.length) {
1310
-          this.getWebsocketPhone();
1311
-        }
1298
+        this.phoneNumListBind.forEach((item) => {
1299
+          let obj = this.phoneNumList.find((item1) => item1.value === item);
1300
+          if (obj) {
1301
+            obj.checked = true;
1302
+          }
1303
+        });
1312 1304
       });
1313 1305
   }
1306
+  getPhoneNum(flag = true) {
1307
+    if (!flag) {
1308
+      //切换院区的时候清除掉缓存中的号码
1309
+      localStorage.removeItem("phones");
1310
+    }
1311
+    this.phoneNumListBind = localStorage.getItem("phones")
1312
+      ? localStorage.getItem("phones").split("_")
1313
+      : [];
1314
+    this.phoneNumListSelected = localStorage.getItem("phones")
1315
+      ? localStorage.getItem("phones").split("_")
1316
+      : [];
1317
+    if (this.phoneNumListBind.length) {
1318
+      this.getWebsocketPhone();
1319
+    }
1320
+  }
1314 1321
   // 绑定分机,重新绑定
1315 1322
   bindingHandle() {
1316 1323
     this.binding = 1;
1324
+    this.phoneNumList.forEach((item) => {
1325
+      item.checked = false;
1326
+    })
1327
+    this.phoneNumList.forEach((item) => {
1328
+      this.phoneNumListBind.forEach(v => {
1329
+        if (item.value == v) {
1330
+          item.checked = true;
1331
+        }
1332
+      })
1333
+    });
1317 1334
   }
1318 1335
   // 点击tab切换
1319 1336
   tabClick(key) {
@@ -2174,9 +2191,7 @@ export class FuwutaiComponent implements OnInit {
2174 2191
         if (data.status == 200) {
2175 2192
           that.showPromptModal("保存", true, "");
2176 2193
           // 关闭phone的websocket
2177
-          if (this.phones.ws) {
2178
-            this.phones.closeWs(true);
2179
-          }
2194
+          this.phones.closeWs(true);
2180 2195
           this.getPhoneNum(false);
2181 2196
           that.user.user.scope = data.data;
2182 2197
           localStorage.setItem("user", JSON.stringify(that.user));