qa-education-exam-weapp/pages/photo/collection.js

164 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import {
getHeadPhoto,
updateUserIdFile,
faceRecognition
} 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,
message: '照片要求人像清晰神态自然无明显畸变。头部占照片尺寸2/3纯色背景无边框照片尺寸为二寸35*49毫米413*578像素)'
},
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: '人脸认证',
message: '点击“人脸认证”按钮进行人脸识别核验,务必本人进行人脸识别。'
})
}
},
async getData() {
const resData = await getHeadPhoto({});
if (resData.pd.AUTHENTICATION == '1') {
this.setData({
filePath: FILEPATHPRE + resData.pd.PORTRAIT
})
this.setData({
uploadMsg: '已认证,重新上传'
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})