|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import {Image, Text, View} from "@tarojs/components"; |
|
|
|
|
import {Text, View} from "@tarojs/components"; |
|
|
|
|
import {FC, useCallback, useEffect, useState} from "react"; |
|
|
|
|
import {CourseDepData, curriculum} from "@/api"; |
|
|
|
|
import './videoInfo.scss' |
|
|
|
@ -9,6 +9,8 @@ import eventsIndex from "@/hooks/eventsIndex"; |
|
|
|
|
import {formatMinute} from "@/utils/time"; |
|
|
|
|
import videoEvents from "@/hooks/videoEvents"; |
|
|
|
|
import unique_ident from "@/hooks/unique_ident"; |
|
|
|
|
import Spin from "@/components/spinner"; |
|
|
|
|
import Img from "@/components/image/image"; |
|
|
|
|
|
|
|
|
|
const VideoInfo: FC = () => { |
|
|
|
|
const {id, depId} = Taro.getCurrentInstance()?.router?.params as any |
|
|
|
@ -16,15 +18,16 @@ const VideoInfo: FC = () => { |
|
|
|
|
const [playId, setPlayId] = useState<number | null>(null) |
|
|
|
|
const [preview, setPreview] = useState(false) // 预览
|
|
|
|
|
const [playing, setPlaying] = useState(false) // 学习中
|
|
|
|
|
const [enable, setEnable] = useState(true) |
|
|
|
|
|
|
|
|
|
const getData = useCallback(async (playing: boolean) => { |
|
|
|
|
try { |
|
|
|
|
const res = await curriculum.courseDep(id, depId) |
|
|
|
|
if (res) { |
|
|
|
|
setData(res) |
|
|
|
|
} |
|
|
|
|
if (playId != null) { // 用于自动播放 判断当前课程是否完成
|
|
|
|
|
currentVideo(res, playing) |
|
|
|
|
res && setData(res) |
|
|
|
|
playId != null && currentVideo(res, playing) // 用于自动播放 判断当前课程是否完成
|
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
setEnable(false) |
|
|
|
|
}, [playing, playId]) |
|
|
|
|
|
|
|
|
|
const curEnd = (test?: boolean) => { |
|
|
|
@ -73,9 +76,7 @@ const VideoInfo: FC = () => { |
|
|
|
|
} |
|
|
|
|
}, [playId, data, preview]) |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 判断当前课程是否完成 |
|
|
|
|
*/ |
|
|
|
|
/** 判断当前课程是否完成 */ |
|
|
|
|
const currentVideo = useCallback((data: CourseDepData, playing: boolean) => { |
|
|
|
|
const courseHourRecordsFinish = data?.learn_hour_records.find(d => d.id === playId)?.courseHourRecordsFinish |
|
|
|
|
if (typeof courseHourRecordsFinish === 'number') { |
|
|
|
@ -106,12 +107,13 @@ const VideoInfo: FC = () => { |
|
|
|
|
}) |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
<Spin enable={enable} overlay/> |
|
|
|
|
<View className='content'> |
|
|
|
|
<View className='content-video'> |
|
|
|
|
{ |
|
|
|
|
playId |
|
|
|
|
? <Course id={playId} courseId={id} curEnd={curEnd} preview={preview}/> |
|
|
|
|
: <Image src={data?.course.thumb || ''} className='image' mode='aspectFill'/> |
|
|
|
|
: <Img width={750} height={500} src={data?.course.thumb || ''} mode='aspectFill'/> |
|
|
|
|
} |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|