Browse Source

Merge branch 'hqyDev' of http://git.dayaedu.com/huangqiyong/pptList into test-online

黄琪勇 4 tháng trước cách đây
mục cha
commit
d92cbb5447

+ 27 - 11
src/messageHooks/pptScreen.ts

@@ -1,28 +1,44 @@
-import { onMounted, onUnmounted, watch } from "vue"
+import { onMounted, onUnmounted, watch, type Ref, type ComputedRef } from "vue"
 import { useSlidesStore } from "@/store"
 
-export const changePageSlideMes = (changePageSlide: (type: "prev" | "next") => void) => {
+export const changePageSlideMes = (
+  execPrev: () => void,
+  execNext: () => void,
+  animationIndex: Ref<number>,
+  formatedAnimations: ComputedRef<any[]>
+) => {
   const slidesStore = useSlidesStore()
 
   /** 初始化ppt完成之后给父级传递消息 */
   function pptInitMes() {
-    window.parent.postMessage({ type: "initPPT", content: { slidesLen: slidesStore.slides.length } }, "*")
+    window.parent.postMessage(
+      { type: "initPPT", content: { slidesLen: slidesStore.slides.length, isAnimationed: animationIndex.value === formatedAnimations.value.length } },
+      "*"
+    )
   }
   function handleMessage(event: any) {
     const { type, content } = event.data || {}
     if (type === "changePageSlide") {
-      changePageSlide(content)
+      /*  翻页 */
+      if (content === "prev") {
+        execPrev()
+      } else if (content === "next") {
+        execNext()
+      }
     }
   }
 
   pptInitMes()
-  watch(
-    () => slidesStore.slideIndex,
-    () => {
-      // 翻页完成之后的事件
-      window.parent.postMessage({ type: "changeSlideIndex", content: { slideIndex: slidesStore.slideIndex } }, "*")
-    }
-  )
+  watch([() => slidesStore.slideIndex, animationIndex], () => {
+    // 翻页完成之后的事件  isAnimationed 动画结束
+    window.parent.postMessage(
+      {
+        type: "changeSlideIndex",
+        content: { slideIndex: slidesStore.slideIndex, isAnimationed: animationIndex.value === formatedAnimations.value.length }
+      },
+      "*"
+    )
+  })
   onMounted(() => {
     window.addEventListener("message", handleMessage)
   })

+ 1 - 1
src/views/Editor/EditorHeader/index.vue

@@ -46,7 +46,7 @@
     </div>
 
     <div class="right">
-      <div class="cancelBtn" @click="handleClose">取消</div>
+      <div class="cancelBtn" @click="handleClose">退出</div>
       <div class="saveBtn" @click="handleSave">保存课件</div>
     </div>
 

+ 0 - 5
src/views/Screen/BaseView.vue

@@ -184,11 +184,6 @@ const contextmenus = (): ContextmenuItem[] => {
   }
   return menusData
 }
-
-defineExpose({
-  execPrev,
-  execNext
-})
 </script>
 
 <style lang="scss" scoped>

+ 2 - 17
src/views/Screen/PresenterView.vue

@@ -104,18 +104,8 @@ const timerlVisible = ref(false)
 const laserPen = ref(false)
 const screenStore = useScreenStore()
 
-const {
-  mousewheelListener,
-  touchStartListener,
-  touchEndListener,
-  turnPrevSlide,
-  turnNextSlide,
-  turnSlideToIndex,
-  turnSlideToId,
-  animationIndex,
-  execPrev,
-  execNext
-} = useExecPlay()
+const { mousewheelListener, touchStartListener, touchEndListener, turnPrevSlide, turnNextSlide, turnSlideToIndex, turnSlideToId, animationIndex } =
+  useExecPlay()
 
 const { slideWidth, slideHeight } = useSlideSize(slideListWrapRef)
 const { exitScreening } = useScreening()
@@ -194,11 +184,6 @@ const contextmenus = (): ContextmenuItem[] => {
   }
   return menusData
 }
