diff --git a/src/store/initLocalStorage.js b/src/store/initLocalStorage.js index dce2c85845..cf43eb9c0d 100644 --- a/src/store/initLocalStorage.js +++ b/src/store/initLocalStorage.js @@ -1,9 +1,13 @@ import { playlistCategories } from "@/utils/staticData"; +console.log("[debug][initLocalStorage.js]"); +const enabledPlaylistCategories = playlistCategories + .filter((c) => c.enable) + .map((c) => c.name); + let localStorage = { player: {}, settings: { - playlistCategories, lang: null, appearance: "auto", musicQuality: 320000, @@ -20,6 +24,7 @@ let localStorage = { enableDiscordRichPresence: false, enableGlobalShortcut: true, showLibraryDefault: false, + enabledPlaylistCategories, }, data: { user: {}, diff --git a/src/store/mutations.js b/src/store/mutations.js index 70ed9c6857..a30b6ceb00 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -22,16 +22,16 @@ export default { state.data[key] = value; }, togglePlaylistCategory(state, name) { - let cat = state.settings.playlistCategories.find((c) => c.name === name); - cat.enable = !cat.enable; - state.settings.playlistCategories = state.settings.playlistCategories.map( - (c) => { - if (c.name === name) { - return cat; - } - return c; - } + const index = state.settings.enabledPlaylistCategories.findIndex( + (c) => c.name === name ); + if (index !== -1) { + state.settings.enabledPlaylistCategories = state.settings.enabledPlaylistCategories.filter( + (c) => c.name !== name + ); + } else { + state.settings.enabledPlaylistCategories.push(name); + } }, updateToast(state, toast) { state.toast = toast; diff --git a/src/utils/staticData.js b/src/utils/staticData.js index 2f4c417244..c4ccbf0a60 100644 --- a/src/utils/staticData.js +++ b/src/utils/staticData.js @@ -11,7 +11,6 @@ export const byAppleMusic = [ name: "\u4e2d\u563b\u5408\u74a7", id: 5277771961, }, - { coverImgUrl: "https://p1.music.126.net/cPaBXr1wZSg86ddl47AK7Q==/109951165375130918.jpg", @@ -38,6 +37,11 @@ export const playlistCategories = [ enable: true, bigCat: "static", }, + // { + // name: "For You", + // enable: true, + // bigCat: "static", + // }, { name: "推荐歌单", enable: true, diff --git a/src/utils/updateApp.js b/src/utils/updateApp.js index bd1b565eeb..59d565447d 100644 --- a/src/utils/updateApp.js +++ b/src/utils/updateApp.js @@ -4,20 +4,20 @@ import pkg from "../../package.json"; const updateSetting = () => { const parsedSettings = JSON.parse(localStorage.getItem("settings")); const { - playlistCategories, showUnavailableSongInGreyStyle, automaticallyCacheSongs, nyancatStyle, showLyricsTranslation, minimizeToTray, + enabledPlaylistCategories, } = initLocalStorage.settings; const settings = { - playlistCategories, showUnavailableSongInGreyStyle, automaticallyCacheSongs, nyancatStyle, showLyricsTranslation, minimizeToTray, + enabledPlaylistCategories, ...parsedSettings, }; diff --git a/src/views/explore.vue b/src/views/explore.vue index 0ac4aff4f2..4711d5ada9 100644 --- a/src/views/explore.vue +++ b/src/views/explore.vue @@ -3,13 +3,13 @@

{{ $t("explore.explore") }}

- {{ cat.name }} + {{ category }}
-
-
+
+
{{ bigCat }}
{{ cat.name }}
@@ -40,21 +42,21 @@
{{ $t("explore.loadMore") }}
@@ -70,6 +72,7 @@ import { recommendPlaylist, toplists, } from "@/api/playlist"; +import { playlistCategories } from "@/utils/staticData"; import ButtonTwoTone from "@/components/ButtonTwoTone.vue"; import CoverRow from "@/components/CoverRow.vue"; @@ -102,6 +105,9 @@ export default { return "none"; }, }, + activated() { + this.loadData(); + }, methods: { ...mapMutations(["togglePlaylistCategory"]), loadData() { @@ -167,15 +173,12 @@ export default { }); }, getCatsByBigCat(name) { - return this.settings.playlistCategories.filter((c) => c.bigCat === name); + return playlistCategories.filter((c) => c.bigCat === name); }, toggleCat(name) { this.togglePlaylistCategory(name); }, }, - activated() { - this.loadData(); - }, beforeRouteUpdate(to, from, next) { NProgress.start(); this.showLoadMoreButton = false;