Add audio player preset playlist options

This commit is contained in:
Aicirou 2020-07-08 01:22:50 +08:00
parent 6afc76f974
commit c50623a3ef
2 changed files with 26 additions and 13 deletions

View File

@ -212,3 +212,15 @@ body {
left: 0px !important; left: 0px !important;
} }
} }
.aplayer {
.aplayer-lrc {
p.aplayer-lrc-current {
font-size: 14px;
color: orange;
}
p {
font-weight: 700;
}
}
}

View File

@ -3,6 +3,8 @@ export default {
state: { state: {
player: null, player: null,
audios: [], audios: [],
openedAudios: [],
customAudios: window.themeOptions.audio.audios || [],
}, },
actions: { actions: {
set({ state }, player) { set({ state }, player) {
@ -10,26 +12,24 @@ export default {
}, },
add({ state, dispatch }, { audio, play }) { add({ state, dispatch }, { audio, play }) {
return new Promise((resolve) => { return new Promise((resolve) => {
for (var i = 0; i < state.audios.length; i++) { var index = state.openedAudios.findIndex((s) => s.id === audio.id);
var s = state.audios[i]; console.log(index);
if (s.id === audio.id) { if (index >= 0) {
state.audios.splice(i, 1); state.openedAudios.splice(index, 1);
state.player.list.remove(i); state.player.list.remove(index + state.customAudios.length || 0);
i--;
}
} }
state.player.list.add(audio); state.player.list.add(audio);
state.audios.push(audio); state.openedAudios.push(audio);
if (play) { if (play) {
var index = state.audios.length; var length = state.player.list.audios.length || 1;
state.player.list.switch(index - 1); state.player.list.switch(length - 1);
state.player.play(); state.player.play();
} }
dispatch( dispatch(
"acrou/db/set", "acrou/db/set",
{ {
path: "audio.list", path: "audio.list",
value: state.audios, value: state.openedAudios,
}, },
{ root: true } { root: true }
); );
@ -39,7 +39,7 @@ export default {
load({ state, dispatch }) { load({ state, dispatch }) {
// eslint-disable-next-line no-async-promise-executor // eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
var audio = await dispatch( var openedAudios = await dispatch(
"acrou/db/get", "acrou/db/get",
{ {
path: "audio.list", path: "audio.list",
@ -47,7 +47,8 @@ export default {
}, },
{ root: true } { root: true }
); );
state.audios = audio; state.openedAudios = openedAudios
state.audios = state.customAudios.concat(openedAudios);
resolve(); resolve();
}); });
}, },