checkPwd(e) {
console.log('输入的密码为:', e);
try {
<!--获取今天凌晨时间戳-->
var nowDateee = new Date(new Date().setHours(0, 0, 0, 0)).getTime();
<!--获取本地存储的上次存入的时间戳-->
var InputTime = uni.getStorageSync('InputPwdNUm').InputTime;
<!--获取本地存储上次存入的次数-->
var InputNum = uni.getStorageSync('InputPwdNUm').InputNum;
if (nowDateee > InputTime) {
console.log('今天时间大于本地存储时间,清空次数');
uni.setStorageSync('InputPwdNUm', { InputTime: nowDateee, InputNum: 0 });
} else {
if (InputNum >= 5) {
uni.showToast({
title: '今日密码输错5次,明日再试',
icon: 'none'
});
return false;
}
}
} catch (e) {
//TODO handle the exception
}
this.request({
url: '校验密码接口',
data: {
id: 'userid',
payPaw: e
},
success: res => {
console.log('校验密码请求:', res);
if (res.data.returnCode == 1) {
<!--校验成功 执行其他业务代码-->
} else {
<!--密码错误-->
try {
var InputNum = uni.getStorageSync('InputPwdNUm').InputNum;
<!--如果第一次就输错了,那么InputNum为undefined 所以置0-->
if (!InputNum) {
InputNum = 0;
}
InputNum += 1;
<!--更新输错的次数-->
uni.setStorageSync('InputPwdNUm', { InputTime: nowDateee, InputNum: InputNum });
} catch (e) {
//TODO handle the exception
}
uni.showToast({
title: `密码错误,输入错误${uni.getStorageSync('InputPwdNUm').InputNum}次`,
icon: 'none'
});
}
}
});
},