From a0b27a806e593e2d00d3bff8fc22f8497c360679 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Fri, 13 May 2022 23:03:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=A8=E7=94=BB=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E9=A1=B9=E4=B8=BA=E9=9D=9E=E4=B8=BB=E5=8A=A8?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=97=B6=E5=BC=82=E5=B8=B8=E3=80=81=E6=92=A4?= =?UTF-8?q?=E5=9B=9E=E6=9C=AA=E6=92=AD=E6=94=BE=E7=9A=84=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=97=B6=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/slides.ts | 10 +++++----- src/views/Screen/hooks/useExecPlay.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/store/slides.ts b/src/store/slides.ts index 72e71eb2..13d50e11 100644 --- a/src/store/slides.ts +++ b/src/store/slides.ts @@ -63,17 +63,17 @@ export const useSlidesStore = defineStore('slides', { const formatedAnimations: FormatedAnimation[] = [] for (const animation of animations) { - if (animation.trigger === 'click') { + if (animation.trigger === 'click' || !formatedAnimations.length) { formatedAnimations.push({ animations: [animation], autoNext: false }) } - if (animation.trigger === 'meantime') { - const last = formatedAnimations[formatedAnimations.length - 1] || { animations: [], autoNext: false } + else if (animation.trigger === 'meantime') { + const last = formatedAnimations[formatedAnimations.length - 1] last.animations = last.animations.filter(item => item.elId !== animation.elId) last.animations.push(animation) formatedAnimations[formatedAnimations.length - 1] = last } - if (animation.trigger === 'auto') { - const last = formatedAnimations[formatedAnimations.length - 1] || { animations: [], autoNext: false } + else if (animation.trigger === 'auto') { + const last = formatedAnimations[formatedAnimations.length - 1] last.autoNext = true formatedAnimations[formatedAnimations.length - 1] = last formatedAnimations.push({ animations: [animation], autoNext: false }) diff --git a/src/views/Screen/hooks/useExecPlay.ts b/src/views/Screen/hooks/useExecPlay.ts index ee5ef92b..a799e73d 100644 --- a/src/views/Screen/hooks/useExecPlay.ts +++ b/src/views/Screen/hooks/useExecPlay.ts @@ -13,8 +13,13 @@ export default () => { // 当前页的元素动画执行到的位置 const animationIndex = ref(0) + + // 动画执行状态 const inAnimation = ref(false) + // 最小已播放页面索引 + const playedSlidesMinIndex = ref(slideIndex.value) + // 执行元素动画 const runAnimation = () => { // 正在执行动画时,禁止其他新的动画开始 @@ -102,13 +107,18 @@ export default () => { // 向上/向下播放 // 遇到元素动画时,优先执行动画播放,无动画则执行翻页 // 向上播放遇到动画时,仅撤销到动画执行前的状态,不需要反向播放动画 + // 撤回到上一页时,若该页从未播放过(意味着不存在动画状态),需要将动画索引置为最小值(初始状态),否则置为最大值(最终状态) const execPrev = () => { if (formatedAnimations.value.length && animationIndex.value > 0) { revokeAnimation() } else if (slideIndex.value > 0) { slidesStore.updateSlideIndex(slideIndex.value - 1) - animationIndex.value = formatedAnimations.value.length + if (slideIndex.value < playedSlidesMinIndex.value) { + animationIndex.value = 0 + playedSlidesMinIndex.value = slideIndex.value + } + else animationIndex.value = formatedAnimations.value.length inAnimation.value = false } else {