Skip to content

Commit

Permalink
新增 支持下一话按钮;
Browse files Browse the repository at this point in the history
  • Loading branch information
MagmaBlock committed Jun 11, 2023
1 parent 3613bfd commit 8382188
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/components/Anime/AnimePlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ onMounted(() => {
},
},
],
controls: [
{
name: "next",
index: 20,
position: "left",
html: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-7.5 -7.5 38 38"><path d="M7.58 16.89l5.77-4.07c.56-.4.56-1.24 0-1.63L7.58 7.11C6.91 6.65 6 7.12 6 7.93v8.14c0 .81.91 1.28 1.58.82zM16 7v10c0 .55.45 1 1 1s1-.45 1-1V7c0-.55-.45-1-1-1s-1 .45-1 1z" fill="currentColor"></path></svg>',
tooltip: "下一话",
click: useThrottleFn(function () {
const newEp = store.findNextEpisode();
if (newEp) store.changeEpisode(newEp);
}, 1000),
},
],
};
const artInstance = reactive(new Artplayer(options));
Expand Down Expand Up @@ -134,6 +147,17 @@ onMounted(() => {
}
});
// 监听集数变化, 重新检查是否有可以播放的下一话
watch(
() => store.fileData.activeEpisode,
() => {
artInstance.controls.update({
...options.controls[0],
disable: !store.findNextEpisode(),
});
}
);
// 销毁
onBeforeUnmount(() => {
artInstance.destroy();
Expand Down
14 changes: 14 additions & 0 deletions src/store/Anime.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ export const useAnimeStore = defineStore("anime", {
this.activeFile?.parseResult?.extensionName?.raw == "mkv"
);
},
/**
* 查找下一个集数, 可能为空
* @param {String | undefined} episode
* @returns {String | undefined}
*/
findNextEpisode(state) {
return (episode) => {
if (typeof episode != "string") episode = this.fileData.activeEpisode;
let currentIndex = this.episodeList.findIndex((findEp) => {
return findEp.episode == episode;
});
return this.episodeList[currentIndex + 1]?.episode;
};
},
},
actions: {
/**
Expand Down

1 comment on commit 8382188

@vercel
Copy link

@vercel vercel bot commented on 8382188 Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.