face.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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="backCourse">返回课程</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import { faceCheck } from '@/api/sys/user/user.js'
  22. import { saveCheck } from '@/api/course/face'
  23. export default {
  24. data() {
  25. return {
  26. photo: '',
  27. courseId: '',
  28. fileId: '',
  29. base64: ''
  30. }
  31. },
  32. onLoad: function(option) {
  33. this.courseId = option.courseId;
  34. this.fileId = option.fileId;
  35. },
  36. methods: {
  37. clearPhoto(){
  38. this.photo = ''
  39. this.base64 = ''
  40. },
  41. // 对比获取token
  42. checkAndNext(){
  43. let that = this
  44. uni.showLoading({
  45. title: '正在比对人脸...'
  46. });
  47. faceCheck({ base64: this.base64 }).then(res => {
  48. console.log('识别结果', res)
  49. this.saveToken(res.faceToken)
  50. uni.hideLoading()
  51. })
  52. },
  53. // 保存人脸入库
  54. saveToken(faceToken) {
  55. let that = this
  56. uni.showLoading({
  57. title: '加载中...'
  58. });
  59. const data = {
  60. courseId: this.courseId,
  61. fileId: this.fileId,
  62. faceToken: faceToken
  63. }
  64. saveCheck(data).then(data => {
  65. // 关闭加载
  66. uni.hideLoading();
  67. // 返回
  68. uni.navigateBack()
  69. })
  70. },
  71. // 返回考试详情
  72. backCourse(){
  73. uni.redirectTo({
  74. url: '/pages/course/detail?id=' + this.courseId
  75. });
  76. }
  77. }
  78. }
  79. </script>
  80. <style scoped>
  81. .out-box {
  82. padding: 25px;
  83. font-size: 14px;
  84. flex-direction: column;
  85. height: 100vh;
  86. }
  87. button {
  88. margin-top: 20px;
  89. }
  90. </style>