Bläddra i källkod

修改播放缓存

lex-xin 5 månader sedan
förälder
incheckning
e80b07a269

+ 11 - 6
src/student/pre-register-active/video.tsx

@@ -131,11 +131,16 @@ export default defineComponent({
     }
 
     const checkVideoDetails = (time: number) => {
+      let status = false
       forms.videoDetails.forEach((item: any) => {
         if (item.startNode <= time && time <= item.endNode) {
           forms.videoSelectId = item.id
+          status = true
         }
       })
+      if(!status) {
+        forms.videoSelectId = null
+      }
     }
 
     /**
@@ -310,12 +315,12 @@ export default defineComponent({
 
         // forms.player.on('loadstart', () => {})
         forms.player.on('ready', (item: any) => {
-          console.log('ready', item)
+          // console.log('ready', item)
 
           // forms.player.pause()
         })
         forms.player.on('loadedmetadata', () => {
-          console.log('loadedmetadata')
+          // console.log('loadedmetadata')
           forms.loading = false
           forms.player.currentTime(forms.videoBrowsePoint)
           checkVideoDetails(forms.player.currentTime())
@@ -330,13 +335,13 @@ export default defineComponent({
         })
 
         forms.player.on('seeking', () => {
-          console.log('seeking')
+          // console.log('seeking')
           videoIntervalRef.isActive.value && videoIntervalRef.pause()
         })
 
         // // 拖动结束时
         forms.player.on('seeked', () => {
-          console.log('seeked')
+          // console.log('seeked')
           videoIntervalRef.isActive.value && videoIntervalRef.pause()
         })
 
@@ -348,7 +353,7 @@ export default defineComponent({
 
         // 如何视频在缓存不会触发
         forms.player.on('timeupdate', () => {
-          console.log('timeupdate', forms.player.currentTime())
+          // console.log('timeupdate', forms.player.currentTime())
           // 时间变化时更新每一段的状态
           checkVideoDetails(forms.player.currentTime())
           // 判断视频计时器是否暂停,如果暂停则恢复
@@ -411,7 +416,7 @@ export default defineComponent({
     watch(
       () => videoIntervalRef.isActive.value,
       (newVal: boolean) => {
-        console.log(videoIntervalRef.isActive.value, 'videoIntervalRef')
+        // console.log(videoIntervalRef.isActive.value, 'videoIntervalRef')
         initVideoCount(newVal)
       }
     )

+ 0 - 1
src/views/courseListSearch/child-node.tsx

@@ -50,7 +50,6 @@ const ChildNode = defineComponent({
       return name.replace(search, `<span style="color: #F67146;">${search}</span>`)
     }
 
-    console.log(props.collapse, "collapse")
     return () => (
       <Collapse
         modelValue={props.collapse}

+ 24 - 3
src/views/courseListSearch/index.tsx

@@ -1,9 +1,9 @@
-import { computed, defineComponent, reactive, TransitionGroup, watch } from 'vue'
+import { defineComponent, reactive, TransitionGroup, watch } from 'vue'
 import styles from './index.module.less'
 import OHeader from '@/components/o-header'
 import OSearch from '@/components/o-search'
 import request from '@/helpers/request'
-import { state } from '@/state'
+import { setLogin, state } from '@/state'
 import { useRoute, useRouter } from 'vue-router'
 import OLoading from '@/components/o-loading'
 import OEmpty from '@/components/o-empty'
@@ -21,6 +21,7 @@ export default defineComponent({
   setup() {
     const route = useRoute()
     const router = useRouter()
+    const pageVisibility = usePageVisibility()
     const browserInfo = browser()
     const data = reactive({
       titleOpacity: 0,
@@ -178,7 +179,7 @@ export default defineComponent({
           }
         }
       }
-      
+
       if (browser().isApp) {
         postMessage({
           api: 'openWebView',
@@ -204,6 +205,26 @@ export default defineComponent({
       }
     }
 
+    const getUserInfo = async () => {
+      try {
+        // 重新初始化用户信息
+        const userCash = await request.get(state.platformApi + '/user/getUserInfo')
+        setLogin(userCash.data)
+      } catch {
+        //
+      }
+    }
+
+    /** 页面显示和隐藏 */
+    watch(
+      () => pageVisibility.value,
+      (value) => {
+        if (value === "visible") {
+          getUserInfo()
+        }
+      }
+    )
+
     return () => (
       <div class={styles.courseListSearch}>
         <OSticky position="top">

+ 43 - 24
src/views/coursewarePlay/index.tsx

@@ -23,7 +23,7 @@ import qs from 'query-string'
 import MusicScore from './component/musicScore'
 // import iconDian from './image/icon-dian.svg'
 // import iconPoint from './image/icon-point.svg'
-import { iconUp, iconDown, iconPen, iconTouping, iconMenu, iconCourseType, iconSearch } from './image/icons.json'
+import { iconUp, iconDown, iconTouping, iconMenu, iconCourseType, iconSearch } from './image/icons.json'
 import Points from './component/points'
 import { browser } from '@/helpers/utils'
 import { Vue3Lottie } from 'vue3-lottie'
@@ -34,8 +34,8 @@ import PlayRecordTime from './playRecordTime'
 import { handleCheckVip } from '../hook/useFee'
 import OGuide from '@/components/o-guide'
 import Tool, { ToolItem, ToolType } from './component/tool'
-import Pen from './component/tools/pen'
-import VideoItem from './component/video-item'
+// import Pen from './component/tools/pen'
+// import VideoItem from './component/video-item'
 import deepClone from '@/helpers/deep-clone'
 import VideoPlay from './component/video-play'
 import CoursewareType from './component/courseware-type'
@@ -48,6 +48,7 @@ export default defineComponent({
   name: 'CoursewarePlay',
   setup() {
     const pageVisibility = usePageVisibility()
+    const browserInfo = browser()
     const { isOnline } = useNetwork()
     /** 页面显示和隐藏 */
     watch(
@@ -76,17 +77,17 @@ export default defineComponent({
     const parentContainer = reactive({
       width: '100vw'
     })
-    const setContainer = () => {
-      const min = Math.min(screen.width, screen.height)
-      const max = Math.max(screen.width, screen.height)
-      const width = min * (16 / 9)
-      if (width > max) {
-        parentContainer.width = '100vw'
-        return
-      } else {
-        parentContainer.width = width + 'px'
-      }
-    }
+    // const setContainer = () => {
+    //   const min = Math.min(screen.width, screen.height)
+    //   const max = Math.max(screen.width, screen.height)
+    //   const width = min * (16 / 9)
+    //   if (width > max) {
+    //     parentContainer.width = '100vw'
+    //     return
+    //   } else {
+    //     parentContainer.width = width + 'px'
+    //   }
+    // }
     const handleInit = (type = 0) => {
       //设置容器16:9
       // setContainer()
@@ -202,17 +203,17 @@ export default defineComponent({
     }
     const getTempList = async (materialList: any, name: any) => {
       const list: any = []
-      const browserInfo = browser()
+      // const browserInfo = browser()
       for (let j = 0; j < materialList.length; j++) {
         const material = materialList[j]
         //请求本地缓存
-        if (browserInfo.isApp && ['VIDEO', 'IMG'].includes(material.type)) {
-          const localData = await getCacheFilePath(material)
-          if (localData?.content?.localPath) {
-            material.url = material.content
-            material.content = localData.content.localPath
-          }
-        }
+        // if (browserInfo.isApp && ['VIDEO', 'IMG'].includes(material.type)) {
+        //   const localData = await getCacheFilePath(material)
+        //   if (localData?.content?.localPath) {
+        //     material.url = material.content
+        //     material.content = localData.content.localPath
+        //   }
+        // }
         const videoData = data.lookVideoDataList.find(
           (i: any) => i.materialId === material.materialId
         )
@@ -284,6 +285,7 @@ export default defineComponent({
       popupData.itemName = item.name
       nextTick(() => {
         data.itemList = list
+        getCurrentItemCatch(popupData.activeIndex) // 获取当前元素的缓存
         checkedAnimation(popupData.activeIndex)
         postMessage({
           api: 'courseLoading',
@@ -301,6 +303,21 @@ export default defineComponent({
         }, 500)
       })
     }
+
+    /** 获取当前元素的缓存 */
+    const getCurrentItemCatch = async (index: number) => {
+      const item = data.itemList[index]
+      if (browserInfo.isApp && ['VIDEO', 'IMG'].includes(item.typeCode) && !item.isReadCatch) {
+        const localData: any = await getCacheFilePath(item)
+        item.isReadCatch = true
+        if (localData?.content?.localPath) {
+          item.url = item.content
+          item.content = localData.content.localPath
+        }
+        console.log('加载了缓存')
+      }
+    }
+
     const getDetail = async (id?: any) => {
       try {
         const res: any = await request.get(
@@ -526,6 +543,7 @@ export default defineComponent({
         
         nextTick(() => {
           data.itemList = allList;
+          getCurrentItemCatch(popupData.activeIndex) // 获取当前元素的缓存
           checkedAnimation(popupData.activeIndex);
           postMessage({
             api: 'courseLoading',
@@ -939,6 +957,7 @@ export default defineComponent({
       checkedAnimation(popupData.activeIndex, index)
       nextTick(() => {
         popupData.activeIndex = index
+        getCurrentItemCatch(index) // 获取当前元素的缓存
         acitveTimer.value = setTimeout(
           () => {
             popupData.playIndex = index
@@ -1644,8 +1663,7 @@ export default defineComponent({
               if(data.currentId === item.id) {
                 return
               }
-              
-              // 
+
               const n = await getDetail(item.id);
               const s = await getRefLevel(item.id);
               if(n && s) {
@@ -1653,6 +1671,7 @@ export default defineComponent({
                 isCurrentCoursewareMenu.value = item.id === route.query.id ? true : false
                 popupData.coursewareOpen = false;
                 popupData.activeIndex = 0;
+                getCurrentItemCatch(popupData.activeIndex) // 获取当前元素的缓存
                 nextTick(() => {
                   popupData.open = true
                 })