This commit is contained in:
@@ -1,16 +1,36 @@
|
|||||||
import { View, Text, Button, Image, ScrollView, Video } from '@tarojs/components'
|
import { View, Text, Button, Image, ScrollView, Video } from '@tarojs/components'
|
||||||
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
import Taro, { useLoad, useDidShow, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||||
import { useState } from 'react'
|
import { useState, useRef } from 'react'
|
||||||
import { getVBCourseDetail } from '../../api'
|
import { getVBCourseDetail } from '../../api'
|
||||||
|
import { login } from '../../utils/request'
|
||||||
import { checkLogin } from '../../utils/auth'
|
import { checkLogin } from '../../utils/auth'
|
||||||
import './detail.scss'
|
import './detail.scss'
|
||||||
|
|
||||||
export default function CourseDetail() {
|
export default function CourseDetail() {
|
||||||
const [detail, setDetail] = useState<any>(null)
|
const [detail, setDetail] = useState<any>(null)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const courseIdRef = useRef<string>('')
|
||||||
|
|
||||||
useLoad((options) => {
|
useLoad((options) => {
|
||||||
if (options.id) fetchDetail(options.id)
|
if (options.id) {
|
||||||
|
courseIdRef.current = options.id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
useDidShow(async () => {
|
||||||
|
if (!courseIdRef.current) return
|
||||||
|
|
||||||
|
// 检查并确保有 Token,以便获取最新的购买状态
|
||||||
|
const token = Taro.getStorageSync('token')
|
||||||
|
if (!token) {
|
||||||
|
try {
|
||||||
|
await login()
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Silent login failed', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchDetail(courseIdRef.current)
|
||||||
})
|
})
|
||||||
|
|
||||||
const typeMap: Record<string, string> = {
|
const typeMap: Record<string, string> = {
|
||||||
@@ -107,7 +127,15 @@ export default function CourseDetail() {
|
|||||||
{detail.is_video_course && (
|
{detail.is_video_course && (
|
||||||
<View className='section video-section'>
|
<View className='section video-section'>
|
||||||
<Text className='section-title'>课程视频</Text>
|
<Text className='section-title'>课程视频</Text>
|
||||||
{detail.video_embed_code ? (
|
{detail.video_url ? (
|
||||||
|
<Video
|
||||||
|
src={detail.video_url}
|
||||||
|
className='course-video'
|
||||||
|
poster={detail.cover_image_url}
|
||||||
|
controls
|
||||||
|
autoplay={false}
|
||||||
|
/>
|
||||||
|
) : detail.video_embed_code ? (
|
||||||
<View className='video-locked' onClick={() => {
|
<View className='video-locked' onClick={() => {
|
||||||
const src = extractIframeSrc(detail.video_embed_code)
|
const src = extractIframeSrc(detail.video_embed_code)
|
||||||
if (src) handleOpenWebview(src)
|
if (src) handleOpenWebview(src)
|
||||||
@@ -119,14 +147,6 @@ export default function CourseDetail() {
|
|||||||
<Text className='lock-text'>点击观看视频</Text>
|
<Text className='lock-text'>点击观看视频</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
) : detail.video_url ? (
|
|
||||||
<Video
|
|
||||||
src={detail.video_url}
|
|
||||||
className='course-video'
|
|
||||||
poster={detail.cover_image_url}
|
|
||||||
controls
|
|
||||||
autoplay={false}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
<View className='video-locked' onClick={handleLaunch}>
|
<View className='video-locked' onClick={handleLaunch}>
|
||||||
<Image src={detail.cover_image_url} className='locked-bg' mode='aspectFill' />
|
<Image src={detail.cover_image_url} className='locked-bg' mode='aspectFill' />
|
||||||
|
|||||||
Reference in New Issue
Block a user