-
-defineExpose({
-  execPrev,
-  execNext
-})
 </script>
 
 <style lang="scss" scoped>

+ 54 - 52
src/views/Screen/hooks/useExecPlay.ts

@@ -1,10 +1,11 @@
-import { onMounted, onUnmounted, ref } from 'vue'
-import { throttle } from 'lodash'
-import { storeToRefs } from 'pinia'
-import { useSlidesStore } from '@/store'
-import { KEYS } from '@/configs/hotkey'
-import { ANIMATION_CLASS_PREFIX } from '@/configs/animation'
-import message from '@/utils/message'
+import { onMounted, onUnmounted, ref } from "vue"
+import { throttle } from "lodash"
+import { storeToRefs } from "pinia"
+import { useSlidesStore, useScreenStore } from "@/store"
+import { KEYS } from "@/configs/hotkey"
+import { ANIMATION_CLASS_PREFIX } from "@/configs/animation"
+import message from "@/utils/message"
+import { changePageSlideMes } from "@/messageHooks/pptScreen"
 
 export default () => {
   const slidesStore = useSlidesStore()
@@ -41,21 +42,21 @@ export default () => {
       }
 
       const animationName = `${ANIMATION_CLASS_PREFIX}${animation.effect}`
-      
+
       // 执行动画前先清除原有的动画状态(如果有)
-      elRef.style.removeProperty('--animate-duration')
+      elRef.style.removeProperty("--animate-duration")
       for (const classname of elRef.classList) {
         if (classname.indexOf(ANIMATION_CLASS_PREFIX) !== -1) elRef.classList.remove(classname, `${ANIMATION_CLASS_PREFIX}animated`)
       }
-      
+
       // 执行动画
-      elRef.style.setProperty('--animate-duration', `${animation.duration}ms`)
+      elRef.style.setProperty("--animate-duration", `${animation.duration}ms`)
       elRef.classList.add(animationName, `${ANIMATION_CLASS_PREFIX}animated`)
 
       // 执行动画结束,将“退场”以外的动画状态清除
       const handleAnimationEnd = () => {
-        if (animation.type !== 'out') {
-          elRef.style.removeProperty('--animate-duration')
+        if (animation.type !== "out") {
+          elRef.style.removeProperty("--animate-duration")
           elRef.classList.remove(animationName, `${ANIMATION_CLASS_PREFIX}animated`)
         }
 
@@ -66,14 +67,14 @@ export default () => {
           if (autoNext) runAnimation()
         }
       }
-      elRef.addEventListener('animationend', handleAnimationEnd, { once: true })
+      elRef.addEventListener("animationend", handleAnimationEnd, { once: true })
     }
   }
 
   onMounted(() => {
     const firstAnimations = formatedAnimations.value[0]
     if (firstAnimations && firstAnimations.animations.length) {
-      const autoExecFirstAnimations = firstAnimations.animations.every(item => item.trigger === 'auto' || item.trigger === 'meantime')
+      const autoExecFirstAnimations = firstAnimations.animations.every(item => item.trigger === "auto" || item.trigger === "meantime")
       if (autoExecFirstAnimations) runAnimation()
     }
   })
@@ -86,15 +87,15 @@ export default () => {
     for (const animation of animations) {
       const elRef: HTMLElement | null = document.querySelector(`#screen-element-${animation.elId} [class^=base-element-]`)
       if (!elRef) continue
-      
-      elRef.style.removeProperty('--animate-duration')
+
+      elRef.style.removeProperty("--animate-duration")
       for (const classname of elRef.classList) {
         if (classname.indexOf(ANIMATION_CLASS_PREFIX) !== -1) elRef.classList.remove(classname, `${ANIMATION_CLASS_PREFIX}animated`)
       }
     }
 
     // 如果撤销时该位置有且仅有强调动画,则继续执行一次撤销
-    if (animations.every(item => item.type === 'attention')) execPrev()
+    if (animations.every(item => item.type === "attention")) execPrev()
   }
 
   // 关闭自动播放
