var loginType = 0; $(function () { var apiurl = "/BookCircle/Handler/CommonHandler.ashx"; $("#loginNow").click(function () { $("div[data-login-modal='true']").show(); }); $("div[data-login-tab='true']").click(function () { $("div[data-login-tab='true']").removeClass("dltdq"); $(this).addClass("dltdq"); loginType = $(this).attr("data-logintype"); $("div[data-login-div='true']").hide(); $("div[data-login-div='true'][data-logintype='"+loginType+"']").show(); }); $("#login_close").click(function () { $("div[data-login-modal='true']").hide(); }); $.fn.seconds = 120; $("#btGetVeryCode").click(function () { var phone = $("#txtPhone"); if ($.trim($(phone).val()) == "") { alert("请输入有效的手机号码"); return; } else { var isMob = /^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/; if ($(phone).val().length != 11) { alert("请输入有效的手机号码"); return; } else { if (!isMob.test($(phone).val())) { alert("请输入有效的手机号码"); return; } } } var imgVeryCode = $("#txtImgVerCode_phone").val(); if ($.trim(imgVeryCode)=="") { alert("请输入图片验证码"); return; } $.get(apiurl, { methodname: "CheckImageVerCode", code: imgVeryCode }, function (result) { if (result>0) { $("#btGetVeryCode").val("获取中…"); $.ajax({ url: apiurl, type: "post", data: { methodname: "SendMobileValidateCodeUserLogin", mobile: $("#txtPhone").val(), type: 40 }, success: function (result) { result = JSON.parse(result); if (result.code == 0) { $.fn.seconds = 120; $("#btGetVeryCode").attr("disabled", "disabled"); $.timer(1000, function (timer) { $.fn.seconds--; if ($.fn.seconds >= 0) { $("#btGetVeryCode").val($.fn.seconds + "秒后重新获取"); } else { timer.stop(); $("#btGetVeryCode").removeAttr("disabled"); $("#btGetVeryCode").val("重新获取"); } }); } else { $("#btGetVeryCode").val("重新获取"); } if (result.msg == '验证码已发送,5分钟内输入有效') { alert(result.msg); } else { alert(result.msg); } } }) } else { alert("图片验证码错误!"); } }); }); $("#login").click(function () { if (loginType == 0) { var phone = $("#txtPhone"); if ($.trim($(phone).val()) == "") { alert("请输入有效的手机号码"); return false; } else { var isMob = /^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/; if ($(phone).val().length != 11) { alert("请输入有效的手机号码"); return false; } else { if (!isMob.test($(phone).val())) { alert("请输入有效的手机号码"); return false; } } } var cerycode = $("#txtPhoneVerCode"); if ($(cerycode).val() == "") { alert("验证码不能为空"); return false; } else { var isVerycode = /^\d{6}$/ if (!isVerycode.test($(cerycode).val())) { alert("验证码错误,请重新输入!"); return false; } } $.ajax({ url: apiurl, type: "post", async: false, data: { methodname: "SignPhone", Mobile: $("#txtPhone").val(), ValidateCode: $("#txtPhoneVerCode").val(), type: 40 }, success: function (result) { result = JSON.parse(result); if (result.code==0) { $.fn.seconds = 0; //$("#login_r").hide(); alert("登陆成功!"); $("div[data-login-modal='true']").hide(); var html = `
HI,`+ userName + ` 欢迎来到Book圈
`; $("#login_r").html(html); //window.location.href = result.Content; } else { alert(result.msg); return false; } } }) } else if (loginType == 1) { var userName = $("#userName").val(); var passWord = $("#password").val(); if (!userName) { alert("用户名不能为空"); return; } else { if (userName.length > 80) { alert("用户名只能输入80个字符"); return; } else { } } if (!passWord) { alert("密码不能为空"); return; } else { if (passWord.length > 80) { alert("密码只能输入80个字符"); return; } else { } } var imgVeryCode = $("#txtImgVerCode_account").val(); if ($.trim(imgVeryCode) == "") { alert("请输入图片验证码"); return; } $.get(apiurl, { methodname: "CheckImageVerCode", code: imgVeryCode }, function (result) { if (result > 0) { $(this).prop("disabled", true); $.ajax({ url: apiurl, type: "post", data: { methodname: "Sign", UserName: userName, PassWord: passWord }, dataType: "json", success: function (data) { if (data.state == 200) { //$("#login_r").hide(); alert(data.message); $("div[data-login-modal='true']").hide(); var html = `
HI,`+userName+` 欢迎来到Book圈
`; $("#login_r").html(html); } else { alert(data.message); } }, complete: function () { $("#login").prop("disabled", false); } }); } else { alert("图片验证码错误!"); } }); } }); $.timer = function (interval, callback) { var interval = interval || 100; if (!callback) return false; var doer = ""; _timer = function (interval, callback) { var self = this; this.stop = function () { clearInterval(self.id); }; this.reset = function (val) { if (self.id) clearInterval(self.id); var val = val || 100; this.id = setInterval(function () { callback(self, { originalEvent: true, target: doer }) }, val); }; this.interval = interval; this.id = setInterval(function () { callback(self, { originalEvent: true, target: doer }) }, this.interval); return this.id; }; return new _timer(interval, callback); }; }) function weixinLogin() { var obj = new WxLogin({ self_redirect: true, id: "login_container", appid: "wxd2cbb38406507b0e", scope: "snsapi_login", redirect_uri: "/Common/", state: "1001", style: "white", href: "" }); }