import { getHeadPhoto, updateUserIdFile, faceRecognition, updUserSign } from "../../api/index"; import { FILEPATHPRE } from "../../utils/util" import Dialog from '@vant/weapp/dialog/dialog'; const app = getApp() Page({ data: { capture: ['camera'], uploadMsg: '上传签字', FILEPATHPRE: FILEPATHPRE, filePath: '', EXAMFACE: false, }, afterRead(event) { const { file } = event.detail; // 正常的头像上传 if (!this.data.EXAMFACE) { updateUserIdFile({ filePath: file.url, }).then((resData) => { if (resData.code == 0) { app.globalData.userInfo.AUTHENTICATION = '1' this.getData() Dialog.alert({ message: '您已成功认证', selector: '#myDialog', }) .then(() => { wx.navigateBack() }); } }).catch((e) => { wx.showToast({ title: '人像比对不通过,请重新提交审核', mask: false, icon: error }) }) } else { // 考试前人脸识别 faceRecognition({ filePath: file.url, formData:{ STUDENT_ID: this.data.STUDENT_ID } }).then((resData)=>{ if (resData.code == 0) { Dialog.alert({ message: '您已成功认证,返回立即考试', selector: '#myDialog', }) .then(() => { //当前页面 let pages = getCurrentPages(); //上一页面 let prevPage = pages[pages.length-2]; wx.navigateBack({ delta: 1, success: function () { if(prevPage != null && prevPage.route == 'pages/exam/online/online'){ let dataInfo = prevPage.data.dataInfo dataInfo.EXAM_FACE_PATH = true prevPage.photoResult(dataInfo); } } }) }); } else { Dialog.alert({ message: '比对失败,请重新比对', selector: '#myDialog', }) .then(() => { }); } }) } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); if (!options.STUDENT_ID) { this.getData() } else { this.setData({ STUDENT_ID: options.STUDENT_ID, EXAMFACE: true, uploadMsg: '上传签字' }) } }, userSignShowChange(){ this.setData({ userSignShow:!this.data.userSignShow }) }, async getData() { const resData = await getHeadPhoto({}); if (resData.pd.SIGNATURE_FILE_PATH != null) { this.setData({ filePath: FILEPATHPRE + resData.pd.SIGNATURE_FILE_PATH }) this.setData({ uploadMsg: '已签字,重新上传' }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, openSign() { this.setData({ userSignShow: true }) }, fnInput1(event) { // 签字图片 event.detail updUserSign({ filePath: event.detail, formData:{ USER_ID: app.globalData.userInfo.USER_ID } }).then((resData) => { if(resData.code != 0) { wx.showToast({ title: '请重签', mask: false, icon:error }) }else { wx.showToast({ title: '签字已经更新', mask: false }) this.getData(); } }).catch((e) =>{ console.log(e); }) }, })