This commit is contained in:
@@ -1,16 +1,36 @@
|
||||
import { View, Text, Button, Image, ScrollView, Video } from '@tarojs/components'
|
||||
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||
import { useState } from 'react'
|
||||
import Taro, { useLoad, useDidShow, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||
import { useState, useRef } from 'react'
|
||||
import { getVBCourseDetail } from '../../api'
|
||||
import { login } from '../../utils/request'
|
||||
import { checkLogin } from '../../utils/auth'
|
||||
import './detail.scss'
|
||||
|
||||
export default function CourseDetail() {
|
||||
const [detail, setDetail] = useState<any>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const courseIdRef = useRef<string>('')
|
||||
|
||||
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> = {
|
||||
@@ -107,7 +127,15 @@ export default function CourseDetail() {
|
||||
{detail.is_video_course && (
|
||||
<View className='section video-section'>
|
||||
<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={() => {
|
||||
const src = extractIframeSrc(detail.video_embed_code)
|
||||
if (src) handleOpenWebview(src)
|
||||
@@ -119,14 +147,6 @@ export default function CourseDetail() {
|
||||
<Text className='lock-text'>点击观看视频</Text>
|
||||
</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}>
|
||||
<Image src={detail.cover_image_url} className='locked-bg' mode='aspectFill' />
|
||||
|
||||
Reference in New Issue
Block a user