fix: login issue

This commit is contained in:
qier222 2021-01-29 10:42:38 +08:00
parent f3c3d841f2
commit 94f7d7b928
2 changed files with 13 additions and 23 deletions

View File

@ -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}`;

View File

@ -17,6 +17,7 @@
v-model="countryCode"
@focus="inputFocus = 'phone'"
@blur="inputFocus = ''"
@keyup.enter="login"
/>
<input
id="phoneNumber"
@ -24,6 +25,7 @@
v-model="phoneNumber"
@focus="inputFocus = 'phone'"
@blur="inputFocus = ''"
@keyup.enter="login"
/>
</div>
</div>
@ -39,6 +41,7 @@
v-model="email"
@focus="inputFocus = 'email'"
@blur="inputFocus = ''"
@keyup.enter="login"
/>
</div>
</div>
@ -56,6 +59,7 @@
v-model="password"
@focus="inputFocus = 'password'"
@blur="inputFocus = ''"
@keyup.enter="login"
/>
</div>
</div>
@ -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);
}
},
},