|
@@ -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>
|
|
|
)}
|