林旭祥 9 meses atrás
pai
commit
66d18b421e
1 arquivos alterados com 49 adições e 24 exclusões
  1. 49 24
      src/utils/trainWs.ts

+ 49 - 24
src/utils/trainWs.ts

@@ -22,7 +22,7 @@ export function useWs() {
     transports: ['websocket', 'polling'],
     query: {
       Authorization: 'JWT ' + token,
-      sysuuid: 'JWT ' + token,
+      sysuuid: 'JWT ' + token
     }
   });
 
@@ -40,7 +40,8 @@ export function useWs() {
       let obj = {
         examState: 0,
         examId: examId,
-        beatNumber: 0
+        beatNumber: 0,
+        wsStatus: 0
       };
       return obj;
     });
@@ -98,6 +99,7 @@ export function useWs() {
         if (index != -1) {
           examStateList[index].examState = e.data;
           examStateList[index].beatNumber = examStateList[index].beatNumber + 1;
+          examStateList[index].wsStatus = e.status;
         }
       }
       //工作站状态
@@ -130,6 +132,15 @@ export function useWs() {
         if (loadingTime) {
           clearTimeout(loadingTime);
         }
+        if (testList.length > 1) {
+          //如果全部的WS状态都为213、220就退出
+          let list = examStateList.filter((item: any) => {
+            return [213, 220, 302].includes(item.wsStatus);
+          });
+          if (list.length == testList.length) {
+            getExit();
+          }
+        }
         if (testList.length == 1) {
           getExit();
           //let examId = e?.exam_id || '';
@@ -143,6 +154,7 @@ export function useWs() {
         });
         if (index != -1) {
           examStateList[index].examState = e.data;
+          examStateList[index].wsStatus = e.status;
         }
         if (e.data == 3) {
           //关闭遮罩层
@@ -171,7 +183,7 @@ export function useWs() {
       callback(e);
       getExit();
     });
-  };
+  }
 
   /**
    * 发送命令
@@ -200,14 +212,14 @@ export function useWs() {
    */
   function sendMessage(type: string, data: any, callback?: () => void) {
     if (socket.connected) {
-      callback = callback || function () { };
+      callback = callback || function () {};
       //版本2就拼接进去
       if (version == 'v2') {
         type = type + '_' + version;
       }
       socket.emit(type, JSON.stringify(data), callback);
     }
-  };
+  }
 
   /**
    * 课程连接成功
@@ -225,9 +237,9 @@ export function useWs() {
         demo: parameter.demo,
         test_time: testTime
       },
-      () => { }
+      () => {}
     );
-  };
+  }
 
   /**
    * 连接成功
@@ -244,9 +256,9 @@ export function useWs() {
         demo: parameter.demo,
         test_time: testTime
       },
-      () => { }
+      () => {}
     );
-  };
+  }
 
   /**
    * 创建测试
@@ -278,7 +290,7 @@ export function useWs() {
         }
       }, 30000);
     });
-  };
+  }
 
   /**
    * 开始人脸识别
@@ -310,7 +322,7 @@ export function useWs() {
         }
       }, 30000);
     });
-  };
+  }
 
   /**
    * 停止人脸识别
@@ -342,7 +354,7 @@ export function useWs() {
         }
       }, 30000);
     });
-  };
+  }
 
   /**
    * 确认并提交人脸
@@ -375,7 +387,7 @@ export function useWs() {
         callback();
       }
     );
-  };
+  }
 
   /**
    * 开始测试
@@ -394,7 +406,7 @@ export function useWs() {
         callback();
       }
     );
-  };
+  }
 
   /**
    * 停止测试
@@ -426,7 +438,7 @@ export function useWs() {
         }
       }, 60000);
     });
-  };
+  }
 
   /**
    * 关闭测试测试
@@ -458,7 +470,7 @@ export function useWs() {
         }
       }, 30000);
     });
-  };
+  }
 
   /**
    * 某道识别到了人就停止某道的识别
@@ -471,7 +483,7 @@ export function useWs() {
         track: track
       }
     });
-  };
+  }
 
   /**
    * 某道重新开始识别
@@ -484,7 +496,7 @@ export function useWs() {
         track: track
       }
     });
-  };
+  }
 
   /**
    * 心跳
@@ -528,14 +540,14 @@ export function useWs() {
         }
       );
     }, beatTime);
-  };
+  }
 
   /**
    * 关闭项目
    */
   function examEnds() {
     getExit();
-  };
+  }
 
   /**
    * 退出
@@ -575,7 +587,7 @@ export function useWs() {
         }
       }
     }
-  };
+  }
 
   /**
    * 清空定时任务
@@ -587,8 +599,7 @@ export function useWs() {
         timerManager[key] = null;
       }
     }
-  };
-
+  }
 
   onUnmounted(() => {
     if (socket) {
@@ -597,5 +608,19 @@ export function useWs() {
     }
   });
 
-  return { initWs, sendMessage, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels, getNetWork, examEnds };
+  return {
+    initWs,
+    sendMessage,
+    openOneTest,
+    startFace,
+    stopFace,
+    faceConfirmOnly,
+    startOneTest,
+    finishOneTest,
+    closeOneTest,
+    suspendFaceRecognitionChannels,
+    resumeFaceRecognitionChannels,
+    getNetWork,
+    examEnds
+  };
 }