From 5b4643c8f96d0d2c5b0827a4f7bb0ec74f53791f Mon Sep 17 00:00:00 2001 From: jeremygan2021 Date: Sun, 1 Mar 2026 18:18:46 +0800 Subject: [PATCH] finish --- miniprogram/src/pages/courses/detail.tsx | 44 +++++++++++++++++------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/miniprogram/src/pages/courses/detail.tsx b/miniprogram/src/pages/courses/detail.tsx index 89ad324..97cdb63 100644 --- a/miniprogram/src/pages/courses/detail.tsx +++ b/miniprogram/src/pages/courses/detail.tsx @@ -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(null) const [loading, setLoading] = useState(true) + const courseIdRef = useRef('') 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 = { @@ -107,7 +127,15 @@ export default function CourseDetail() { {detail.is_video_course && ( 课程视频 - {detail.video_embed_code ? ( + {detail.video_url ? ( + - ) : detail.video_url ? ( -