Files
peko-h5/view/peko/modules/identity/js/mobile.js
2022-09-08 18:22:18 +08:00

212 lines
6.0 KiB
JavaScript

/**
* Created by raymondjack on 2018/12/21.
*/
var info = {};
$(function () {
var browser = checkVersion();
var api = locateJudge();
var timer = null;
var env = EnvCheck();
if(env == 'test') {
var vConsole = new VConsole();
}
var main = {
init: function () {
this.getDeviceMsg();
this.eventRegister();
var that = this;
setTimeout(function () {
that.getData();
},200)
},
getDeviceMsg: function () {
if(browser.app){
if(browser.android){
info.uid = parseInt(window.androidJsObj.getUid());
info.deviceId = window.androidJsObj.getDeviceId();
info.ticket = window.androidJsObj.getTicket();
}else{
info.uid = tools.cookieUtils.get("uid");
if(!info.uid){
window.webkit.messageHandlers.getUid.postMessage(null);
}
window.webkit.messageHandlers.getDeviceId.postMessage(null);
window.webkit.messageHandlers.getTicket.postMessage(null);
}
}else{
info.uid = 922473;
info.deviceId = "204aa0c983384f1e84a3625b4f04bac1";
}
// setTimeout(function () {
// $('.deviceId').val(info.deviceId);
// },200)
},
getData: function () {
$.ajax({
type: "post",
url: api + "/user/h5/getSimpleUserByUid",
headers:{
"pub_ticket": info.ticket
},
data: {
uid: info.uid,
ticket: info.ticket
},
success:function (res) {
if (res.code == 200) {
$('.code-text').find('span').html(res.data.phone)
info.phone = res.data.phone
// info.phone = '13610174071'
}
},
error: function (res) {
// if (res.status == 401 ) {
$('.warm').html(res.message).removeClass('hide')
setTimeout(function() {
$('.warm').addClass('hide')
}, 1500)
// }
console.log(res, '报错啦');
}
})
},
eventRegister: function () {
// 获取短信
$('.button-identity-code').on('click',function () {
// var phone = $('.phone').val();
// if(!phone.trim()){
// toastShow("手机号不能为空");
// return;
// }
// if(!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/).test(phone.trim())){
// toastShow("手机号不符合规格");
// return;
// }
if($(this).hasClass("disable")){
return;
}
$(this).addClass('disable');
var time = 60;
var $that = $(this);
$(this).html(time + 's后重新获取');
timer = setInterval(function () {
time--;
$that.html(time + "s后重新获取");
if(time < 0){
clearInterval(timer);
$that.removeClass('disable');
$that.html("获取验证码");
}
},1000)
var requestParam = {
phone: info.phone,
uid: info.uid,
ticket: info.ticket
};
if(browser.android){
requestParam.deviceInfo = JSON.stringify({
deviceId: info.deviceId
});
}
console.log('发送请求')
$.ajax({
type: "post",
url: api + "/certification/send/code",
headers:{
"pub_ticket":info.ticket
},
data: requestParam,
success: function (res) {
console.log(res,'请求成功')
if (res.code == 200) {
$('.code-text').css('visibility','visible')
} else {
console.log('res')
$('.warm').html(res.message).removeClass('hide')
setTimeout(function () {
$('.warm').addClass('hide');
// window.location.reload(true);
}, 1500)
}
},
error: function (res) {
// if (res.status == 401 ) {
$('.warm').html(res.message).removeClass('hide')
setTimeout(function() {
$('.warm').addClass('hide')
}, 1500)
// }
console.log(res, '报错啦');
}
});
})
// 监控输入框
$(".identity-code").bind("input propertychange", function (event) {
var value = $(".identity-code").val();
console.log($(".identity-code").val());
if (value.length >= 4) {
$('.submit').removeClass('ban').attr('disabled', false);
} else {
$('.submit').addClass('ban').attr('disabled', true);
}
});
$('.submit').on('click', function () {
var code = $(".identity-code").val()
console.log('1111');
$.ajax({
type: "post",
url: api + "/certification/smsCode/auth",
headers:{
"pub_ticket": info.ticket
},
data: {
uid: info.uid,
ticket: info.ticket,
phone: info.phone,
code: code
},
success: function (res) {
console.log(res)
if (res.code == 200 && res.data.result) {
$('.warm').html('验证成功!正在为您跳转').removeClass('hide')
setTimeout(function () {
window.location.href = 'new.html?auth=' + res.data.auth
}, 1500)
} else {
$('.warm').html(res.message).removeClass('hide')
setTimeout(function () {
$('.warm').addClass('hide');
// window.location.reload(true);
}, 1500)
}
},
error: function (res) {
// if (res.status == 401 ) {
$('.warm').html(res.message).removeClass('hide')
setTimeout(function() {
$('.warm').addClass('hide')
}, 1500)
// }
console.log(res, '报错啦');
}
})
})
}
};
main.init();
});
function getMessage(key,value) {
info[key] = value;
}