Browse Source

Merge branch 'master' into jenkins

skyblued 2 years ago
parent
commit
dcd8d36e6c

+ 8 - 1
src/router/routes-student.ts

@@ -22,7 +22,14 @@ const noLoginRouter = [
     meta: {
       title: '下载管乐团学生端'
     }
-  }
+  },
+  {
+    path: '/transfer',
+    component: () => import('@/student/download/transfer'),
+    meta: {
+      title: '管乐团'
+    }
+  },
 ]
 
 export default [

+ 112 - 0
src/student/download/transfer.tsx

@@ -0,0 +1,112 @@
+import { browser } from '@/helpers/utils'
+import { Button, showToast } from 'vant'
+import { defineComponent } from 'vue'
+import styles from './index.module.less'
+import wxBg from './images/wx_bg.png'
+import qs from 'query-string'
+
+export default defineComponent({
+  name: 'download-transfer',
+  data() {
+    return {
+      wxStatus: false,
+      type: 'student',
+      buttonText: '下载管乐团学生端'
+    }
+  },
+  mounted() {
+    const { pn, url, action, pageTag, ...rest } = this.$route.query
+    const { origin, pathname } = location
+    let tempPathname = pathname
+    let beforeIos = 'BandMusicTeam://linkUrl='
+    let beforeAndroid = 'colexiustudent://html:8888/SplashActivity?url='
+
+    if (pn === 's') {
+      tempPathname = '/orchestra-student/'
+      beforeIos = 'BandMusicTeam://linkUrl='
+      beforeAndroid = 'orchestrastudent://html:8888/SplashActivity?url='
+    } else if (pn === 't') {
+      tempPathname = '/orchestra-teacher/'
+      beforeIos = 'BandMusicTeamTeacher://linkUrl='
+      beforeAndroid = 'orchestrateacher://html:8888/SplashActivity?url='
+    } else if (pn === 'm') {
+      tempPathname = '/orchestra-school/'
+      beforeIos = 'BandMusicTeamManager://linkUrl='
+      beforeAndroid = 'orchestramanager://html:8888/SplashActivity?url='
+    }
+
+    let str = origin + tempPathname + '#/'
+    // 判断是否有跳转连接, 如果连接和动作没有时, 则不跳转
+    if (!url && !action) {
+      return
+    }
+    str +=
+      url +
+      qs.stringify({
+        ...rest
+      })
+
+    const query = {
+      url: str,
+      action: action || 'h5', // app, h5
+      pageTag: pageTag || 1 // 页面标识
+      // params: {}
+    } as any
+    const iosStr = encodeURIComponent(JSON.stringify(query))
+    console.log(query, 'iosStr')
+    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
+      /*  
+        唤起前缀 IOS
+        BandMusicTeam:// 管乐团
+        BandMusicTeamTeacher://
+        BandMusicTeamManager:// */
+      /* 
+        唤起前缀 ANDROID
+        orchestrastudent://html:8888/SplashActivity?url=
+        orchestrateacher://html:8888/SplashActivity?url=
+        orchestramanager://html:8888/SplashActivity?url=
+       */
+      window.location.href = beforeIos + iosStr
+    } else if (/(Android)/i.test(navigator.userAgent)) {
+      window.location.href = beforeAndroid + iosStr
+    } else {
+      showToast('请用手机或移动设备打开')
+    }
+  },
+  methods: {
+    onDownload() {
+      if (browser().weixin) {
+        this.wxStatus = true
+        return
+      }
+
+      if (browser().ios || /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
+        window.location.href = 'https://itunes.apple.com/cn/app/id1626971695?mt=8'
+      } else if (/(Android)/i.test(navigator.userAgent)) {
+        window.location.href = 'https://appstore.ks3-cn-beijing.ksyuncs.com/clx-student-domain.apk'
+      } else {
+        showToast('请用手机或移动设备打开')
+      }
+    }
+  },
+  render() {
+    return (
+      <div class={[styles.student]}>
+        <Button round size="large" color="#FF8057" class={styles.btn} onClick={this.onDownload}>
+          {this.buttonText}
+        </Button>
+
+        {this.wxStatus && (
+          <div
+            class={styles.wxpopup}
+            onClick={() => {
+              this.wxStatus = false
+            }}
+          >
+            <img src={wxBg} alt="" />
+          </div>
+        )}
+      </div>
+    )
+  }
+})

+ 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