var app = new Vue({ el: '#app', data: { submitStatus: false, formData: { mobile: '', password: '', } }, mounted: function () { var _this = this; $(document).on('keydown', function (event) { if (event.keyCode == 13) { _this.doLogin(); } }) }, methods: { // 登录 doLogin: function () { var _this = this; if (_this.submitStatus) { return false; } if (!_this.checkForm()) { return false; } _this.submitStatus = true; $.showLoading("登录中..."); $.post('/weixin/login/doLogin', _this.formData, function (res) { _this.submitStatus = false; $.hideLoading(); if (res.code == 'success') { $.showLoading(res.message); setTimeout(function () { var url = res.data.url ? res.data.url : '/weixin/index/index'; location.href = url; }, 500); } else { $.toast(res.message, 'text'); } }, "json"); }, // 验证表单 checkForm: function () { if (this.formData.mobile == '' || this.formData.mobile == null) { $.toast("请输入手机号码", 'text'); return false; } var patternMobile = /1[3-9][0-9]{9}/; if (!patternMobile.test(this.formData.mobile)) { $.toast("请输入正确的手机号码", 'text'); return false; } if (this.formData.password == '' || this.formData.password == null) { $.toast("请输入登录密码", 'text'); return false; } var passwordPattern = /^[0-9a-zA-Z][0-9a-zA-Z\_\!\@\#\$\%\^\&\*\(\)]{2,19}/; if (!passwordPattern.test(this.formData.password)) { $.toast("登录密码格式不正确", 'text'); return false; } return true; } } })