You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
3.2 KiB

// pages/profile/authentication/index.js
Page({
/**
* 页面的初始数据
*/
data: {
idCardFront: '', // 身份证人像面
idCardBack: '', // 身份证国徽面
name: '', // 姓名
idNumber: '', // 身份证号
address: '', // 居住地址
validStart: '', // 有效期开始
validEnd: '' // 有效期结束
},
/**
* 返回上一页
*/
navigateBack() {
wx.navigateBack({ delta: 1 });
},
/**
* 上传身份证人像面
*/
uploadIdCardFront() {
this.uploadImage('idCardFront');
},
/**
* 上传身份证国徽面
*/
uploadIdCardBack() {
this.uploadImage('idCardBack');
},
/**
* 通用图片上传方法
* @param {string} field - 上传的字段名
*/
uploadImage(field) {
const _this = this;
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success(res) {
// 获取图片临时路径
const tempFilePaths = res.tempFiles;
if (tempFilePaths && tempFilePaths.length > 0) {
// 更新页面数据
_this.setData({
[field]: tempFilePaths[0].tempFilePath
});
// 这里可以添加图片上传到服务器的逻辑
// 模拟识别成功后填充信息
_this.simulateOcrResult();
}
},
fail(err) {
console.error('选择图片失败:', err);
wx.showToast({
title: '选择图片失败',
icon: 'none'
});
}
});
},
/**
* 模拟OCR识别结果
*/
simulateOcrResult() {
// 模拟识别成功后填充信息
this.setData({
name: '张三',
idNumber: '110101199001011234',
address: '北京市朝阳区建国路88号',
validStart: '2020-01-01',
validEnd: '2030-01-01'
});
},
/**
* 提交认证
*/
submitAuth() {
// 验证是否上传了身份证
if (!this.data.idCardFront || !this.data.idCardBack) {
wx.showToast({
title: '请上传身份证正反面',
icon: 'none'
});
return;
}
// 这里可以添加提交认证信息到服务器的逻辑
wx.showLoading({ title: '提交中...' });
// 模拟提交成功
setTimeout(() => {
wx.hideLoading();
wx.showToast({
title: '认证成功',
icon: 'success',
duration: 1500
});
// 延时返回上一页
setTimeout(() => {
this.navigateBack();
}, 1500);
}, 1000);
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
});