This commit is contained in:
@@ -7,6 +7,7 @@ export default defineAppConfig({
|
||||
'pages/courses/detail',
|
||||
'pages/forum/index',
|
||||
'pages/goods/detail',
|
||||
'pages/webview/index',
|
||||
'pages/cart/cart',
|
||||
'pages/order/checkout',
|
||||
'pages/order/payment',
|
||||
|
||||
@@ -71,6 +71,19 @@ export default function CourseDetail() {
|
||||
return `${year}/${month}/${day} ${hour}:${minute}`
|
||||
}
|
||||
|
||||
const extractIframeSrc = (html: string) => {
|
||||
if (!html) return null
|
||||
const match = html.match(/src=["'](.*?)["']/)
|
||||
return match ? match[1] : null
|
||||
}
|
||||
|
||||
const handleOpenWebview = (url: string) => {
|
||||
if (!url) return
|
||||
Taro.navigateTo({
|
||||
url: `/pages/webview/index?url=${encodeURIComponent(url)}`
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<View className='page-container'>
|
||||
<ScrollView scrollY className='scroll-content'>
|
||||
@@ -94,7 +107,19 @@ export default function CourseDetail() {
|
||||
{detail.is_video_course && (
|
||||
<View className='section video-section'>
|
||||
<Text className='section-title'>课程视频</Text>
|
||||
{detail.video_url ? (
|
||||
{detail.video_embed_code ? (
|
||||
<View className='video-locked' onClick={() => {
|
||||
const src = extractIframeSrc(detail.video_embed_code)
|
||||
if (src) handleOpenWebview(src)
|
||||
else Taro.showToast({ title: '无法解析视频地址', icon: 'none' })
|
||||
}}>
|
||||
<Image src={detail.cover_image_url} className='locked-bg' mode='aspectFill' />
|
||||
<View className='locked-overlay'>
|
||||
<View className='lock-icon' style={{fontSize: '40px'}}>▶</View>
|
||||
<Text className='lock-text'>点击观看视频</Text>
|
||||
</View>
|
||||
</View>
|
||||
) : detail.video_url ? (
|
||||
<Video
|
||||
src={detail.video_url}
|
||||
className='course-video'
|
||||
|
||||
3
miniprogram/src/pages/webview/index.config.ts
Normal file
3
miniprogram/src/pages/webview/index.config.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
navigationBarTitleText: '加载中...'
|
||||
}
|
||||
14
miniprogram/src/pages/webview/index.tsx
Normal file
14
miniprogram/src/pages/webview/index.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { WebView } from '@tarojs/components'
|
||||
import { useRouter } from '@tarojs/taro'
|
||||
|
||||
export default function WebViewPage() {
|
||||
const router = useRouter()
|
||||
const { url } = router.params
|
||||
|
||||
if (!url) return null
|
||||
|
||||
// Ensure url has protocol if missing (e.g. starts with //)
|
||||
const fullUrl = url.startsWith('//') ? `https:${url}` : url
|
||||
|
||||
return <WebView src={fullUrl} />
|
||||
}
|
||||
Reference in New Issue
Block a user