face-scan-pop.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {toast} from "../../../../utils/utils";
  2. Component({
  3. properties: {
  4. show: Boolean,
  5. name: String,
  6. idcard: String,
  7. currentTime: Number,
  8. },
  9. data: {
  10. support: false,
  11. errMsg: ''
  12. },
  13. attached() {
  14. let that = this;
  15. wx.checkIsSupportFacialRecognition({
  16. success() {
  17. that.setData({
  18. support: true
  19. });
  20. },
  21. fail(res) {
  22. that.handleError(res);
  23. },
  24. });
  25. },
  26. methods: {
  27. scan() {
  28. if (!this.data.support) {
  29. wx.showModal({
  30. title: this.data.errMsg || '人脸识别初始化失败,请稍后重试',
  31. showCancel: false
  32. })
  33. return
  34. }
  35. let that = this;
  36. if (this.data.name && this.data.idcard) {
  37. wx.startFacialRecognitionVerify({
  38. name: this.data.name,
  39. idCardNumber: this.data.idcard,
  40. complete(res) {
  41. if (res.errCode == 0) {
  42. that.triggerEvent("scanOk", {currentTime: that.data.currentTime})
  43. toast('识别成功')
  44. } else {
  45. console.log("识别失败" + res.errMsg)
  46. toast('识别失败')
  47. }
  48. }
  49. })
  50. } else {
  51. toast('人脸识别初始化失败,请稍后重试')
  52. }
  53. },
  54. handleError(res) {
  55. let errMsg = "不支持人脸核身";
  56. switch (res.ErrCode) {
  57. case 10001:
  58. errMsg = "不支持人脸采集:设备没有前置摄像头";
  59. break
  60. case 10002:
  61. errMsg = "不支持人脸采集:没有下载到必要模型";
  62. break
  63. case 10003:
  64. errMsg = "不支持人脸采集:后台控制不支持";
  65. break
  66. }
  67. this.setData({
  68. errMsg
  69. })
  70. }
  71. },
  72. });