FaceCheck.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view style="display: none;">检测人脸...</view>
  3. </template>
  4. <script>
  5. import { simpleDetail } from '@/api/course.js'
  6. import { checkFace } from '@/api/course/face'
  7. export default {
  8. name: 'FaceCheck',
  9. props: {
  10. courseId: String,
  11. fileId: String
  12. },
  13. data() {
  14. return {
  15. faceTimer: null,
  16. file: {
  17. startFace: false,
  18. faceInterval: 0,
  19. randFace: false
  20. }
  21. }
  22. },
  23. watch: {
  24. fileId: {
  25. handler(){
  26. this.fileData()
  27. }
  28. }
  29. },
  30. mounted() {
  31. console.log('++++进行人脸校验...')
  32. // 进入即校验人脸
  33. this.fileData()
  34. },
  35. destroyed() {
  36. // 移除定时
  37. if (this.faceTimer) {
  38. clearInterval(this.faceTimer)
  39. }
  40. },
  41. methods: {
  42. // 获取课件描述信息
  43. fileData(){
  44. simpleDetail(this.courseId).then(res=>{
  45. // 初始化刷脸操作
  46. this.initFace(res)
  47. })
  48. },
  49. // 初始化人脸识别
  50. initFace(file) {
  51. // 校验是否需要人脸认证
  52. if (file.faceStart) {
  53. // 校验不通过,重新校验
  54. this.confirmFace(true)
  55. }
  56. },
  57. /**
  58. * 确认人脸识别数据
  59. */
  60. confirmFace(msg, tm) {
  61. // 校验不通过,重新校验
  62. checkFace({courseId: this.courseId, fileId: this.fileId}).then(res => {
  63. console.log(res)
  64. if (res) {
  65. // 可以继续阅读
  66. this.$emit('ok')
  67. } else {
  68. this.$emit('no')
  69. console.log('跳转人脸识别去....')
  70. setTimeout(() => {
  71. uni.navigateTo({
  72. url: `/pages/course/face?courseId=${this.courseId}&fileId=${this.fileId}`
  73. })
  74. }, 100)
  75. }
  76. })
  77. }
  78. }
  79. }
  80. </script>
  81. <style scoped>
  82. </style>