$(document.body).on('click', '.event-el', function (e) { var el = $(this), func = el.data('func'); if (!func) return; switch (func) { case 'send': send(el.parents('div.form-group')); break; } }); function identity(el) {//登录调用,此处el是从login.html的登录form里面获取的数据 this.$F = el; this.F = el.get(0); return this.init(); } function phoneLogin(el) {//注册调用,此处el是从login.html的注册form里面获取的数据 this.$F = el; this.F = el.get(0); return this.init(); } function RegisterPhone(el) {//手机注册调用,此处el是从register/index.html的手机注册form里面获取的数据 this.$F = el; this.F = el.get(0); return this.init(); } function RegisterEmail(el) {//邮箱注册调用,此处el是从register/index.html的邮箱注册form里面获取的数据 this.$F = el; this.F = el.get(0); return this.init(); } function send(el) { var _this = el.parent('form'), sendType = ['login', 'register', 'recover'], btn = el.children('div.input-group').children('a'), number = _this.children('div.form-group').eq(1), input = number.children('input'), getnumber = number.children('input').val(), lock = btn.attr('disabled'); sendType = sendType[btn.attr('data-id')]; if (lock) return; if (!getnumber) { YZ.Valid(input, '请输入手机号码', true); return false; } if (!isMobile(getnumber)) { YZ.Valid(input, '请输入正确的手机号码', true); return false; } if (getnumber) { YZ.Valid(input); $.ajax({ url: BASE_URL + sendType + '/sendSms', type: 'post', dataType: 'json', data: { mobile: getnumber, }, success: function (rs) { if (rs.state == 0) { errorMessage(_this, rs.message); } else if (rs.state == 1) { delayedGet(60, '#sendCode', '重新发送验证码'); } return false; }, error: function (rs) { errorMessage(_this, rs || '系统错误,请重试'); return false; } }); } else { YZ.Valid(input, '请输入手机号码', true); return false; } } function regMailFail(el) { this.$F = el; this.F = el.get(0); return this.init(); }//邮箱验证失败 function freshCode(el, type) {//刷新验证码 el = $(el); var url = el.data('url'); el.attr('src', url + (url.indexOf('?') > 0 ? '&' : '?') + new Date().getTime()); }//刷新验证码 function errorMessage(elem, messageStr) {//错误提示框 var message = elem.children('.show-error'); $('html').scrollTop(0); message.removeClass('hide'); message.text(messageStr || '注册失败'); }//顶部提示框 function checkUserPhone() {//注册检查手机号码 var that = $(this), username = $.trim(this.value); if (!username) return false; if (!(isMobile(username))) { YZ.Valid(that.next().context, '请输入正确的手机号码'); $('#msgCodeInput').value = ''; return false; } phoneReg = true; YZ.Valid(that.next().context); $.ajax({ url: BASE_URL + 'register/checkuser', type: 'post', dataType: 'json', data: { action: 'mobile', username: username }, success: function (rs) { if (rs.state == 0) { YZ.Valid(that.next().context, '该账号已注册,请更换'); phoneReg = false; return false; } if (rs.state == 1) { that.next().addClass('hide'); YZ.Valid(that.next().context); return false; } }, error: function () { YZ.Valid(that.next().context, '系统错误,请重新输入'); phoneReg = false; return false; } }); }//注册验证手机 function checkUsefull() { var that = $(this), username = $.trim(this.value); if (!username) return false; if (!(isMobile(username))) { YZ.Valid(that.next().context, '请输入正确的手机号码'); $('#msgCodeInput').value = ''; return false; } YZ.Valid(that.next().context); $.ajax({ url: BASE_URL + 'login/checkuser', type: 'post', dataType: 'json', data: { action: 'mobile', username: username }, success: function (rs) { if (rs.state == 1) { that.next().addClass('hide'); YZ.Valid(that.next().context); return false; } if (rs.state == 0) { YZ.Valid(that.next().context, '该账号还没注册,请先注册'); return false; } }, error: function () { YZ.Valid(that.next().context, '系统错误,请重新输入'); return false; } }); }//登录时验证手机是否已注册 function checkUserEmail() {//检查邮箱 var that = $(this), username = $.trim(this.value); emailReg = false; if (!username) return false; if (!(isEmail(username))) { YZ.Valid(that.next().context, '请输入正确的邮箱'); return false; } else { emailReg = true; YZ.Valid(that.next().context); } }//验证邮箱 function confirmPassword(i, btn) {//验证两次输入的密码是否相同,需要绑定两个一样的name【password,affirm】,并传入当前绑定的控件this var that = $(btn); YZ.Valid(that.next().context); if (i.password.value != i.affirm.value) { YZ.Valid(that.next().context, '两次输入的密码不一致'); return; } }//验证密码相同 function checKey(i) {//判断密码是否为6到18位 var that = $(i), key = $.trim(i.value); if (!key) return false; YZ.Valid(that.next('div.help-block').context); if (key.length < 6 || key.length > 18) { YZ.Valid(that.next('div.help-block').context, '请输入6到18位的密码'); return; } }//验证密码长度 function activate(btn, msg, url) { var that = $(btn); //YZ.Valid(that.next().context,'请输入正确的手机号码',,url); }//特殊情况下的激活 function delayedGet(time, el, beTxt) {//验证码倒计时 time--; var ele = $(el); if (time < 1) { ele.attr('disabled', false); ele.text(beTxt); } else { ele.attr('disabled', true); ele.text(time + '秒后重新获取'); setTimeout('delayedGet(' + time + ',"' + el + '","' + beTxt + '")', 1000); } }//倒计时 function vcodeChange(el, type) {//重新请求验证码 el = $(el); var url = el.data('url'); el.attr('src', url + (url.indexOf('?') > 0 ? '&' : '?') + new Date().getTime()); }//重新请求验证码 function sendEmail(el) {//发送邮件验证 el = $(el); el.attr('disabled', true); $.ajax({ url: BASE_URL + 'register/againmail', type: 'post', dataType: 'json', success: function (rs) { if (rs.state == 1) { $('#senderror').text(''); delayedGet(60, '#checkSms', el.text()); } else { $('#senderror').text('(' + rs.message + ')'); el.attr('disabled', false); } }, error: function () { $('#senderror').text('(系统错误,请重试)'); el.attr('disabled', false); } }); }//发送邮件 !function () { //自调即时验证输入信息的正确性,用来在注册的那一步来验证 function initError() { this.$error = $('.has-error', this.$F); if (!this.$error.is(':hidden')) this.$error.addClass('hide'); } function hideMessage() { $(this).find('.help-block').addClass('hide'); $(this).find('.has-error').removeClass('has-error'); } function showMessage(e, s, ipt) { if (e.$error.is(':hidden')) e.$error.removeClass('hide'); e.$error.text(s); if (ipt) ipt.focus(); }; function checkUsername(v) { if (!isMobile(v) && !isEmail(v) && !isUsername(v))return false; return true; }; function checkPassword(v) { if (v.value.length < 6 || v.value.length > 18)return false; return true; } var $box = $("#box"); //TODO 登录验证原型 identity.prototype.init = function () {//调用 initError.call(this); this.initEvent(); return this; }; identity.prototype.messages = [ '请输入账号', '请输入密码', '请输入验证码', '系统错误,请重试' ]; identity.prototype.initEvent = function () { var _this = this; _this.$F.on('submit', function () { hideMessage.call(this); if (!this.username.value) { YZ.Valid(this.username, _this.messages[0], true); return; } else if (!this.password.value) { YZ.Valid(this.password, _this.messages[1], true); return; } var code = $('#loginVcode'); if(code.length){ if (!code.hasClass('hide')) { if (!this.vcode.value) { YZ.Valid(this.vcode, _this.messages[2], true); return; } YZ.Valid(this.vcode); } } hideMessage.call(this); $.ajax({ url: BASE_URL + 'login', type: 'post', dataType: 'json', data: _this.$F.serialize(), success: function (rs) { if (rs.state == 0) { errorMessage(_this.$F, rs.message); if (rs.content && rs.content.is_code) { var img = code.find('img'); if (!img.length) { code.removeClass('hide'); $(_this.F.vcode).after(''); } } } else if (rs.state == 1) { $('img-load').removeClass('hide'); location.href = rs.content && rs.content.forward ? rs.content.forward : BASE_URL; } else if (rs.state == 2) { YZ.ValidWithBtn(_this.F.username, (rs.content), rs.message.forward); } else if (rs.state == false) { errorMessage(_this.$F, rs.message); } }, error: function (rs) { errorMessage(_this.$F, _this.messages[3]); } }); return false; }); return false; }; //TODO 手机登录验证原型 phoneLogin.prototype.init = function () { initError.call(this); this.initEvent(); return this; }; phoneLogin.prototype.messages = [ '请输入正确的注册手机号码', '请输入注册手机号码', '请输入手机验证码', '请输入密码', '请输入验证码', '两次输入的密码不一致', '请阅读并同意服务条款', '系统错误,请重试' ]; phoneLogin.prototype.initEvent = function () { var _this = this; hideMessage.call(this); if (_this.F.username.value) { if (!isMobile(_this.F.username.value)) { YZ.Valid(this.username, _this.messages[0], true); return; } } else { YZ.Valid(this.username, _this.messages[1], true); return; } if (!_this.F.smsPhone.value) { YZ.Valid(this.smsPhone, _this.messages[2], true); return; } if (!_this.F.password.value) { YZ.Valid(this.password, _this.messages[3], true); return; } if (_this.F.vcode && !_this.F.vcode.value) { YZ.Valid(this.vcode, _this.messages[4], true); return; } if (_this.F.password.value != _this.F.affirm.value) { YZ.Valid((_this.F.password), _this.messages[5]); return; } if (_this.F.fuwu) { if (!_this.F.fuwu.checked) { errorMessage(_this.$F, _this.messages[6]); } } hideMessage.call(this); _this.$F.on('submit', function () {//手机登录发送 if (true) { $.ajax({ url: BASE_URL + 'login', type: 'post', dataType: 'json', data: _this.$F.serialize(), success: function (rs) { if (rs.state == 0) { errorMessage(_this.$F, rs.message); } else if (rs.state == 1) { location.href = rs.content && rs.content.forward ? rs.content.forward : BASE_URL; } else if (rs.state == 2) { YZ.ValidWithBtn(_this.F.email, (rs.content), rs.message.forward); } }, error: function () { errorMessage(_this.$F, _this.messages[7]); } }); } }); }; /*------------------------------------ register ----------------------------------------*/ //TODO 手机注册验证原型 RegisterPhone.prototype.init = function () { initError.call(this); this.initEvent(); return this; }; RegisterPhone.prototype.messages = [ '请输入正确的手机号码', '请输入手机号码', '请输入手机验证码', '请输入密码', '请输入验证码', '两次输入的密码不一致', '请阅读并同意服务条款', '系统错误,请重试' ]; RegisterPhone.prototype.initEvent = function () { var _this = this; $(_this.F.affirm).on('blur', function () { var btn = this; confirmPassword(_this.F, btn); }); $(_this.F.password).on('blur', function () { var btn = this; checKey(btn) }); _this.$F.on('submit', function () {//手机注册发送 YZ.Valid(this.mobile); if (_this.F.mobile.value) { if (!isMobile(_this.F.mobile.value)) { YZ.Valid(this.mobile, _this.messages[0], true); return; } } else { YZ.Valid(this.mobile, _this.messages[1], true); return; } if (!_this.F.smsPhone.value) { YZ.Valid(this.smsPhone, _this.messages[2], true); return; } if (!_this.F.password.value) { YZ.Valid(this.password, _this.messages[3], true); return; } if (_this.F.vcode && !_this.F.vcode.value) {//if has vcode YZ.Valid(this.vcode, _this.messages[4], true); return; } if (_this.F.password.value != _this.F.affirm.value) { YZ.Valid((_this.F.password), _this.messages[5]); return; } if (_this.F.fuwu) { if (!_this.F.fuwu.checked) { errorMessage(_this.$F, _this.messages[6]); } } if (true) { $.ajax({ url: BASE_URL + 'register', type: 'post', dataType: 'json', data: { action: 'mobile', username: _this.F.mobile.value, smscode: _this.F.smsPhone.value, password: _this.F.password.value, repassword: _this.F.affirm.value, vcode: _this.F.vcode ? _this.F.vcode.value : '', read: 1, }, success: function (rs) { if (rs.state == 0) { errorMessage(_this.$F, rs.message); } else if (rs.state == 1) { location.href = BASE_URL + 'register/success'; } }, error: function (rs) { if (rs.message) { errorMessage(_this.$F, rs.message); return; } errorMessage(_this.$F, _this.messages[7]); } }); } }); } //TODO 邮箱注册验证原型 RegisterEmail.prototype.init = function () { initError.call(this); this.initEvent(); return this; }; RegisterEmail.prototype.messages = [ '请输入正确的注册邮箱', '请输入注册邮箱', '请输入密码', '请输入确认密码', '请输入验证码', '两次输入的密码不一致', '请阅读并同意服务条款', '系统错误,请重试' ]; RegisterEmail.prototype.initEvent = function () { var _this = this; $(_this.F.password).on('blur', function () { var btn = this; checKey(btn) }); $(_this.F.affirm).on('blur', function () { var btn = this; confirmPassword(_this.F, btn); }); _this.$F.on('submit', function () {//邮箱注册发送 if (_this.F.email.value) { if (!isEmail(_this.F.email.value)) { YZ.Valid(this.email, _this.messages[0], true); return; } } else { YZ.Valid(this.email, _this.messages[1], true); return; } if (!_this.F.password.value) { YZ.Valid(this.password, _this.messages[2], true); return; } if (!_this.F.affirm.value) { YZ.Valid(this.password, _this.messages[3], true); return; } if (_this.F.vcode && !_this.F.vcode.value) { YZ.Valid(this.vcode, _this.messages[4], true); return; } if (_this.F.password.value != _this.F.affirm.value) { YZ.Valid(this.password, _this.messages[5], true); return; } if (_this.F.fuwu) { if (!_this.F.fuwu.checked) { errorMessage(_this.$F, _this.messages[6]); return; } } if (true) { $.ajax({ url: BASE_URL + 'register', type: 'post', dataType: 'json', data: { action: 'email', username: _this.F.email.value, password: _this.F.password.value, repassword: _this.F.affirm.value, vcode: _this.F.vcode ? _this.F.vcode.value : '', read: 1, }, success: function (rs) { if (rs.state == 0) { errorMessage(_this.$F, rs.message); } if (rs.state == 1) { location.href = BASE_URL + 'register/sendmail'; } if (rs.state == 2) { YZ.ValidWithBtn(_this.F.email, (rs.content), rs.message.forward); } }, error: function () { errorMessage(_this.$F, _this.messages[7]); } }); } }) }; //TODO 邮箱验证失败 regMailFail.prototype.init = function () { initError.call(this); this.initEvent(); return this; }; regMailFail.prototype.initEvent = function () { var _this = this; }; var $box = $("#box").find('.mask').click(function () { hideBox(); }).end(); function showBox() { $('#smsPrompt').text(''); // freshCode('#mobileImgVcode'); $box.removeClass('hide'); } function hideBox() { $box.addClass('hide'); } }();