var phone; var telReg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/; // 登录注册切换 $('.bd_nav').find('span').click(function () { $('.bd_nav').find('span').removeClass('active').eq($(this).index()).addClass('active'); $('.login_wrap').find('.agileits').hide().eq($(this).index()).show(); }) // 倒计时 function invokeSettime(obj) { var countdown = 60; settime(obj); function settime(obj) { if (countdown == 0) { $(obj).attr("disabled", false); $(obj).html("获取验证码"); countdown = 60; return; } else { $(obj).attr("disabled", true); $(obj).html("(" + countdown + ") s 重新发送"); countdown--; } setTimeout(function () { settime(obj) }, 1000) } } // 验证码 $("#getyzm").on('click', function () { phone = $("#phone").val().trim(); if (!phone) { layer.msg('请输入手机号!', { time: 2500 }); return false; } else if (!(telReg.test(phone))) { layer.msg('手机格式错误,请重新核对!', { time: 2500 }); return false; } $.ajax({ url: '/application/index/login/code', type: 'POST', data: { mobile: phone }, success: res => { console.log(res); if (res.code == 1) { layer.msg(res.msg, { time: 2500 }); if (!res.mobile) { invokeSettime("#getyzm"); } else { $("#loginPhone").val(res.mobile); $('.bd_nav').find('span').removeClass('active').eq(0).addClass('active'); $('.login_wrap').find('.agileits').hide().eq(0).show(); } } } }) }) // 登录 $("#denglu").on('click', function () { var loginPhone = $("#loginPhone").val().trim(); if (!loginPhone) { layer.msg('请输入手机号!', { time: 2500 }); return } else if (!telReg.test(loginPhone)) { layer.msg('手机格式错误,请重新核对!', { time: 2500 }); return } else { $.ajax({ url: '/application/index/login/login', type: 'POST', data: { mobile: loginPhone }, success: res => { console.log(res); if (res.code == 1) { layer.msg(res.msg, { time: 2500 }); $('.zg_cover').hide(); $('.login_wrap').hide(); $("#login_btn").hide(); $(".btn_wrap").show().find(".user_phone").text(res.mobile); $("#username").val(res.uid); } else { layer.msg(res.msg, { time: 2500 }); $('.bd_nav').find('span').removeClass('active').eq(1).addClass('active'); $('.login_wrap').find('.agileits').hide().eq(1).show(); } } }) } }) // 注册 $("#zhuce").on('click', function () { phone = $("#phone").val().trim(); var phone_code = $("#yzm").val(); if (!phone) { layer.msg('请输入手机号!', { time: 2500 }); return } else if (!telReg.test(phone)) { layer.msg('手机格式错误,请重新核对!', { time: 2500 }); return } else if (!phone_code) { layer.msg('请输入手机验证码!', { time: 2500 }); return } $.ajax({ url: '/application/index/login/sign', type: 'POST', data: { mobile: phone, code: phone_code }, success: res => { if (res.code == 1) { layer.msg(res.msg, { time: 2500 }); // 遮罩隐藏,登录注册隐藏,手机号显示 $('.zg_cover').hide(); $('.login_wrap').hide(); $("#login_btn").hide(); $(".btn_wrap").show().find(".user_phone").text(res.mobile); $("#username").val(res.uid); } } }) }) // 退出登录 $(".quit_btn").on('click', function () { $.ajax({ url: '/application/index/login/out', type: 'POST', success: res => { console.log(res); if (res.code == 1) { layer.msg(res.msg, { time: 2000 }); $("#login_btn").show(); $(".btn_wrap").hide(); $("#username").val(''); } } }) })