|
@@ -9,7 +9,9 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { mapState } from "vuex";
|
|
|
+import { mapState as globalMapState } from "vuex";
|
|
|
+import { createNamespacedHelpers } from "vuex";
|
|
|
+const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
|
|
|
import {
|
|
|
UPYUN_URL,
|
|
|
FACEPP_API,
|
|
@@ -32,6 +34,12 @@ export default {
|
|
|
this.openCamera();
|
|
|
},
|
|
|
watch: {
|
|
|
+ snapNow(val) {
|
|
|
+ if (val) {
|
|
|
+ this.snapTimer();
|
|
|
+ this.toggleSnapNow();
|
|
|
+ }
|
|
|
+ },
|
|
|
closeCamera: function(newValue) {
|
|
|
if (newValue) {
|
|
|
console.log("关闭摄像头");
|
|
@@ -49,6 +57,7 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
methods: {
|
|
|
+ ...mapMutations(["toggleSnapNow"]),
|
|
|
async openCamera() {
|
|
|
const video = this.$refs.video;
|
|
|
|
|
@@ -69,19 +78,33 @@ export default {
|
|
|
this.$Message.error("没有找到可用的摄像头");
|
|
|
}
|
|
|
},
|
|
|
- // TODO: 定时抓拍
|
|
|
- snap() {
|
|
|
+ async snapTimer() {
|
|
|
+ const captureBlob = await this.getSnapShot();
|
|
|
+ const captureFilePath = await this.uploadToServer(captureBlob);
|
|
|
+ await this.faceCompare(captureFilePath);
|
|
|
const video = this.$refs.video;
|
|
|
- video.pause();
|
|
|
- var canvas = document.createElement("canvas");
|
|
|
- canvas.width = 220;
|
|
|
- canvas.height = 165;
|
|
|
+ video && video.play();
|
|
|
+ },
|
|
|
+ async snap() {
|
|
|
+ const captureBlob = await this.getSnapShot();
|
|
|
+ const captureFilePath = await this.uploadToServer(captureBlob);
|
|
|
+ await this.faceCompareSync(UPYUN_URL + captureFilePath);
|
|
|
+ const video = this.$refs.video;
|
|
|
+ video && video.play();
|
|
|
+ },
|
|
|
+ async getSnapShot() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const video = this.$refs.video;
|
|
|
+ video.pause();
|
|
|
+ var canvas = document.createElement("canvas");
|
|
|
+ canvas.width = 220;
|
|
|
+ canvas.height = 165;
|
|
|
|
|
|
- var context = canvas.getContext("2d");
|
|
|
- context.drawImage(video, 0, 0, 220, 165);
|
|
|
+ var context = canvas.getContext("2d");
|
|
|
+ context.drawImage(video, 0, 0, 220, 165);
|
|
|
|
|
|
- canvas.toBlob(this.uploadToServer);
|
|
|
- video.play();
|
|
|
+ canvas.toBlob(resolve);
|
|
|
+ });
|
|
|
},
|
|
|
async uploadToServer(captureBlob) {
|
|
|
//保存抓拍照片到又拍云
|
|
@@ -99,18 +122,13 @@ export default {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const captureFilePath =
|
|
|
- UPYUN_URL + "/capture_photo/" + this.user.userId + "/" + fileName;
|
|
|
- await this.faceCompare(captureFilePath);
|
|
|
+ return "/capture_photo/" + this.user.userId + "/" + fileName;
|
|
|
},
|
|
|
- async faceCompare(captureFilePath) {
|
|
|
+ async faceCompareSync(captureFilePath) {
|
|
|
try {
|
|
|
const res = await this.$http.post(
|
|
|
"/api/ecs_oe_student_face/examCaptureQueue/compareFaceSync?fileUrl=" +
|
|
|
- captureFilePath,
|
|
|
- {
|
|
|
- fileUrl: captureFilePath
|
|
|
- }
|
|
|
+ captureFilePath
|
|
|
);
|
|
|
|
|
|
// TODO: 识别成功、失败的通知或跳转
|
|
@@ -124,10 +142,50 @@ export default {
|
|
|
this.$Message.error(e.message);
|
|
|
return;
|
|
|
}
|
|
|
+ },
|
|
|
+ async faceCompare(captureFilePath) {
|
|
|
+ try {
|
|
|
+ const res = await this.$http.post(
|
|
|
+ "/api/ecs_oe_student_face/examCaptureQueue/uploadExamCapture?fileUrl=" +
|
|
|
+ UPYUN_URL +
|
|
|
+ captureFilePath +
|
|
|
+ "&fileName=" +
|
|
|
+ captureFilePath +
|
|
|
+ "&examRecordDataId=" +
|
|
|
+ this.$route.params.examRecordDataId
|
|
|
+ );
|
|
|
+ this.showSnapResult(captureFilePath);
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e);
|
|
|
+ this.$Message.error(e.message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async showSnapResult(captureFilePath) {
|
|
|
+ try {
|
|
|
+ // 获取抓拍结果
|
|
|
+ const snapRes = (await this.$http.get(
|
|
|
+ "/api/ecs_oe_student_face/examCaptureQueue/getExamCaptureResult?fileName=" +
|
|
|
+ captureFilePath +
|
|
|
+ "&examRecordDataId=" +
|
|
|
+ this.$route.params.examRecordDataId
|
|
|
+ )).data;
|
|
|
+ if (snapRes) {
|
|
|
+ if (snapRes.stranger) {
|
|
|
+ this.$Message.error("请独立考试");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ setTimeout(this.showSnapResult.bind(this, captureFilePath), 3000);
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e);
|
|
|
+ this.$Message.error(e.message);
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapState(["user"])
|
|
|
+ ...globalMapState(["user"]),
|
|
|
+ ...mapState(["snapNow"])
|
|
|
}
|
|
|
};
|
|
|
</script>
|