import { validatorIdCard } from '../../util/validator' import { faceAuth } from '../../api/auth' import { getUser, setUser } from '../../util/user' Page({ data: { authFlag: true, disabled: true, realName: '', idCard: '' }, onLoad() { const user = getUser(); this.setData({ realName: user.realName, idCard: user.idCard }) this.onInput() }, switchAuthFlag() { this.setData({ authFlag: false }) }, onInput() { if (this.data.realName && this.data.realName.length >= 2 && validatorIdCard(this.data.idCard)) { this.setData({ disabled: false }) } else { this.setData({ disabled: true }) } }, handleFaceAuth() { wx.startFacialRecognitionVerify({ name: this.data.realName, idCardNumber: this.data.idCard, complete: (res) => { console.log('complete ', res) if (res.errMsg !== 'startFacialRecognitionVerify:ok') { wx.showToast({ title: res.errMsg, icon: 'none', duration: 3000 }); return } const data = { realName: this.data.realName, idCard: this.data.idCard, errMsg: res.errMsg, errCode: res.errCode, verifyResult: res.verifyResult } faceAuth(data).then(data => { setUser(data); wx.redirectTo({ url: '/pages/write/index', }) }) }, success(res) { console.log('success ', res) }, fail(res) { console.log('fail', res) wx.showToast({ title: res.errMsg, icon: 'none', duration: 3000 }); } }) } });