@@ -113,9 +114,13 @@ export default () => {
     loopPlay.value = loop
   }
 
-  const throttleMassage = throttle(function(msg) {
-    message.success(msg)
-  }, 1000, { leading: true, trailing: false })
+  const throttleMassage = throttle(
+    function (msg) {
+      message.success(msg)
+    },
+    1000,
+    { leading: true, trailing: false }
+  )
 
   // 向上/向下播放
   // 遇到元素动画时,优先执行动画播放,无动画则执行翻页
@@ -124,34 +129,29 @@ export default () => {
   const execPrev = () => {
     if (formatedAnimations.value.length && animationIndex.value > 0) {
       revokeAnimation()
-    }
-    else if (slideIndex.value > 0) {
+    } else if (slideIndex.value > 0) {
       slidesStore.updateSlideIndex(slideIndex.value - 1)
       if (slideIndex.value < playedSlidesMinIndex.value) {
         animationIndex.value = 0
         playedSlidesMinIndex.value = slideIndex.value
-      }
-      else animationIndex.value = formatedAnimations.value.length
-    }
-    else {
+      } else animationIndex.value = formatedAnimations.value.length
+    } else {
       if (loopPlay.value) turnSlideToIndex(slides.value.length - 1)
-      else throttleMassage('已经是第一页了')
+      else throttleMassage("已经是第一页了")
     }
     inAnimation.value = false
   }
   const execNext = () => {
     if (formatedAnimations.value.length && animationIndex.value < formatedAnimations.value.length) {
       runAnimation()
-    }
-    else if (slideIndex.value < slides.value.length - 1) {
+    } else if (slideIndex.value < slides.value.length - 1) {
       slidesStore.updateSlideIndex(slideIndex.value + 1)
       animationIndex.value = 0
       inAnimation.value = false
-    }
-    else {
+    } else {
       if (loopPlay.value) turnSlideToIndex(0)
       else {
-        throttleMassage('已经是最后一页了')
+        throttleMassage("已经是最后一页了")
         closeAutoPlay()
       }
       inAnimation.value = false
@@ -162,7 +162,7 @@ export default () => {
   const autoPlayInterval = ref(2500)
   const autoPlay = () => {
     closeAutoPlay()
-    message.success('开始自动放映')
+    message.success("开始自动放映")
     autoPlayTimer.value = setInterval(execNext, autoPlayInterval.value)
   }
 
@@ -173,18 +173,22 @@ export default () => {
   }
 
   // 鼠标滚动翻页
-  const mousewheelListener = throttle(function(e: WheelEvent) {
-    if (e.deltaY < 0) execPrev()
-    else if (e.deltaY > 0) execNext()
-  }, 500, { leading: true, trailing: false })
+  const mousewheelListener = throttle(
+    function (e: WheelEvent) {
+      if (e.deltaY < 0) execPrev()
+      else if (e.deltaY > 0) execNext()
+    },
+    500,
+    { leading: true, trailing: false }
+  )
 
   // 触摸屏上下滑动翻页
-  const touchInfo = ref<{ x: number; y: number; } | null>(null)
+  const touchInfo = ref<{ x: number; y: number } | null>(null)
 
   const touchStartListener = (e: TouchEvent) => {
     touchInfo.value = {
       x: e.changedTouches[0].pageX,
-      y: e.changedTouches[0].pageY,
+      y: e.changedTouches[0].pageY
     }
   }
   const touchEndListener = (e: TouchEvent) => {
@@ -193,7 +197,7 @@ export default () => {
     const offsetX = Math.abs(touchInfo.value.x - e.changedTouches[0].pageX)
     const offsetY = e.changedTouches[0].pageY - touchInfo.value.y
 
-    if ( Math.abs(offsetY) > offsetX && Math.abs(offsetY) > 50 ) {
+    if (Math.abs(offsetY) > offsetX && Math.abs(offsetY) > 50) {
       touchInfo.value = null
 
       if (offsetY > 0) execPrev()
@@ -206,17 +210,11 @@ export default () => {
     const key = e.key.toUpperCase()
 
     if (key === KEYS.UP || key === KEYS.LEFT || key === KEYS.PAGEUP) execPrev()
-    else if (
-      key === KEYS.DOWN || 
-      key === KEYS.RIGHT ||
-      key === KEYS.SPACE || 
-      key === KEYS.ENTER ||
-      key === KEYS.PAGEDOWN
-    ) execNext()
+    else if (key === KEYS.DOWN || key === KEYS.RIGHT || key === KEYS.SPACE || key === KEYS.ENTER || key === KEYS.PAGEDOWN) execNext()
   }
 
-  onMounted(() => document.addEventListener('keydown', keydownListener))
-  onUnmounted(() => document.removeEventListener('keydown', keydownListener))
+  onMounted(() => document.addEventListener("keydown", keydownListener))
+  onUnmounted(() => document.removeEventListener("keydown", keydownListener))
 
   // 切换到上一张/上一张幻灯片(无视元素的入场动画)
   const turnPrevSlide = () => {
@@ -240,7 +238,11 @@ export default () => {
       animationIndex.value = 0
     }
   }
-
+  const screenStore = useScreenStore()
+  if (["pptScreen", "mobileScreen"].includes(screenStore.mode)) {
+    // mes 翻页
+    changePageSlideMes(execPrev, execNext, animationIndex, formatedAnimations)
+  }
   return {
     autoPlayTimer,
     autoPlayInterval,
@@ -258,6 +260,6 @@ export default () => {
     turnSlideToId,
     execPrev,
     execNext,
-    animationIndex,
+    animationIndex
   }
 }

+ 2 - 14
src/views/Screen/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="pptist-screen">
-    <BaseView ref="screenViewDom" :changeViewMode="changeViewMode" v-if="viewMode === 'base'" />
-    <PresenterView ref="screenViewDom" :changeViewMode="changeViewMode" v-else-if="viewMode === 'presenter'" />
+    <BaseView :changeViewMode="changeViewMode" v-if="viewMode === 'base'" />
+    <PresenterView :changeViewMode="changeViewMode" v-else-if="viewMode === 'presenter'" />
   </div>
 </template>
 
@@ -12,7 +12,6 @@ import useScreening from "@/hooks/useScreening"
 
 import BaseView from "./BaseView.vue"
 import PresenterView from "./PresenterView.vue"
-import { changePageSlideMes } from "@/messageHooks/pptScreen"
 
 const viewMode = ref<"base" | "presenter">("base")
 
@@ -22,17 +21,6 @@ const changeViewMode = (mode: "base" | "presenter") => {
 
 const { exitScreening } = useScreening()
 
-const screenViewDom = ref()
-// mes 翻页
-changePageSlideMes((type: "prev" | "next") => {
-  /*  翻页 */
-  if (type === "prev") {
-    screenViewDom.value.execPrev()
-  } else if (type === "next") {
-    screenViewDom.value.execNext()
-  }
-})
-
 // 快捷键退出放映
 const keydownListener = (e: KeyboardEvent) => {
   const key = e.key.toUpperCase()

+ 1 - 1
vite.config.ts

@@ -28,7 +28,7 @@ export default defineConfig({
     proxy: {
       // 正则表达式写法
       "^/pptApi/.*": {
-        target: "https://dev.kt.colexiu.com",
+        target: "https://test.kt.colexiu.com",
         changeOrigin: true,
         rewrite: path => path.replace(/^\/pptApi/, "")
       }