feat: using vuex to make login status reactively (#51)

This commit is contained in:
Hawtim Zhang 2020-10-24 18:55:10 +08:00 committed by GitHub
parent 5ce9c3689a
commit 780b429fa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 110 additions and 71 deletions

View file

@ -112,9 +112,9 @@ export default {
NProgress.done();
},
methods: {
...mapMutations(["updateUser", "updateUserInfo"]),
...mapMutations(["updateUser", "updateUserInfo", "updateAccountLogin"]),
afterLogin() {
// Cookies.set("MUSIC_U", true, { expires: 3650 });
this.updateAccountLogin(true);
Cookies.set("loginMode", "account", { expires: 3650 });
userPlaylist({
uid: this.$store.state.settings.user.userId,
@ -127,18 +127,34 @@ export default {
this.$router.push({ path: "/library" });
});
},
validatePhone() {
if (
this.countryCode === "" ||
this.phone === "" ||
this.password === ""
) {
alert("国家区号、手机或密码不正确");
this.processing = false;
return false;
}
return true;
},
validateEmail() {
const emailReg = /^[A-Za-z0-9]+([_][A-Za-z0-9]+)*@([A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/;
if (
this.email === "" ||
this.password === "" ||
!emailReg.test(this.email)
) {
alert("邮箱或密码不正确");
return false;
}
return true;
},
login() {
this.processing = true;
if (this.mode === "phone") {
if (
this.countryCode === "" ||
this.phone === "" ||
this.password === ""
) {
alert("国家区号、手机或密码不正确");
this.processing = false;
return;
}
this.processing = this.validatePhone();
loginWithPhone({
countrycode: this.countryCode.replace("+", "").replace(/\s/g, ""),
phone: this.phoneNumber.replace(/\s/g, ""),
@ -156,16 +172,7 @@ export default {
alert(error);
});
} else {
let emailReg = /^[A-Za-z0-9]+([_][A-Za-z0-9]+)*@([A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/;
if (
this.email === "" ||
this.password === "" ||
!emailReg.test(this.email)
) {
alert("邮箱或密码不正确");
this.processing = false;
return;
}
this.processing = this.validateEmail();
loginWithEmail({
email: this.email.replace(/\s/g, ""),
password: "fakePassword",