diff --git a/src/utils/request.js b/src/utils/request.js index d5fe447..76dba79 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -18,28 +18,10 @@ const service = axios.create({ timeout: 15000, }); -const errors = new Map([ - [401, "The token you are using has expired."], - [301, "You must login to use this feature."], - [-1, "An unexpected error has occurred: "], -]); - service.interceptors.response.use( (response) => { const res = response.data; - - if (response.status !== 200) { - alert( - errors.has(response.status) - ? errors.get(response.status) || - // null = `The server returned ${res.msg}` - `The server returned ${res.msg}` - : // -1 = default expection message - errors.get(-1) + response.status - ); - } else { - return res; - } + return res; }, (error) => { const errMsg = `error: ${error}`; diff --git a/src/views/loginAccount.vue b/src/views/loginAccount.vue index 7423f92..a355a34 100644 --- a/src/views/loginAccount.vue +++ b/src/views/loginAccount.vue @@ -17,6 +17,7 @@ v-model="countryCode" @focus="inputFocus = 'phone'" @blur="inputFocus = ''" + @keyup.enter="login" /> @@ -39,6 +41,7 @@ v-model="email" @focus="inputFocus = 'email'" @blur="inputFocus = ''" + @keyup.enter="login" /> @@ -56,6 +59,7 @@ v-model="password" @focus="inputFocus = 'password'" @blur="inputFocus = ''" + @keyup.enter="login" /> @@ -139,7 +143,7 @@ export default { this.phone === "" || this.password === "" ) { - alert("国家区号、手机或密码不正确"); + alert("国家区号或手机号不正确"); this.processing = false; return false; } @@ -152,15 +156,15 @@ export default { this.password === "" || !emailReg.test(this.email) ) { - alert("邮箱或密码不正确"); + alert("邮箱不正确"); return false; } return true; }, login() { - this.processing = true; if (this.mode === "phone") { this.processing = this.validatePhone(); + if (!this.processing) return; loginWithPhone({ countrycode: this.countryCode.replace("+", "").replace(/\s/g, ""), phone: this.phoneNumber.replace(/\s/g, ""), @@ -174,6 +178,7 @@ export default { }); } else { this.processing = this.validateEmail(); + if (!this.processing) return; loginWithEmail({ email: this.email.replace(/\s/g, ""), password: "fakePassword", @@ -191,9 +196,12 @@ export default { this.processing = false; return; } - if (data.code !== 502) { + if (data.code === 200) { this.updateData({ key: "user", value: data.profile }); this.afterLogin(); + } else { + this.processing = false; + alert(data.msg ?? data.message); } }, },