OnlineExamFaceCheckModal.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <Modal v-model="faceCheckModalOpen" width="900" :mask-closable="false" :closable="false" @on-visible-change="updateCameraState">
  3. <div slot="header" style="display: flex; justify-content: space-between; align-items: center;">
  4. <div class="qm-title-text">人脸识别</div>
  5. <Icon type="ios-close" class="qm-icon-button" size="24" @click="closeModal" />
  6. </div>
  7. <div style="display: grid; grid-template-columns: 200px 400px 1fr; grid-gap: 5px; position: relative">
  8. <!-- TODO: 显示子组件的message -->
  9. <!-- <div style="position: absolute; top: -16px; left: 0; width: 100%; height: 50px; background-color: #eee; opacity: 0.8; display: grid; ">
  10. <div class="qm-title-text" style="width: 100%; text-algin: center; ">msg</div>
  11. </div> -->
  12. <div class="avatar" :style="{ backgroundImage: `url('${userPhoto}')` }">
  13. <!-- <img :src="userPhoto" width="200px" height="300px" alt="底照" /> -->
  14. <div class="avatar-info" style="text-align: center; margin-top: 260px; color: white;">
  15. <span style="background-color: rgba(0, 0, 0, 0.5); display: inline-block;padding: 6px 16px; border-radius: 6px;">我的底照</span>
  16. </div>
  17. </div>
  18. <div class="camera">
  19. <FaceRecognition v-if="faceCheckModalOpen" width="400" height="300" :showRecognizeButton="true" :close-camera="closeCamera" @on-recognize-result="getFaceRecognitionResult">
  20. </FaceRecognition>
  21. </div>
  22. <div class="verify-desc qm-primary-text">
  23. <h4 class="qm-big-text" style="font-weight: bold">操作提示:</h4>
  24. <p>1.请先确保摄像头设备已连接并能正常工作;</p>
  25. <p>2.请保持光源充足,不要逆光操作;</p>
  26. <p>3.请保证脸部正面面向摄像头,并适当调整姿势保证整个脸部能够进入左侧识别画面;</p>
  27. <p>4.系统识别通过后,将自动跳转进入考试界面;</p>
  28. </div>
  29. </div>
  30. <div slot="footer">
  31. </div>
  32. </Modal>
  33. </template>
  34. <script>
  35. import FaceRecognition from "@/components/FaceRecognition/FaceRecognition.vue";
  36. import { createNamespacedHelpers } from "vuex";
  37. const { mapState, mapMutations } = createNamespacedHelpers("examHomeModule");
  38. export default {
  39. name: "OnlineExamFaceCheckModal",
  40. data() {
  41. return { userPhoto: null, closeCamera: false };
  42. },
  43. props: {
  44. open: Boolean,
  45. course: Object
  46. },
  47. async mounted() {
  48. try {
  49. const res = await this.$http.get(
  50. "/api/ecs_core/student/getStudentInfoBySession"
  51. );
  52. this.userPhoto = res.data.photoPath;
  53. if (this.course && this.course.faceEnable && !this.userPhoto) {
  54. this.$Message.error("没有底照");
  55. return;
  56. }
  57. } catch (error) {
  58. this.$Message.error("获取学生底照信息失败");
  59. this.closeModal();
  60. }
  61. },
  62. computed: {
  63. ...mapState(["faceCheckModalOpen"])
  64. },
  65. methods: {
  66. ...mapMutations(["toggleFaceCheckModal"]),
  67. closeModal() {
  68. this.closeCamera = true;
  69. this.toggleFaceCheckModal(false);
  70. },
  71. updateCameraState(modalVisible) {
  72. this.closeCamera = !modalVisible;
  73. },
  74. getFaceRecognitionResult({ error, faceCount, pass }) {
  75. if (error) {
  76. console.log(error, faceCount, pass);
  77. this.$Message.error(error);
  78. return;
  79. }
  80. if (!pass) {
  81. this.$Message.error("人脸比对失败");
  82. if (!this.course.faceCheck) {
  83. this.toggleFaceCheckModal(false);
  84. this.$Modal.confirm({
  85. title: "郑重承诺",
  86. content:
  87. "我承诺由本人参加考试,并且同意接受考试监控系统信息审核,一经发现作弊,立即取消本门课程考试成绩。",
  88. onOk: () =>
  89. this.$router.push(
  90. `/online-exam/exam/${
  91. this.course.examId
  92. }/overview?examStudentId=${this.course.examStudentId}`
  93. )
  94. });
  95. }
  96. return;
  97. }
  98. this.toggleFaceCheckModal(false);
  99. this.$router.push(
  100. `/online-exam/exam/${this.course.examId}/overview?examStudentId=${
  101. this.course.examStudentId
  102. }`
  103. );
  104. }
  105. },
  106. components: {
  107. FaceRecognition
  108. }
  109. };
  110. </script>
  111. <style scoped>
  112. .avatar {
  113. background: center no-repeat;
  114. background-size: cover;
  115. width: 200px;
  116. height: 300px;
  117. }
  118. .verify-desc {
  119. padding: 0 1em;
  120. line-height: 1.8em;
  121. }
  122. </style>