OnlineExamFaceCheckModal.vue 4.4 KB

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