diff --git a/src/App.vue b/src/App.vue index 920aeee..4c725af 100644 --- a/src/App.vue +++ b/src/App.vue @@ -34,9 +34,10 @@ const store = useStore(); //载入localstorage的设置 store.commit("loadSettings"); +store.state.settings.playing = false; //默认停止播放 store.commit("loadCaches"); -router.replace('/discover/recommend') +// router.replace('/discover/recommend') const showPlaying = ref(false); //是否显示播放列表 diff --git a/src/router/index.js b/src/router/index.js index 33f0ee9..104e9b9 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,15 +3,15 @@ import pubsub from 'pubsub-js' import Home from "../views/Home.vue"; const routes = [ - // { - // path: "/", - // redirect: "/discover/recommend", - // name: "index", - // // component: ()=> import('@/views/Home.vue'), - // // meta:{ - // // title:'zmusic', - // // } - // }, + { + path: "/", + redirect: "/discover/recommend", + name: "index", + // component: ()=> import('@/views/Home.vue'), + // meta:{ + // title:'zmusic', + // } + }, { path: "/discover", name: "discover", diff --git a/src/store/index.js b/src/store/index.js index f355c5f..328d5c0 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -7,6 +7,8 @@ export default createStore({ settings: { currentRoute: "/discover/recommend", //当前路由 songId: 0, //歌曲id + playing: false, //是否播放 + playMode: 0, //播放模式:0-3,顺序,循环,单曲,随机。 lastPlayed: [], //最近播放 playingList: [], //当前播放 }, @@ -53,7 +55,7 @@ export default createStore({ //载入settings设置 loadSettings(state) { const l = localStorage.getItem("zmusic.settings"); - if (l) state.settings = JSON.parse(l); + if (l) state.settings ={...state.settings, ...JSON.parse(l)}; }, //保存settings设置 saveSettings(state, settings) { @@ -64,7 +66,7 @@ export default createStore({ //载入caches设置 loadCaches(state) { const l = localStorage.getItem("zmusic.caches"); - if (l) state.caches = JSON.parse(l); + if (l) state.caches = {...state.caches, ...JSON.parse(l)} }, //保存caches设置 saveCaches(state, caches) { @@ -81,7 +83,7 @@ export default createStore({ //载入theme设置 loadTheme(state) { const l = localStorage.getItem("zmusic.theme"); - if (l) state.theme = JSON.parse(l); + if (l) state.theme = {...state.theme, ...JSON.parse(l)}; }, //保存theme设置 saveTheme(state, theme) { @@ -98,6 +100,20 @@ export default createStore({ state.settings.lastPlayed = p; saveLoaclSettings(state.settings); }, + addToPlayingList(state, song) { + //如果没有,设置为[] + if (!state.settings.playingList) + state.settings.playingList = []; + + let f = state.settings.playingList.find((item) => { + return item.id === song.id; + }); + if (!f) { + // console.log("add to playingList"); + state.settings.playingList.unshift(song) + saveLoaclSettings(state.settings); + } + }, }, actions: {}, modules: {}, diff --git a/src/views/common/PlayingList.vue b/src/views/common/PlayingList.vue index e9de524..d6dc770 100644 --- a/src/views/common/PlayingList.vue +++ b/src/views/common/PlayingList.vue @@ -1,10 +1,15 @@