nomadro/apps/miniprogram/h5/src/pages/social/_components/JoinPaySheet.tsx
Eric 92bbee3c6c Ship native social weapp: immersive hall chat, SRS live, join pay.
Wire Taro social pages to social_svc (Centrifugo + live RTMP), drop multi-channel chat chrome, and add weapp WXSS sanitize/deploy helpers.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-02 12:33:35 +08:00

165 lines
4.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

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.

import { useEffect, useState } from 'react'
import { Input } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { H5El } from './H5El'
import {
fetchSocialJoinStatus,
isSocialJoinLocal,
paySocialJoin,
} from '@/utils/socialJoinPay'
import './JoinPaySheet.scss'
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
const EMAIL_KEY = 'userEmail'
type Props = {
open: boolean
onClose: () => void
onPaid?: () => void
}
/**
* 加群收费底栏 — 微信虚拟支付(social-join),不是 VIP / community。
* rem + 全宽底栏,避免 designWidth:750 缩水。
*/
export function JoinPaySheet({ open, onClose, onPaid }: Props) {
const [email, setEmail] = useState('')
const [busy, setBusy] = useState(false)
const [err, setErr] = useState('')
const [priceLabel, setPriceLabel] = useState('¥49')
const [already, setAlready] = useState(false)
useEffect(() => {
if (!open) return
try {
setEmail(String(Taro.getStorageSync(EMAIL_KEY) || ''))
} catch {
setEmail('')
}
setErr('')
setBusy(false)
setAlready(isSocialJoinLocal())
void fetchSocialJoinStatus().then((s) => {
if (!s) return
if (s.isMember) setAlready(true)
if (s.priceFen > 0) setPriceLabel(`¥${(s.priceFen / 100).toFixed(0)}`)
})
}, [open])
if (!open) return null
const submit = async () => {
if (busy) return
if (already) {
onClose()
return
}
const value = email.trim().toLowerCase()
if (!EMAIL_RE.test(value)) {
setErr('请输入有效邮箱')
return
}
setErr('')
setBusy(true)
try {
Taro.setStorageSync(EMAIL_KEY, value)
Taro.setStorageSync('userName', value.split('@')[0] || '游民')
await paySocialJoin()
setAlready(true)
Taro.showToast({ title: '已加入游民社区', icon: 'success' })
onPaid?.()
onClose()
} catch (e) {
const msg = String((e as Error)?.message || e || '')
if (/取消|cancel/i.test(msg)) {
setErr('')
} else {
setErr(msg || '支付唤起失败,请稍后重试')
}
} finally {
setBusy(false)
}
}
return (
<H5El className='social-join-sheet-mask' onClick={() => !busy && onClose()}>
<H5El
className='social-join-sheet-panel'
onClick={(e) => {
e?.stopPropagation?.()
}}
>
<H5El className='social-join-sheet-handle' aria-hidden />
<H5El className='social-join-sheet-head'>
<H5El as='span' className='social-join-brand'>
✨ 游民社区 · 加群
</H5El>
<H5El
as='button'
type='button'
className='social-join-sheet-close'
aria-label='关闭'
onClick={() => !busy && onClose()}
>
✕
</H5El>
</H5El>
<H5El as='h2' className='social-join-sheet-title'>
{already ? '你已在群里' : '加入游民社区'}
</H5El>
<H5El as='p' className='social-muted social-join-sheet-lead'>
{already
? '认识同频 · 开视频 · 找搭子,直接去逛就好。'
: `认识同频的人 · 开视频聊聊 · 出来见一面 · 一起做点事`}
</H5El>
{!already ? (
<>
<H5El className='social-join-price' aria-label='加群费用'>
<H5El as='strong'>{priceLabel}</H5El>
<H5El as='span'>一次性加群 · 非 VIP 会员</H5El>
</H5El>
<H5El className='social-join-field'>
<H5El as='span'>邮箱</H5El>
<Input
className='social-join-input'
type='text'
placeholder='你的常用邮箱'
value={email}
disabled={busy}
onInput={(e) => setEmail(e.detail.value)}
/>
</H5El>
{err ? (
<H5El as='p' className='social-join-err' role='alert'>
{err}
</H5El>
) : null}
<H5El
as='button'
type='button'
className='btn btn-primary social-join-sheet-submit'
onClick={() => void submit()}
>
{busy ? '正在唤起支付…' : `确认并支付 ${priceLabel}`}
</H5El>
<H5El as='p' className='social-join-privacy'>
🔒 邮箱用于账号识别 · 微信小程序虚拟支付
</H5El>
</>
) : (
<H5El
as='button'
type='button'
className='btn btn-primary social-join-sheet-submit'
onClick={onClose}
>
好的,继续逛
</H5El>
)}
</H5El>
</H5El>
)
}