重开一个组件再写当前播放完成
This commit is contained in:
@@ -2,8 +2,8 @@ import { createStore, storeKey } from "vuex";
|
||||
|
||||
export default createStore({
|
||||
state: {
|
||||
appVersion: "0.0.1",
|
||||
debugStr: "测试debug字符",
|
||||
// appVersion: "0.0.1",
|
||||
// debugStr: "测试debug字符",
|
||||
settings: {
|
||||
currentRoute: "/discover/recommend", //当前路由
|
||||
songId: 0, //歌曲id
|
||||
@@ -11,8 +11,9 @@ export default createStore({
|
||||
playMode: 0, //播放模式:0-3,顺序,循环,单曲,随机。
|
||||
lastPlayed: [], //最近播放
|
||||
playingList: [], //当前播放
|
||||
tArr: [], //测试数组
|
||||
ts: "", //测试字符
|
||||
},
|
||||
haha: 'haha',
|
||||
caches: {},
|
||||
theme: {
|
||||
//主题覆盖变量
|
||||
@@ -32,9 +33,7 @@ export default createStore({
|
||||
//根据当前路由计算主菜单的选择项
|
||||
mainMenuSelected: (state) => (menuOptions) => {
|
||||
return menuOptions.find((item) => {
|
||||
return (
|
||||
state.settings.currentRoute.indexOf(item.key) > -1
|
||||
);
|
||||
return state.settings.currentRoute.indexOf(item.key) > -1;
|
||||
})?.key;
|
||||
},
|
||||
cache:
|
||||
@@ -44,8 +43,7 @@ export default createStore({
|
||||
if (
|
||||
state.caches[key].time &&
|
||||
(expire <= 0 ||
|
||||
Date.now() - state.caches[key].time <
|
||||
1000 * expire)
|
||||
Date.now() - state.caches[key].time < 1000 * expire)
|
||||
)
|
||||
return state.caches[key].data;
|
||||
}
|
||||
@@ -56,7 +54,7 @@ export default createStore({
|
||||
//载入settings设置
|
||||
loadSettings(state) {
|
||||
const l = localStorage.getItem("zmusic.settings");
|
||||
if (l) state.settings ={...state.settings, ...JSON.parse(l)};
|
||||
if (l) state.settings = { ...state.settings, ...JSON.parse(l) };
|
||||
},
|
||||
//保存settings设置
|
||||
saveSettings(state, settings) {
|
||||
@@ -67,7 +65,7 @@ export default createStore({
|
||||
//载入caches设置
|
||||
loadCaches(state) {
|
||||
const l = localStorage.getItem("zmusic.caches");
|
||||
if (l) state.caches = {...state.caches, ...JSON.parse(l)}
|
||||
if (l) state.caches = { ...state.caches, ...JSON.parse(l) };
|
||||
},
|
||||
//保存caches设置
|
||||
saveCaches(state, caches) {
|
||||
@@ -84,7 +82,7 @@ export default createStore({
|
||||
//载入theme设置
|
||||
loadTheme(state) {
|
||||
const l = localStorage.getItem("zmusic.theme");
|
||||
if (l) state.theme = {...state.theme, ...JSON.parse(l)};
|
||||
if (l) state.theme = { ...state.theme, ...JSON.parse(l) };
|
||||
},
|
||||
//保存theme设置
|
||||
saveTheme(state, theme) {
|
||||
@@ -105,13 +103,24 @@ export default createStore({
|
||||
//如果没有,设置为[]
|
||||
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)
|
||||
state.settings.playingList.unshift(song);
|
||||
saveLoaclSettings(state.settings);
|
||||
}
|
||||
},
|
||||
removePlayingList(state, song) {
|
||||
// console.log('removePlayingList', song)
|
||||
let idx = state.settings.playingList.findIndex(
|
||||
(item) => item.id === song.id
|
||||
);
|
||||
// console.log(idx)
|
||||
if (idx > -1) {
|
||||
state.settings.playingList.splice(idx, 1);
|
||||
saveLoaclSettings(state.settings);
|
||||
}
|
||||
},
|
||||
@@ -121,10 +130,7 @@ export default createStore({
|
||||
});
|
||||
|
||||
function saveLoaclSettings(s) {
|
||||
localStorage.setItem(
|
||||
"zmusic.settings",
|
||||
JSON.stringify(s)
|
||||
);
|
||||
localStorage.setItem("zmusic.settings", JSON.stringify(s));
|
||||
}
|
||||
function saveLoaclCaches(s) {
|
||||
localStorage.setItem("zmusic.caches", JSON.stringify(s));
|
||||
|
||||
Reference in New Issue
Block a user