Commit 8957e28898763dae9f4064d5b4522cc737305d9b

Authored by Andy
1 parent 8cb58a4c

停车服务登录 重复发送验证码 bug修复

src/utils/request.js
... ... @@ -46,13 +46,17 @@ service.interceptors.response.use(
46 46 const res = response.data;
47 47 // if the custom code is not 20000, it is judged as an error.
48 48 if (res.code !='8888') {
49   - Message({
50   - message: res.msg || 'Error',
51   - type: 'error',
52   - duration: 5 * 1000
53   - })
  49 + if(res.code!='1011'){
  50 + Message({
  51 + message: res.msg || 'Error',
  52 + type: 'error',
  53 + duration: 5 * 1000
  54 + })
  55 + return Promise.reject(res.msg || 'error')
  56 + }else{
  57 + return res
  58 + }
54 59  
55   - return Promise.reject(res.msg)
56 60 } else {
57 61 return res
58 62 }
... ...
src/views/login/index.vue
... ... @@ -39,7 +39,7 @@
39 39 onkeyup = "value=value.replace(/[^\d]/g,'')"
40 40 @keyup.enter.native="handleLogin"
41 41 />
42   - <el-button type="primary" @click="getVerifyCode" :disabled="disabled" style="float:right;margin-top:6px;margin-right:10px;">{{btnTitle}}</el-button>
  42 + <el-button type="primary" @click="getVerifyCode" :disabled="isDisable" style="float:right;margin-top:6px;margin-right:10px;">{{btnTitle}}</el-button>
43 43 </el-form-item>
44 44  
45 45 <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;"
... ... @@ -85,7 +85,7 @@ export default {
85 85 password: [{ required: true, trigger: 'blur', validator: validatePassword }]
86 86 },
87 87 loading: false,
88   - disabled: false,
  88 + isDisable: false,
89 89 btnTitle: '发送验证码',
90 90 redirect: undefined
91 91 }
... ... @@ -100,13 +100,16 @@ export default {
100 100 },
101 101 methods: {
102 102 getVerifyCode(){
  103 + this.isDisable = true;
103 104 let phone = this.loginForm.phone;
104 105 if (!this.loginForm.phone) {
  106 + this.isDisable = false;
105 107 this.$message({
106 108 type: 'error',
107 109 message: '请输入正确的手机号!'
108 110 });
109 111 } else if(!/^1[345678]\d{9}$/.test(this.loginForm.phone)) {
  112 + this.isDisable = false;
110 113 this.$message({
111 114 type: 'error',
112 115 message: '请输入正确的手机号!'
... ... @@ -114,39 +117,53 @@ export default {
114 117 }
115 118 //获取验证码
116 119 else {
  120 +
117 121 sendValidatorCode(phone).then(response =>{
118 122 let data = response;
119 123 if(data.code=='8888'){
  124 + console.log(111);
  125 + this.validateBtn();
120 126 this.$message({
121 127 type: 'success',
122 128 message: '验证码发送成功!'
123 129 });
124   - this.validateBtn();
125 130 }else{
  131 + this.isDisable = false;
126 132 this.$message({
127 133 type: 'error',
128 134 message: data.msg
129 135 });
130 136 }
131 137 });
132   -
133   -
134 138 }
135 139 },
136 140 validateBtn(){
137 141 //倒计时
  142 + let that = this, time = 60;
  143 + let sendTimer = setInterval(function(){
  144 + that.isDisable = true;
  145 + time--;
  146 + that.btnTitle = time + '秒后重试';
  147 + if(time <=0){
  148 + that.isDisable = false;
  149 + clearInterval(sendTimer);
  150 + that.btnTitle = "获取验证码";
  151 + }
  152 + },1000)
  153 +
  154 + /*
138 155 let time = 60;
139 156 let timer = setInterval(() => {
140 157 if(time == 0) {
141 158 clearInterval(timer);
142   - this.disabled = false;
143   - this.btnTitle = "获取验证码";
  159 + that.disabled = false;
  160 + that.btnTitle = "获取验证码";
144 161 } else {
145   - this.btnTitle =time + '秒后重试';
146   - this.disabled = true;
  162 + that.btnTitle =time + '秒后重试';
  163 + that.disabled = true;
147 164 time--
148 165 }
149   - },1000)
  166 + },1000)*/
150 167 },
151 168 handleLogin() {
152 169 this.$refs.loginForm.validate(valid => {
... ...