mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-03-06 02:05:20 +08:00
fix: login issue
This commit is contained in:
parent
f3c3d841f2
commit
94f7d7b928
@ -18,28 +18,10 @@ const service = axios.create({
|
|||||||
timeout: 15000,
|
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(
|
service.interceptors.response.use(
|
||||||
(response) => {
|
(response) => {
|
||||||
const res = response.data;
|
const res = response.data;
|
||||||
|
return res;
|
||||||
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;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
const errMsg = `error: ${error}`;
|
const errMsg = `error: ${error}`;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
v-model="countryCode"
|
v-model="countryCode"
|
||||||
@focus="inputFocus = 'phone'"
|
@focus="inputFocus = 'phone'"
|
||||||
@blur="inputFocus = ''"
|
@blur="inputFocus = ''"
|
||||||
|
@keyup.enter="login"
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
id="phoneNumber"
|
id="phoneNumber"
|
||||||
@ -24,6 +25,7 @@
|
|||||||
v-model="phoneNumber"
|
v-model="phoneNumber"
|
||||||
@focus="inputFocus = 'phone'"
|
@focus="inputFocus = 'phone'"
|
||||||
@blur="inputFocus = ''"
|
@blur="inputFocus = ''"
|
||||||
|
@keyup.enter="login"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -39,6 +41,7 @@
|
|||||||
v-model="email"
|
v-model="email"
|
||||||
@focus="inputFocus = 'email'"
|
@focus="inputFocus = 'email'"
|
||||||
@blur="inputFocus = ''"
|
@blur="inputFocus = ''"
|
||||||
|
@keyup.enter="login"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -56,6 +59,7 @@
|
|||||||
v-model="password"
|
v-model="password"
|
||||||
@focus="inputFocus = 'password'"
|
@focus="inputFocus = 'password'"
|
||||||
@blur="inputFocus = ''"
|
@blur="inputFocus = ''"
|
||||||
|
@keyup.enter="login"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -139,7 +143,7 @@ export default {
|
|||||||
this.phone === "" ||
|
this.phone === "" ||
|
||||||
this.password === ""
|
this.password === ""
|
||||||
) {
|
) {
|
||||||
alert("国家区号、手机或密码不正确");
|
alert("国家区号或手机号不正确");
|
||||||
this.processing = false;
|
this.processing = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -152,15 +156,15 @@ export default {
|
|||||||
this.password === "" ||
|
this.password === "" ||
|
||||||
!emailReg.test(this.email)
|
!emailReg.test(this.email)
|
||||||
) {
|
) {
|
||||||
alert("邮箱或密码不正确");
|
alert("邮箱不正确");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
login() {
|
login() {
|
||||||
this.processing = true;
|
|
||||||
if (this.mode === "phone") {
|
if (this.mode === "phone") {
|
||||||
this.processing = this.validatePhone();
|
this.processing = this.validatePhone();
|
||||||
|
if (!this.processing) return;
|
||||||
loginWithPhone({
|
loginWithPhone({
|
||||||
countrycode: this.countryCode.replace("+", "").replace(/\s/g, ""),
|
countrycode: this.countryCode.replace("+", "").replace(/\s/g, ""),
|
||||||
phone: this.phoneNumber.replace(/\s/g, ""),
|
phone: this.phoneNumber.replace(/\s/g, ""),
|
||||||
@ -174,6 +178,7 @@ export default {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.processing = this.validateEmail();
|
this.processing = this.validateEmail();
|
||||||
|
if (!this.processing) return;
|
||||||
loginWithEmail({
|
loginWithEmail({
|
||||||
email: this.email.replace(/\s/g, ""),
|
email: this.email.replace(/\s/g, ""),
|
||||||
password: "fakePassword",
|
password: "fakePassword",
|
||||||
@ -191,9 +196,12 @@ export default {
|
|||||||
this.processing = false;
|
this.processing = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.code !== 502) {
|
if (data.code === 200) {
|
||||||
this.updateData({ key: "user", value: data.profile });
|
this.updateData({ key: "user", value: data.profile });
|
||||||
this.afterLogin();
|
this.afterLogin();
|
||||||
|
} else {
|
||||||
|
this.processing = false;
|
||||||
|
alert(data.msg ?? data.message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user