import {toast} from "../../../../utils/utils"; Component({ properties: { show: Boolean, name: String, idcard: String, currentTime: Number, }, data: { support: false, errMsg: '' }, attached() { let that = this; wx.checkIsSupportFacialRecognition({ success() { that.setData({ support: true }); }, fail(res) { that.handleError(res); }, }); }, methods: { scan() { if (!this.data.support) { wx.showModal({ title: this.data.errMsg || '人脸识别初始化失败,请稍后重试', showCancel: false }) return } let that = this; if (this.data.name && this.data.idcard) { wx.startFacialRecognitionVerify({ name: this.data.name, idCardNumber: this.data.idcard, complete(res) { if (res.errCode == 0) { that.triggerEvent("scanOk", {currentTime: that.data.currentTime}) toast('识别成功') } else { console.log("识别失败" + res.errMsg) toast('识别失败') } } }) } else { toast('人脸识别初始化失败,请稍后重试') } }, handleError(res) { let errMsg = "不支持人脸核身"; switch (res.ErrCode) { case 10001: errMsg = "不支持人脸采集:设备没有前置摄像头"; break case 10002: errMsg = "不支持人脸采集:没有下载到必要模型"; break case 10003: errMsg = "不支持人脸采集:后台控制不支持"; break } this.setData({ errMsg }) } }, });