face-scan-pop.js 2.4 KB

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