face.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="out-box">
  3. <view v-if="photo">
  4. <view style="text-align: center; padding: 20px;">
  5. <image :src="photo" style="width: 60vw; height: 60vh;"></image>
  6. </view>
  7. <view>
  8. <button type="primary" @tap="checkAndNext">识别并开始考试</button>
  9. </view>
  10. <view>
  11. <button type="warn" @tap="clearPhoto">重新拍照</button>
  12. </view>
  13. </view>
  14. <view v-else>
  15. <yf-photo-take v-model="photo" :base64.sync="base64"></yf-photo-take>
  16. <button type="warn" @tap="backExam">返回上一页</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import { handExam } from '@/api/exam.js'
  22. import { faceCheck } from '@/api/sys/user/user.js'
  23. import { createPaper } from '@/api/exam.js'
  24. export default {
  25. data() {
  26. return {
  27. photo: '',
  28. examId: '',
  29. password: '',
  30. base64: ''
  31. }
  32. },
  33. onLoad: function(option) {
  34. this.examId = option.examId;
  35. this.password = option.password;
  36. },
  37. methods: {
  38. clearPhoto(){
  39. this.photo = ''
  40. this.base64 = ''
  41. },
  42. // 对比获取token
  43. checkAndNext(){
  44. let that = this
  45. uni.showLoading({
  46. title: '正在比对人脸...'
  47. });
  48. faceCheck({ base64: this.base64 }).then(res => {
  49. console.log('识别结果', res)
  50. this.startExam(res.faceToken)
  51. uni.hideLoading()
  52. })
  53. },
  54. // 交卷操作
  55. startExam(faceToken) {
  56. let that = this
  57. uni.showLoading({
  58. title: '创建试卷...'
  59. });
  60. const data = {
  61. examId: this.examId,
  62. password: this.password,
  63. faceToken: faceToken
  64. }
  65. createPaper(data).then(data => {
  66. // 关闭加载
  67. uni.hideLoading();
  68. //打印请求返回的数据
  69. uni.redirectTo({
  70. url: '/pages/exam/exam?id=' + data.id
  71. });
  72. })
  73. },
  74. // 返回考试详情
  75. backExam(){
  76. uni.redirectTo({
  77. url: '/pages/exam/detail?id=' + this.examId
  78. });
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. .out-box {
  85. padding: 25px;
  86. font-size: 14px;
  87. flex-direction: column;
  88. height: 100vh;
  89. }
  90. button {
  91. margin-top: 20px;
  92. }
  93. </style>