瀏覽代碼

人脸检测不可用时,退出登录

Michael Wang 5 年之前
父節點
當前提交
53678f95c1
共有 1 個文件被更改,包括 16 次插入5 次删除
  1. 16 5
      src/features/OnlineExam/Examing/FaceMotion/FaceMotion.vue

+ 16 - 5
src/features/OnlineExam/Examing/FaceMotion/FaceMotion.vue

@@ -874,17 +874,28 @@ export default {
       });
       console.log(videoEl.readyState, faceapi.nets.tinyFaceDetector.params);
       console.log("increaseTestSpeed --- doing faceapi");
-      const result = await faceapi
-        .detectSingleFace(videoEl, options)
-        .withFaceLandmarks()
-        .withFaceExpressions();
+      const result = await Promise.race([
+        faceapi
+          .detectSingleFace(videoEl, options)
+          .withFaceLandmarks()
+          .withFaceExpressions(),
+        new Promise(resolve => setTimeout(resolve, 20 * 1000)),
+      ]);
       console.log("increaseTestSpeed --- result:", result);
+      this.$Spin.hide();
+      if (typeof result === "undefined") {
+        this.$Message.error({
+          content: "人脸检测功能不可用",
+          duration: 15,
+          closable: true,
+        });
+        this.logout("?LogoutReason=人脸检测功能不可用");
+      }
       if (!result) {
         console.log("increaseTestSpeed --- end failed");
       } else {
         console.log("increaseTestSpeed --- end successfully");
       }
-      this.$Spin.hide();
     },
     videoStartPlay() {
       const video = document.getElementById("inputVideo");