finish
All checks were successful
Deploy to Server / deploy (push) Successful in 24s

This commit is contained in:
jeremygan2021
2026-03-01 18:18:46 +08:00
parent 2c5ec64f8f
commit 5b4643c8f9

View File

@@ -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' />