var $url="/login",$urlCaptcha="/login/captcha",$urlCaptchaCheck="/login/captcha/actions/check",$urlSendSms="/login/actions/sendSms",data=utils.init({status:utils.getQueryInt("status"),pageAlert:null,captchaToken:null,captchaUrl:null,version:null,homeTitle:null,isSmsEnabled:!1,countdown:0,form:{type:"account",account:null,password:null,mobile:null,code:null,isPersistent:!1,captchaValue:null},returnUrl:utils.getQueryString("returnUrl")}),methods={apiGet:function(){var t=this;401===this.status&&(this.pageAlert={type:"error",title:"您的账号登录已过期或失效，请重新登录"}),utils.loading(this,!0),$api.get($url).then(function(i){var n=i.data;t.version=n.version,t.homeTitle=n.homeTitle,t.isSmsEnabled=n.isSmsEnabled,t.apiCaptcha()}).catch(function(t){utils.notifyError(t)}).then(function(){utils.loading(t,!1)})},apiCaptcha:function(){var t=this;utils.loading(this,!0),$api.post($urlCaptcha).then(function(i){var n=i.data;t.captchaToken=n.value,t.captchaUrl=$apiUrl+$urlCaptcha+"?token="+t.captchaToken,t.btnTypeClick()}).catch(function(t){utils.notifyError(t)}).then(function(){utils.loading(t,!1)})},apiCaptchaCheck:function(){var t=this;utils.loading(this,!0),$api.post($urlCaptchaCheck,{token:this.captchaToken,value:this.form.captchaValue}).then(function(i){t.apiSubmit()}).catch(function(i){t.apiCaptcha(),utils.loading(t,!1),utils.notifyError(i)})},apiSendSms:function(){var t=this;utils.loading(this,!0),$api.post($urlSendSms,{mobile:this.form.mobile}).then(function(i){i.data;utils.notifySuccess("验证码发送成功，10分钟内有效"),t.countdown=60;var n=setInterval(function(){t.countdown-=1,t.countdown<=0&&clearInterval(n)},1e3)}).catch(function(t){utils.notifyError(t)}).then(function(){utils.loading(t,!1)})},apiSubmit:function(){var t=this;utils.loading(this,!0),$api.post($url,{isSmsLogin:"mobile"==this.form.type,account:this.form.account,password:this.form.password?md5(this.form.password):"",mobile:this.form.mobile,code:this.form.code,isPersistent:this.form.isPersistent}).then(function(i){var n=i.data;localStorage.removeItem(ACCESS_TOKEN_NAME),localStorage.setItem(ACCESS_TOKEN_NAME,n.token),n.redirectToVerifyMobile?location.href=utils.getRootUrl("verifyMobile",{returnUrl:t.returnUrl}):t.returnUrl?location.href=t.returnUrl:t.redirectIndex()}).catch(function(t){utils.notifyError(t)}).then(function(){t.apiCaptcha(),utils.loading(t,!1)})},redirectIndex:function(){location.href=utils.getIndexUrl()},redirectLostPassword:function(){location.href=utils.getRootUrl("lostPassword")},btnTypeClick:function(){var t=this;this.$refs.formAccount.clearValidate(),this.$refs.formMobile.clearValidate(),"account"==this.form.type?setTimeout(function(){t.$refs.account.focus()},100):"mobile"==this.form.type&&setTimeout(function(){t.$refs.mobile.focus()},100)},btnCaptchaClick:function(){this.apiCaptcha()},isMobile:function(t){return/^1[3|4|5|7|8][0-9]\d{8}$/.test(t)},btnSendSmsClick:function(){this.countdown>0||(this.form.mobile?this.isMobile(this.form.mobile)?this.apiSendSms():utils.notifyError("请输入有效的手机号码"):utils.notifyError("手机号码不能为空"))},btnSubmitClick:function(){var t=this;"account"==this.form.type?this.$refs.formAccount.validate(function(i){i&&t.apiCaptchaCheck()}):this.$refs.formMobile.validate(function(i){i&&t.apiSubmit()})},btnRegisterClick:function(t){t.preventDefault(),location.href=utils.getRootUrl("register")}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiGet()}});