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

@ -36,7 +36,8 @@
</span>
</div>
</div>
<div class="like-button" v-show="isLoggedIn">
<!-- 账号登录才会显示 like 图标 -->
<div class="like-button" v-show="accountLogin">
<button-icon
@click.native="likeCurrentSong"
:title="$t('player.like')"
@ -118,7 +119,7 @@
<script>
import { updateMediaSessionMetaData } from "@/utils/mediaSession";
import { mapState, mapMutations, mapActions } from "vuex";
import { isLoggedIn } from "@/utils/auth";
import { isAccountLoggedIn } from "@/utils/auth";
import { userLikedSongsIDs } from "@/api/user";
import { likeATrack } from "@/api/track";
import "@/assets/css/slider.css";
@ -144,14 +145,14 @@ export default {
setInterval(() => {
this.progress = ~~this.howler.seek();
}, 1000);
if (this.isLoggedIn) {
if (isAccountLoggedIn()) {
userLikedSongsIDs(this.settings.user.userId).then((data) => {
this.updateLikedSongs(data.ids);
});
}
},
computed: {
...mapState(["player", "howler", "settings", "liked"]),
...mapState(["player", "howler", "settings", "liked", "accountLogin"]),
currentTrack() {
return this.player.currentTrack;
},
@ -174,9 +175,6 @@ export default {
let max = ~~(this.currentTrack.dt / 1000);
return max > 1 ? max - 1 : max;
},
isLoggedIn() {
return isLoggedIn();
},
},
methods: {
...mapMutations([