feat: 添加自动放映

This commit is contained in:
pipipi-pikachu 2021-04-01 18:05:32 +08:00
parent b788ff94d3
commit 98d30be554

View File

@ -69,6 +69,8 @@ import { ContextmenuItem } from '@/components/Contextmenu/types'
import { isFullscreen } from '@/utils/fullscreen'
import useScreening from '@/hooks/useScreening'
import { message } from 'ant-design-vue'
import ScreenSlide from './ScreenSlide.vue'
import SlideThumbnails from './SlideThumbnails.vue'
import WritingBoardTool from './WritingBoardTool.vue'
@ -158,6 +160,16 @@ export default defineComponent({
}
}
//
const autoPlayTimer = ref(0)
const closeAutoPlay = () => {
if (autoPlayTimer.value) {
clearInterval(autoPlayTimer.value)
autoPlayTimer.value = 0
}
}
onUnmounted(closeAutoPlay)
// /
//
//
@ -170,6 +182,9 @@ export default defineComponent({
const lastIndex = animations.value ? animations.value.length : 0
animationIndex.value = lastIndex
}
else {
message.success('已经是第一页了')
}
}
const execNext = () => {
if (animations.value.length && animationIndex.value < animations.value.length) {
@ -179,6 +194,17 @@ export default defineComponent({
store.commit(MutationTypes.UPDATE_SLIDE_INDEX, slideIndex.value + 1)
animationIndex.value = 0
}
else {
message.success('已经是最后一页了')
closeAutoPlay()
}
}
//
const autoPlay = () => {
closeAutoPlay()
message.success('开始自动放映')
autoPlayTimer.value = setInterval(execNext, 2500)
}
//
@ -226,17 +252,27 @@ export default defineComponent({
const contextmenus = (): ContextmenuItem[] => {
return [
{
text: '上一',
subText: '↑←',
text: '上一',
subText: '↑ ←',
disable: slideIndex.value <= 0,
handler: () => turnPrevSlide(),
},
{
text: '下一',
subText: '↓→',
text: '下一',
subText: '↓ →',
disable: slideIndex.value >= slides.value.length - 1,
handler: () => turnNextSlide(),
},
{
text: '第一页',
disable: slideIndex.value === 0,
handler: () => turnSlideToIndex(0),
},
{
text: '最后一页',
disable: slideIndex.value === slides.value.length - 1,
handler: () => turnSlideToIndex(slides.value.length - 1),
},
{ divider: true },
{
text: '显示页码',
@ -248,6 +284,10 @@ export default defineComponent({
handler: () => slideThumbnailModelVisible.value = true,
},
{ divider: true },
{
text: autoPlayTimer.value ? '取消自动放映' : '自动放映',
handler: autoPlayTimer.value ? closeAutoPlay : autoPlay,
},
{
text: '结束放映',
subText: 'ESC',