197 lines
5.4 KiB
JavaScript
197 lines
5.4 KiB
JavaScript
![]() |
let urlPrefix = getUrlPrefix()
|
||
|
let browser = checkVersion()
|
||
|
let env = EnvCheck();
|
||
|
if (env == 'test') {
|
||
|
new VConsole();
|
||
|
}
|
||
|
// 封装layer消息提醒框
|
||
|
let layerIndex
|
||
|
const showLoading = (content = '加載中...') => {
|
||
|
layer.open({
|
||
|
type: 2,
|
||
|
shadeClose: false,
|
||
|
content,
|
||
|
success (e) {
|
||
|
layerIndex = $(e).attr('index')
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
const hideLoading = (index) => {
|
||
|
layer.close(index)
|
||
|
}
|
||
|
const toastMsg = (content = '操作完成', time = 2) => {
|
||
|
layer.open({
|
||
|
content,
|
||
|
time,
|
||
|
skin: 'msg'
|
||
|
})
|
||
|
}
|
||
|
var idOrPhone = true;//判断id登入或手机号登入
|
||
|
var times = 0;//倒计时计时器
|
||
|
var isClick = true;//判断是否再次获取验证码
|
||
|
$(function () {
|
||
|
setTimeout(function () {
|
||
|
getInfoFromClient()
|
||
|
setTimeout(function () {
|
||
|
getAreaInfo();
|
||
|
}, 100)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
// 获取验证码接口
|
||
|
function getCode () {
|
||
|
showLoading()
|
||
|
networkRequest({
|
||
|
type: 'POST',
|
||
|
url: urlPrefix + '/sms/getCode',
|
||
|
data:{mobile: `${$('.box .phone .phoneNumberBox .prefix b').text()}${$('.box .phone .phoneNumberBox .phoneNumber').val()}`, type: 1},
|
||
|
success (res) {
|
||
|
if (res.code === 200) {
|
||
|
$('.box .phone .codeBox .codeBut').addClass('codeButTime')
|
||
|
timerFun()
|
||
|
} else {
|
||
|
toastMsg(res.message)
|
||
|
}
|
||
|
hideLoading(layerIndex)
|
||
|
},
|
||
|
error (err) {
|
||
|
hideLoading(layerIndex)
|
||
|
toastMsg('網絡錯誤,請退出重進')
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
// 登入接口
|
||
|
function getAreaInfo () {
|
||
|
showLoading()
|
||
|
networkRequest({
|
||
|
type: 'POST',
|
||
|
url: urlPrefix + '/oauth/token',
|
||
|
success (res) {
|
||
|
if (res.code === 200) {
|
||
|
|
||
|
} else {
|
||
|
toastMsg(res.message)
|
||
|
}
|
||
|
hideLoading(layerIndex)
|
||
|
},
|
||
|
error (err) {
|
||
|
hideLoading(layerIndex)
|
||
|
toastMsg('網絡錯誤,請退出重進')
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
// 区号接口
|
||
|
function getAreaInfo () {
|
||
|
showLoading()
|
||
|
networkRequest({
|
||
|
type: 'GEt',
|
||
|
url: urlPrefix + '/areaInfo/list',
|
||
|
success (res) {
|
||
|
if (res.code === 200) {
|
||
|
var str = '';
|
||
|
res.data.forEach((res, i) => {
|
||
|
str += `
|
||
|
|
||
|
<span>${res.name} +${res.phoneAreaCode}</span>
|
||
|
`
|
||
|
});
|
||
|
$('.area .box .list').append(str);
|
||
|
$('.area .box .list span').click(function () {
|
||
|
$('.box .phone .phoneNumberBox .prefix b').text($(this).text().replace(/[^0-9]/gi, ''));
|
||
|
$(this).addClass('active').siblings().removeClass('active');
|
||
|
})
|
||
|
} else {
|
||
|
toastMsg(res.message)
|
||
|
}
|
||
|
hideLoading(layerIndex)
|
||
|
},
|
||
|
error (err) {
|
||
|
hideLoading(layerIndex)
|
||
|
toastMsg('網絡錯誤,請退出重進')
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
// 点击获取验证码
|
||
|
$('.box .phone .codeBox .codeBut').click(function () {
|
||
|
var val = $('.box .phone .phoneNumberBox .phoneNumber').val();
|
||
|
if (val == '') {
|
||
|
toastMsg('請輸入手機號')
|
||
|
return
|
||
|
}
|
||
|
if (isClick) {
|
||
|
getCode()
|
||
|
}
|
||
|
|
||
|
})
|
||
|
// 倒计时
|
||
|
function timerFun () {
|
||
|
isClick = false;
|
||
|
times = 59;
|
||
|
// 开启定时器
|
||
|
var timer = setInterval(function () {
|
||
|
// 判断剩余秒数
|
||
|
if (times == 0) {
|
||
|
// 清除定时器和复原按钮
|
||
|
clearInterval(timer);
|
||
|
$('.box .phone .codeBox .codeBut').text('獲取驗證碼');
|
||
|
$('.box .phone .codeBox .codeBut').removeClass('codeButTime')
|
||
|
isClick = true;
|
||
|
} else {
|
||
|
$('.box .phone .codeBox .codeBut').text(`${times}秒`);
|
||
|
times--;
|
||
|
}
|
||
|
}, 1000);
|
||
|
}
|
||
|
// 切换登入方式按钮
|
||
|
$('.box .hone').click(function () {
|
||
|
idOrPhone = !idOrPhone;
|
||
|
$('.box .phone .phoneNumberBox .phoneNumber,.box .phone .codeBox .code,.box .idLogin .id,.box .idLogin .password').val('');
|
||
|
$('.box .but').removeClass('butok');
|
||
|
if (idOrPhone) {
|
||
|
$('.idLogin').show();
|
||
|
$('.phone').hide();
|
||
|
$('.box .hone').text('Peko手機號登錄');
|
||
|
} else {
|
||
|
$('.phone').show();
|
||
|
$('.idLogin').hide();
|
||
|
$('.box .hone').text('Peko賬號登錄');
|
||
|
}
|
||
|
})
|
||
|
// 打开选择区号
|
||
|
$('.box .phone .phoneNumberBox .prefix').click(function () {
|
||
|
$('.area').show();
|
||
|
return false;
|
||
|
})
|
||
|
// 关闭选择区号
|
||
|
$('.area').click(function () {
|
||
|
$('.area').hide();
|
||
|
return false;
|
||
|
})
|
||
|
//监听是否可以登入函数
|
||
|
function phoneFun () {
|
||
|
var num1 = $(".box .idLogin .id").val();
|
||
|
var num2 = $(".box .idLogin .password").val();
|
||
|
var num3 = $(".box .phone .phoneNumberBox .phoneNumber").val();
|
||
|
var num4 = $(".box .phone .codeBox .code").val();
|
||
|
if (num1 != '' && num2 != '' || num3 != '' && num4 != '') {
|
||
|
$('.box .but').addClass('butok');
|
||
|
} else {
|
||
|
$('.box .but').removeClass('butok');
|
||
|
}
|
||
|
}
|
||
|
// 监听账号输入
|
||
|
$(".box .idLogin .id").on("keyup", function () {
|
||
|
phoneFun()
|
||
|
});
|
||
|
// 监听密码输入
|
||
|
$(".box .idLogin .password").on("keyup", function () {
|
||
|
phoneFun()
|
||
|
});
|
||
|
// 监听手机号输入
|
||
|
$(".box .phone .phoneNumberBox .phoneNumber").on("keyup", function () {
|
||
|
phoneFun()
|
||
|
});
|
||
|
// 监听验证码输入
|
||
|
$(".box .phone .codeBox .code").on("keyup", function () {
|
||
|
phoneFun()
|
||
|
});
|