Browse Source

确保摄像头的状态是正确的

Michael Wang 6 năm trước cách đây
mục cha
commit
b900fb5807
1 tập tin đã thay đổi với 8 bổ sung1 xóa
  1. 8 1
      src/components/FaceRecognition/FaceRecognition.vue

+ 8 - 1
src/components/FaceRecognition/FaceRecognition.vue

@@ -116,6 +116,7 @@ export default {
       } catch (error) {
         // FIXME: more processing
         console.log("同步照片比对流程失败");
+        throw error;
       } finally {
         const video = this.$refs.video;
         video && video.play();
@@ -124,8 +125,14 @@ export default {
       }
     },
     async getSnapShot() {
-      return new Promise(resolve => {
+      return new Promise((resolve, reject) => {
         const video = this.$refs.video;
+        if (video.readyState !== 4) {
+          this.$Message.error({ content: "摄像头没有正常启用", duration: 5 });
+          reject("摄像头没有正常启用");
+          this.logout();
+          return;
+        }
         video.pause();
         var canvas = document.createElement("canvas");
         canvas.width = 220;