skyblued 2 년 전
부모
커밋
17324499bb
3개의 변경된 파일102개의 추가작업 그리고 27개의 파일을 삭제
  1. 1 1
      src/views/courseList/index.module.less
  2. 93 18
      src/views/courseList/index.tsx
  3. 8 8
      src/views/coursewarePlay/index.tsx

+ 1 - 1
src/views/courseList/index.module.less

@@ -42,7 +42,7 @@
       align-items: center;
       justify-content: center;
       font-size: 12px;
-      width: 50%;
+      width: 70%;
       height: 20px;
       border-radius: 20px;
       background: linear-gradient(180deg, #ff9c7c 0%, #ff5757 100%);

+ 93 - 18
src/views/courseList/index.tsx

@@ -1,10 +1,15 @@
 import request from '@/helpers/request'
 import { state } from '@/state'
-import { Button, Empty, Grid, GridItem, Icon, showToast } from 'vant'
-import { defineComponent, onMounted, reactive } from 'vue'
+import { Button, Empty, Grid, GridItem, Icon, showConfirmDialog, showToast } from 'vant'
+import { defineComponent, onMounted, reactive, onUnmounted } from 'vue'
 import styles from './index.module.less'
 import { useRoute, useRouter } from 'vue-router'
-import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
+import {
+  listenerMessage,
+  postMessage,
+  promisefiyPostMessage,
+  removeListenerMessage
+} from '@/helpers/native-message'
 import iconLook from './image/look.svg'
 import iconCourse from './image/icon-course.png'
 import { browser } from '@/helpers/utils'
@@ -42,7 +47,8 @@ export default defineComponent({
             state.platformApi + '/courseSchedule/myCoursewareDetail/' + route.query.id
           )
           if (Array.isArray(res?.data)) {
-            data.list = res.data
+            // data.list = res.data
+            data.list = browserInfo.isApp ? await checkCoursewareCache(res.data) : res.data
           }
         } catch (error) {}
       }
@@ -50,6 +56,10 @@ export default defineComponent({
     }
     onMounted(() => {
       getList()
+      listenerMessage('downloadCoursewareToCache', getProgress)
+    })
+    onUnmounted(() => {
+      removeListenerMessage('downloadCoursewareToCache', getProgress)
     })
 
     const handleClick = async (item: any) => {
@@ -58,8 +68,25 @@ export default defineComponent({
         setCoursewareDetail(item)
         return
       }
-      // const isCache = await checkCache(item)
-      // if (!isCache) return
+      if (!item.hasCache) {
+        if (browserInfo.isStudent || /(192|localhost)/.test(location.origin)) {
+          try {
+            await showConfirmDialog({
+              message: '当前课程没有缓存是否缓存'
+            })
+          } catch (error) {
+            gotoPlay(item)
+            return
+          }
+        }
+        item.downloadStatus = 1
+        downCatch(item)
+        return
+      }
+      gotoPlay(item)
+    }
+    // 去课件播放
+    const gotoPlay = (item: any) => {
       router.push({
         path: '/coursewarePlay',
         query: {
@@ -67,23 +94,57 @@ export default defineComponent({
         }
       })
     }
-    // 检查课时是否有缓存
-    const checkCache = async (item: any) => {
+    // 检查数据的缓存状态
+    const checkCoursewareCache = (list: []) => {
+      return new Promise((resolve) => {
+        postMessage(
+          {
+            api: 'checkCoursewareCache',
+            content: {
+              data: list
+            }
+          },
+          (res) => {
+            if (res?.content?.data) {
+              resolve(res.content.data)
+              return
+            }
+            return []
+          }
+        )
+      })
+    }
+    // 下载缓存
+    const downCatch = async (item: any) => {
       if (browserInfo.isApp) {
-        const res = await promisefiyPostMessage({
-          api: 'checkCoursewareCache',
+        const res = await postMessage({
+          api: 'downloadCoursewareToCache',
           content: {
-            lessonCoursewareDetailId: item.lessonCoursewareDetailId,
-            finish: true,
-            rate: 0.2
+            data: item
           }
         })
-        console.log(res)
         return res
       }
 
       return true
     }
+    // 下载缓存进度
+    const getProgress = (res: any) => {
+      console.log('🚀 ~ res', res)
+      if (res?.content?.lessonCoursewareDetailId) {
+        const { lessonCoursewareDetailId, downloadStatus, progress } = res.content
+        const course = data.list.find(
+          (n: any) => n.lessonCoursewareDetailId == lessonCoursewareDetailId
+        )
+        if (course) {
+          if (downloadStatus == 2) {
+            course.hasCache = 1
+            course.progress = 100
+          }
+          course.progress = progress
+        }
+      }
+    }
     // 绑定课时
     const setCoursewareDetail = async (item: any) => {
       try {
@@ -115,10 +176,24 @@ export default defineComponent({
                     {route.query.code !== 'select' && <div>已使用 {item.useNum} 次</div>}
                   </div>
                   {route.query.code !== 'select' ? (
-                    <div class={styles.num} >
-                      查看
-                      <Icon name="play-circle-o" />
-                    </div>
+                    <>
+                      {item.hasCache ? (
+                        <div class={styles.num}>
+                          查看
+                          <Icon name="play-circle-o" />
+                        </div>
+                      ) : (
+                        <>
+                          {item.downloadStatus === 1 ? (
+                            <div class={styles.num}>
+                              下载中 {item.progress}%
+                            </div>
+                          ) : (
+                            <div class={styles.num}>下载</div>
+                          )}
+                        </>
+                      )}
+                    </>
                   ) : (
                     <div class={styles.num}>选择</div>
                   )}

+ 8 - 8
src/views/coursewarePlay/index.tsx

@@ -124,14 +124,14 @@ export default defineComponent({
         const item = data.knowledgePointList[i]
         for (let j = 0; j < item.materialList.length; j++) {
           const material = item.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
-          //     // console.log("🚀 ~ material", material)
-          //   }
-          // }
+          if (browserInfo.isApp && ['VIDEO', 'IMG'].includes(material.type) && /(192|localhost)/.test(location.origin)){
+            const localData = await getCacheFilePath(material)
+            if (localData?.content?.localPath){
+              material.url = material.content
+              material.content = localData.content.localPath
+              // console.log("🚀 ~ material", material)
+            }
+          }
           if (popupData.itemActive === '') {
             popupData.tabName = item.name
             popupData.tabActive = material.knowledgePointId