nomadro/apps/miniprogram/h5/src/pages/community/index.tsx
eric 98a54730ff Port nomadvip VIP into native WeChat pages and document the flow.
Add vip-course/lesson/ebook with source markdown seeds, VIP order API + admin offers, ban web-view for content, and update READMEs for weapp rebuild/extract scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-04 22:30:27 +08:00

259 lines
10 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 社区首页收敛:仅顶栏 + Hero;「加群」按 flags.joinGroupAction 弹窗或跳 VIP。
* Hero 视觉:社交星座网(区别于门户首页地球)。对齐 Next `/community`。
*/
import { View, Button } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { useEffect, useMemo, useState } from 'react'
import { CommunityNavbar } from '../../components/Chrome'
import { H5Box, H5Txt } from '../../components/H5Box'
import { WechatOaModal } from '../../components/WechatOaModal'
import { TYPEWRITER_LINES, TYPEWRITER_LINES_EN } from '../../data/homeStatic'
import { MiniModuleGate } from '@/components/MiniModuleGate'
import { useNomadroTheme } from '@/utils/h5Theme'
import { usePageShare, markPageShare } from '@/utils/pageShare'
import { getSafeAreaMetrics } from '@/utils/safeArea'
import { getCachedRemoteConfig, loadRemoteConfig } from '@/services/remoteConfig'
import { usePageTrack } from '@/hooks/usePageTrack'
import { trackTap } from '@/utils/track'
import './index.scss'
const isH5 = process.env.TARO_ENV === 'h5'
const SOCIAL_MESH_SVG = `<svg class="social-mesh-svg" viewBox="0 0 400 400" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<defs>
<radialGradient id="meshGlow" cx="50%" cy="50%" r="50%">
<stop offset="0%" stop-color="#4ECDC4" stop-opacity="0.22"/>
<stop offset="100%" stop-color="#4ECDC4" stop-opacity="0"/>
</radialGradient>
<linearGradient id="meshLink" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#FF6B6B"/>
<stop offset="50%" stop-color="#FFE66D"/>
<stop offset="100%" stop-color="#4ECDC4"/>
</linearGradient>
</defs>
<circle cx="200" cy="200" r="170" fill="url(#meshGlow)"/>
<g stroke="url(#meshLink)" stroke-width="1.6" stroke-linecap="round" fill="none">
<path class="mesh-link" d="M200 200 L118 112" stroke-dasharray="5 7"/>
<path class="mesh-link" d="M200 200 L292 98" stroke-dasharray="5 7"/>
<path class="mesh-link" d="M200 200 L318 220" stroke-dasharray="5 7"/>
<path class="mesh-link" d="M200 200 L260 308" stroke-dasharray="5 7"/>
<path class="mesh-link" d="M200 200 L95 268" stroke-dasharray="5 7"/>
<path class="mesh-link" d="M118 112 L292 98" stroke-opacity="0.35" stroke-dasharray="3 8"/>
<path class="mesh-link" d="M318 220 L260 308" stroke-opacity="0.35" stroke-dasharray="3 8"/>
</g>
<circle r="3.5" fill="#FFE66D"><animateMotion dur="3.2s" repeatCount="indefinite" path="M200 200 L292 98"/></circle>
<circle r="3" fill="#4ECDC4"><animateMotion dur="4s" repeatCount="indefinite" path="M200 200 L95 268" begin="0.6s"/></circle>
<circle r="3" fill="#FF6B6B"><animateMotion dur="3.6s" repeatCount="indefinite" path="M200 200 L318 220" begin="1.2s"/></circle>
<g>
<g transform="translate(200 200)">
<circle r="36" fill="rgba(17,24,39,0.92)" stroke="url(#meshLink)" stroke-width="2.5"/>
<circle r="28" fill="rgba(78,205,196,0.12)"/>
<text text-anchor="middle" dominant-baseline="central" font-size="28">👋</text>
</g>
<g transform="translate(118 112)">
<circle r="26" fill="rgba(17,24,39,0.95)" stroke="#FF6B6B" stroke-width="2"/>
<text text-anchor="middle" dominant-baseline="central" font-size="22">👩‍💻</text>
</g>
<g transform="translate(292 98)">
<circle r="24" fill="rgba(17,24,39,0.95)" stroke="#FFE66D" stroke-width="2"/>
<text text-anchor="middle" dominant-baseline="central" font-size="20">🧑‍🔬</text>
</g>
<g transform="translate(318 220)">
<circle r="25" fill="rgba(17,24,39,0.95)" stroke="#4ECDC4" stroke-width="2"/>
<text text-anchor="middle" dominant-baseline="central" font-size="21">🧑‍🎨</text>
</g>
<g transform="translate(260 308)">
<circle r="24" fill="rgba(17,24,39,0.95)" stroke="#A78BFA" stroke-width="2"/>
<text text-anchor="middle" dominant-baseline="central" font-size="20">🧔</text>
</g>
<g transform="translate(95 268)">
<circle r="23" fill="rgba(17,24,39,0.95)" stroke="#F472B6" stroke-width="2"/>
<text text-anchor="middle" dominant-baseline="central" font-size="19">🧚‍♀️</text>
</g>
</g>
<circle class="mesh-online" cx="136" cy="96" r="5" fill="#22c55e"/>
<circle class="mesh-online" cx="308" cy="84" r="4.5" fill="#22c55e"/>
<circle class="mesh-online" cx="336" cy="206" r="4.5" fill="#22c55e"/>
</svg>`
function HomePageInner() {
usePageTrack('pages/community/index', '旅居社群')
const theme = useNomadroTheme()
const [tw, setTw] = useState('')
const [joinOpen, setJoinOpen] = useState(false)
const safe = useMemo(() => getSafeAreaMetrics(), [])
const safeStyle = useMemo(
() => ({
['--safe-status-bar' as string]: `${safe.statusBarHeight}px`,
['--safe-nav-bar' as string]: `${safe.navBarHeight}px`,
['--safe-menu-pad' as string]: `${safe.menuRightPad}px`,
['--safe-header' as string]: `${safe.headerHeight}px`,
}),
[safe],
)
useEffect(() => {
void loadRemoteConfig(true)
}, [])
async function onJoinClick() {
// 点击前强制拉最新远程配置(后台 VIP「加群→跳转」实时生效)
try {
await loadRemoteConfig(true)
} catch {
/* 用缓存 */
}
const action = getCachedRemoteConfig().flags.joinGroupAction
if (action === 'vip') {
void Taro.navigateTo({ url: '/pages/vip/index' })
return
}
setJoinOpen(true)
}
useEffect(() => {
let locale: 'zh' | 'en' = 'zh'
try {
const l = Taro.getStorageSync('nomadro-locale')
if (l === 'en' || l === 'zh') locale = l
} catch {
/* ignore */
}
const phrases = locale === 'en' ? TYPEWRITER_LINES_EN : TYPEWRITER_LINES
let phraseIdx = 0
let charIdx = 0
let deleting = false
let timer: ReturnType<typeof setTimeout>
const type = () => {
const current = phrases[phraseIdx] || ''
if (!deleting) {
setTw(current.substring(0, charIdx + 1))
charIdx++
if (charIdx === current.length) {
deleting = true
timer = setTimeout(type, 2500)
return
}
timer = setTimeout(type, 60)
} else {
setTw(current.substring(0, charIdx - 1))
charIdx--
if (charIdx === 0) {
deleting = false
phraseIdx = (phraseIdx + 1) % phrases.length
}
timer = setTimeout(type, 30)
}
}
timer = setTimeout(type, 400)
return () => clearTimeout(timer)
}, [])
return (
<View
className="page-shell home-flow home-flow--hero-only"
data-theme={theme}
style={safeStyle}
>
<CommunityNavbar />
<H5Box className="hero" id="hero">
<H5Box className="hero-bg-shapes" aria-hidden>
<H5Box className="shape shape-1" />
<H5Box className="shape shape-2" />
<H5Box className="shape shape-3" />
</H5Box>
<H5Box className="hero-inner">
<H5Box className="hero-top">
<H5Box className="hero-content">
<H5Box className="hero-title">
<H5Txt className="hero-title-line">在任意城市</H5Txt>
<H5Txt className="hero-title-line">
<H5Txt className="gradient-text">过你想要的生活</H5Txt>
</H5Txt>
</H5Box>
<H5Txt className="hero-title-spark" aria-hidden>
✨
</H5Txt>
<H5Txt className="hero-subtitle">
{tw}
<H5Txt className="typewriter-cursor">|</H5Txt>
</H5Txt>
</H5Box>
<H5Box className="hero-visual">
<H5Box className="social-mesh">
{isH5 ? (
<H5Box className="social-mesh-host" html={SOCIAL_MESH_SVG} />
) : (
<H5Box className="social-mesh-css" aria-hidden>
<H5Box className="social-mesh-css-glow" />
<H5Box className="social-mesh-css-ring" />
<H5Box className="social-mesh-css-node social-mesh-css-node-1">
<H5Txt>✈️</H5Txt>
</H5Box>
<H5Box className="social-mesh-css-node social-mesh-css-node-2">
<H5Txt>💻</H5Txt>
</H5Box>
<H5Box className="social-mesh-css-node social-mesh-css-node-3">
<H5Txt>🏠</H5Txt>
</H5Box>
<H5Box className="social-mesh-css-node social-mesh-css-node-4">
<H5Txt>☕</H5Txt>
</H5Box>
<H5Box className="social-mesh-css-node social-mesh-css-node-5">
<H5Txt>🌏</H5Txt>
</H5Box>
<H5Box className="social-mesh-css-node social-mesh-css-node-6">
<H5Txt>🤝</H5Txt>
</H5Box>
<H5Box className="social-mesh-css-core">
<H5Txt>👋</H5Txt>
</H5Box>
</H5Box>
)}
<H5Box className="social-float-chips">
<H5Box className="social-chip sc-1">
<H5Txt>💬 3 条新消息</H5Txt>
</H5Box>
<H5Box className="social-chip sc-2">
<H5Txt>🟢 128 人在线</H5Txt>
</H5Box>
<H5Box className="social-chip sc-3">
<H5Txt>🤝 同城聚会</H5Txt>
</H5Box>
</H5Box>
</H5Box>
</H5Box>
</H5Box>
<H5Box className="hero-bottom">
<H5Box className="hero-actions">
<Button className="btn btn-primary" onClick={trackTap('加群', onJoinClick)}>
👥 加群
</Button>
</H5Box>
</H5Box>
</H5Box>
</H5Box>
<WechatOaModal open={joinOpen} onClose={() => setJoinOpen(false)} />
</View>
)
}
function HomePage() {
usePageShare({ title: 'nomadro · 旅居社群', path: '/pages/community/index' })
return (
<MiniModuleGate moduleKey="community">
<HomePageInner />
</MiniModuleGate>
)
}
export default markPageShare(HomePage)