/** * VIP 专题 / 云手机课 — 复刻 nomadvip * - /topic/[id]:Header + Breadcrumb + Hero + Curriculum * - /cloudphone:再加 Audience + Benefits + FAQ */ import { View, Text, ScrollView } from '@tarojs/components' import Taro, { useRouter } from '@tarojs/taro' import { useEffect, useMemo, useState } from 'react' import { H5Box, H5Txt } from '../../components/H5Box' import { getVipTopicConfig, getVipTopicCurriculum, resolveTopicId, type VipTopicModule, } from '../../data/vipTopics' import { loadVipCourse } from '../../services/vipLibrary' import { CLOUDPHONE_AUDIENCE, CLOUDPHONE_BENEFITS, CLOUDPHONE_CURRICULUM_META, CLOUDPHONE_FAQ, CLOUDPHONE_HERO, } from '../../data/vipCloudphoneLanding' import { goPage } from '../../utils/nav' import { goVipUnlock, hasVipContentAccessSync, resolveVipContentAccess, subscribeVipAccess, } from '../../utils/vipAccess' import { getLastWatched, getProgress, getBookmarks, getCompletedLessons, isBookmarked, toggleBookmark, } from '../../utils/vipLearning' import { getSafeAreaMetrics } from '../../utils/safeArea' import { useNomadroTheme } from '@/utils/h5Theme' import './index.scss' export default function VipCoursePage() { const theme = useNomadroTheme() const router = useRouter() const topicId = resolveTopicId(router.params?.id) const isCloudphone = topicId === 'cloudphone' const config = getVipTopicConfig(topicId) const localCurriculum = useMemo(() => getVipTopicCurriculum(topicId), [topicId]) const [remoteModules, setRemoteModules] = useState(null) const curriculum = useMemo(() => { if (isCloudphone && remoteModules?.length) { return { modules: remoteModules, hasContent: true } } return localCurriculum }, [isCloudphone, remoteModules, localCurriculum]) const totalLessons = curriculum.modules.reduce((s, m) => s + m.lessons.length, 0) const [isVip, setIsVip] = useState(false) const [ready, setReady] = useState(false) const [expanded, setExpanded] = useState>({}) const [bookmarks, setBookmarks] = useState>(() => getBookmarks()) const [completed, setCompleted] = useState>(() => getCompletedLessons()) const [last, setLast] = useState(() => getLastWatched()) const [progress, setProgress] = useState(() => getProgress(totalLessons)) const [updatingName, setUpdatingName] = useState('') const [faqOpen, setFaqOpen] = useState(0) const safe = getSafeAreaMetrics() const headerPadRight = Math.max(safe.menuRightPad, 12) const heroTitle = isCloudphone ? CLOUDPHONE_HERO.title : `${config?.icon || ''} ${config?.title || ''}` const heroSub = isCloudphone ? CLOUDPHONE_HERO.subtitle : config?.subtitle || '' const heroDesc = isCloudphone ? '' : config?.desc || '' const heroStats = isCloudphone ? CLOUDPHONE_HERO.stats : config?.stats || [] const currTitle = isCloudphone ? CLOUDPHONE_CURRICULUM_META.title : '实战课程' const currSub = isCloudphone ? CLOUDPHONE_CURRICULUM_META.subtitle : '从入门到进阶,完整学习路径' useEffect(() => { Taro.setNavigationBarTitle({ title: isCloudphone ? '云手机实战课' : config?.title || '视频课程', }) void (async () => { if (isCloudphone) { try { const { course } = await loadVipCourse() if (course.modules?.length) { setRemoteModules( course.modules.map((m) => ({ emoji: m.emoji, title: m.title, lessons: m.lessons.map((l) => ({ name: l.name, duration: l.duration, moduleIndex: l.moduleIndex, lessonIndex: l.lessonIndex, })), })), ) } } catch { /* keep local */ } } const ok = await resolveVipContentAccess(true) setIsVip(ok) setReady(true) })() const unsub = subscribeVipAccess((vip) => setIsVip(hasVipContentAccessSync(vip))) return () => unsub() }, [config?.title, isCloudphone]) useEffect(() => { setExpanded(Object.fromEntries(curriculum.modules.map((_, i) => [i, i === 0]))) setLast(getLastWatched()) setProgress(getProgress(totalLessons)) setBookmarks(getBookmarks()) setCompleted(getCompletedLessons()) }, [topicId, curriculum.modules, totalLessons]) if (!config) { return ( 模块不存在 goPage('/pages/vip/index')}> ← 返回首页 ) } const isLivestreamUpdating = topicId === 'livestream' && isVip const showPrep = (topicId === 'indie' || topicId === 'aiagent') && !curriculum.hasContent function onEnroll() { goVipUnlock() } function onPrimaryCta() { if (!isVip) { onEnroll() return } if (last) { goPage(`/pages/vip-lesson/index?m=${last.moduleIndex}&l=${last.lessonIndex}`) return } const first = curriculum.modules[0]?.lessons[0] if (first) { goPage(`/pages/vip-lesson/index?m=${first.moduleIndex}&l=${first.lessonIndex}`) } } function openLesson(m: number, l: number, name: string) { if (isLivestreamUpdating) { setUpdatingName(name) return } if (!isVip) { Taro.showModal({ title: '会员专享', content: '开通 VIP 后可观看全部视频课程', confirmText: '立即报名', success: (r) => { if (r.confirm) onEnroll() }, }) return } goPage(`/pages/vip-lesson/index?m=${m}&l=${l}`) } function onToggleBookmark(m: number, l: number, e: { stopPropagation?: () => void }) { e.stopPropagation?.() toggleBookmark(m, l) setBookmarks(getBookmarks()) } const ctaLabel = !isVip ? '立即报名 →' : last ? '继续学习 →' : '进入课程 →' const headerCta = !isVip ? '报名' : '进入' return ( goPage('/pages/vip/index')}> 🌍 异度星球 { if (!isVip) onEnroll() else onPrimaryCta() }} > {headerCta} goPage('/pages/vip/index')}> 首页 / goPage('/pages/vip/index')}> 模块 / {isCloudphone ? '云手机' : config.title} {heroTitle} {heroSub} {heroDesc ? {heroDesc} : null} {heroStats.map((s) => ( {s.value} {s.label} ))} {showPrep ? ( {config.icon} 课程筹备中,敬请期待 ) : null} {curriculum.hasContent ? ( {ready ? ctaLabel : '…'} ) : null} {isVip && progress.completed > 0 ? ( 学习进度 {progress.completed}/{totalLessons} 节 ) : null} {isCloudphone ? ( <> {CLOUDPHONE_AUDIENCE.title} {CLOUDPHONE_AUDIENCE.subtitle} {CLOUDPHONE_AUDIENCE.items.map((it) => ( {it.emoji} {it.title} {it.desc} ))} {CLOUDPHONE_BENEFITS.title} {CLOUDPHONE_BENEFITS.subtitle} {CLOUDPHONE_BENEFITS.items.map((it) => ( {it.num} {it.title} {it.desc} ))} ) : null} {curriculum.hasContent ? ( {currTitle} {currSub} {curriculum.modules.map((mod, mi) => { const open = expanded[mi] !== false return ( setExpanded((p) => ({ ...p, [mi]: !open }))} > ▶ {mod.emoji} {mod.title} {mod.lessons.length} 节 {open ? mod.lessons.map((les) => { const unlocked = isVip && !isLivestreamUpdating const key = `${les.moduleIndex}-${les.lessonIndex}` const starred = bookmarks.has(key) || isBookmarked(les.moduleIndex, les.lessonIndex) const done = completed.has(key) return ( openLesson(les.moduleIndex, les.lessonIndex, les.name) } > onToggleBookmark(les.moduleIndex, les.lessonIndex, e) } > {starred ? '⭐' : '☆'} {les.name} {done ? ✓ : null} {isLivestreamUpdating ? ( 🛠️ ) : null} {!isVip ? 🔒 : null} {les.duration} {isLivestreamUpdating ? '···' : '→'} ) }) : null} ) })} ) : ( {config.icon} 课程筹备 {config.subtitle || '内容策划中,敬请期待'} )} {isCloudphone ? ( {CLOUDPHONE_FAQ.title} {CLOUDPHONE_FAQ.items.map((item, i) => { const open = faqOpen === i return ( setFaqOpen(open ? null : i)} > {item.q} {open ? '−' : '+'} {open ? {item.a} : null} ) })} ) : null} goPage('/pages/vip/index')}>返回首页 goPage('/pages/vip/index')}>模块列表 {isCloudphone ? '🌍 云手机 · 低成本工作室搭建指南' : `${config.icon} ${config.title} · 异度星球`} {updatingName ? ( setUpdatingName('')}> e.stopPropagation?.()}> 🚧 正在更新 「{updatingName}」正在升级内容,将在完成后第一时间开放。 现在可以先学习「云手机」课程,后续会自动同步最新章节。 setUpdatingName('')}> 稍后再看 { setUpdatingName('') goPage('/pages/vip-course/index?id=cloudphone') }} > 去学云手机 ) : null} ) }