|
@@ -1,15 +1,146 @@
|
|
|
var loginCard = new Vue({
|
|
|
- el: '#login-card-container',
|
|
|
- delimiters: ['${', '}'],
|
|
|
- data: function () {
|
|
|
- return {}
|
|
|
+ el: '#login-card-container',
|
|
|
+ delimiters: ['${', '}'],
|
|
|
+ data: function () {
|
|
|
+ return {
|
|
|
+ phoneVal: '',
|
|
|
+ captchaVal: '',
|
|
|
+ codeVal: '',
|
|
|
+ focus: {
|
|
|
+ phone: false,
|
|
|
+ captcha: false,
|
|
|
+ code: false
|
|
|
+ },
|
|
|
+ error: {
|
|
|
+ phone: false,
|
|
|
+ captcha: false,
|
|
|
+ code: false
|
|
|
+ },
|
|
|
+ imgCaptcha: '/front/landpage/captcha',
|
|
|
+ smsText: '获取验证码',
|
|
|
+ phoneErrorText: '手机号码输入错误',
|
|
|
+ captchaErrorText: '图形验证码输入错误',
|
|
|
+ codeErrorText: '短信验证码输入错误',
|
|
|
+ countdown: 0,
|
|
|
+ beforeTime: -1,
|
|
|
+ sendCodeStatus: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ stopClickCode: function () {
|
|
|
+ var phonePass = !this.error.phone && this.phoneVal && this.phoneVal.length === 11
|
|
|
+ var captchaPass = !this.error.captcha && this.captchaVal && this.captchaVal.length === 4
|
|
|
+ return !(phonePass && captchaPass)
|
|
|
+ },
|
|
|
+ submitStatus: function () {
|
|
|
+ var phonePass = !this.error.phone && this.phoneVal && this.phoneVal.length === 11
|
|
|
+ var captchaPass = !this.error.captcha && this.captchaVal && this.captchaVal.length === 4
|
|
|
+ var codePass = !this.error.code && this.codeVal && this.codeVal.length === 6
|
|
|
+ return phonePass && captchaPass && codePass
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created: function () {
|
|
|
+ this.checkLogin()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ checkLogin: function () {
|
|
|
+ console.log('checkLogin')
|
|
|
+ },
|
|
|
+ onFocus: function (item) {
|
|
|
+ this.focus[item] = true
|
|
|
+ this.error[item] = false
|
|
|
+ },
|
|
|
+ onBlur: function (item) {
|
|
|
+ this.focus[item] = false
|
|
|
+ this.error[item] = !this.ruleFormItem(item)
|
|
|
+ },
|
|
|
+ onPhoneInput: function (val) {
|
|
|
+ if (val.length >= 11) {
|
|
|
+ this.ruleFormItem('phone')
|
|
|
+ this.error.phone = !this.ruleFormItem('phone')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ changeCaptcha: function() {
|
|
|
+ this.imgCaptcha = '/front/landpage/captcha?v=' + Date.now()
|
|
|
},
|
|
|
- created: function () {
|
|
|
- this.checkLogin()
|
|
|
+ ruleFormItem (type) {
|
|
|
+ if (type === 'phone') {
|
|
|
+ var phoneReg = /^[1][3-9][0-9]{9}$/.test(this.phoneVal)
|
|
|
+ var createPhoneReg = /^[1][0][0][0-9]{8}$/.test(this.phoneVal)
|
|
|
+ var checkStatus = phoneReg || createPhoneReg
|
|
|
+ return this.phoneVal.length ? checkStatus : true
|
|
|
+ } else if (type === 'captcha') {
|
|
|
+ var checkStatus = this.captchaVal.length === 4
|
|
|
+ return this.captchaVal.length ? checkStatus : true
|
|
|
+ } else if (type === 'code') {
|
|
|
+ var checkStatus = this.codeVal.length === 6
|
|
|
+ return this.codeVal.length ? checkStatus : true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ajaxSendCode: function (type, code) {
|
|
|
+ var _this = this
|
|
|
+ $.post("/phone/login",{
|
|
|
+ reqType: type,
|
|
|
+ register: 'true',
|
|
|
+ phone: _this.phoneVal,
|
|
|
+ code: code
|
|
|
+ },function(r){
|
|
|
+ if (r.status==-1) {
|
|
|
+ _this.error.phone = true
|
|
|
+ _this.phoneErrorText = '手机号格式错误'
|
|
|
+ } else if (r.status== -2){
|
|
|
+ //图形验证码错误
|
|
|
+ _this.error.captcha = true
|
|
|
+ _this.captchaErrorText = '图形验证码输入错误'
|
|
|
+ _this.changeCaptcha()
|
|
|
+ } else if (r.status==-3){
|
|
|
+ _this.error.phone = true
|
|
|
+ _this.phoneErrorText = '手机号已被注册'
|
|
|
+ _this.changeCaptcha()
|
|
|
+ } else {
|
|
|
+ sessionStorage.setItem('login-verify-start-time', new Date().getTime())
|
|
|
+ _this.startTimeDown()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getCodeFn: function () {
|
|
|
+ if (this.stopClickCode) return
|
|
|
+ this.ajaxSendCode('sendIdentCode', this.captchaVal)
|
|
|
+ },
|
|
|
+ startTimeDown: function () {
|
|
|
+ this.sendCodeStatus = false
|
|
|
+ this.countdown = 60
|
|
|
+ this.beforeTime = new Date().getTime()
|
|
|
+ var _this = this
|
|
|
+ var timeInt = setInterval(function() {
|
|
|
+ if (_this.beforeTime !== -1) {
|
|
|
+ var nowCount = 60 - Math.ceil((new Date().getTime() - _this.beforeTime) / 1000)
|
|
|
+ if (nowCount < _this.countdown) {
|
|
|
+ _this.countdown = nowCount
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _this.countdown--
|
|
|
+ if (_this.countdown <= 0) {
|
|
|
+ _this.sendCodeStatus = true
|
|
|
+ _this.beforeTime = -1
|
|
|
+ window.clearInterval(timeInt)
|
|
|
+ }
|
|
|
+ }, 1000)
|
|
|
},
|
|
|
- methods: {
|
|
|
- checkLogin: function () {
|
|
|
- console.log('checkLogin')
|
|
|
+ onSubmitReg: function () {
|
|
|
+ var _this = this
|
|
|
+ $.post("/phone/login",{
|
|
|
+ reqType:"identCodeLogin",
|
|
|
+ identCode: _this.codeVal,
|
|
|
+ source:''
|
|
|
+ },function(r){
|
|
|
+ if(r.status==1){
|
|
|
+ logic(r.userInfo, mynum);
|
|
|
+ }else if(r.status==-1){
|
|
|
+ _this.error.code = true
|
|
|
+ _this.codeErrorText = '短信验证码输入错误'
|
|
|
}
|
|
|
+ });
|
|
|
}
|
|
|
+ }
|
|
|
})
|