# 前端模块详解 - Soul创业实验项目
> **核心模块**: 首页、匹配、阅读、我的、支付、分销
**我是卡若。**
这里记录每个前端模块的实现细节,方便以后维护和扩展。
---
## 1. 首页模块
**路径**: `/app/page.tsx`
### 1.1 核心功能
```typescript
export default function HomePage() {
return (
{/* 1. 品牌标签 */}
{/* 2. 书籍封面 */}
{/* 3. 核心数据 */}
{/* 4. 作者信息 */}
{/* 5. 行动按钮 */}
{/* 6. 寄语卡片 */}
{/* 7. 章节列表 */}
)
}
```
### 1.2 关键组件
**书籍封面**:
```typescript
function BookCover({ src }: { src: string }) {
return (
)
}
```
**数据亮点**:
```typescript
function DataHighlights({ price, cases, insights }: Props) {
return (
)
}
```
---
## 2. 匹配模块
**路径**: `/app/match/page.tsx`
### 2.1 核心功能
```typescript
export default function MatchPage() {
const [isMatching, setIsMatching] = useState(false)
const [matchResult, setMatchResult] = useState(null)
const handleMatch = async () => {
setIsMatching(true)
// 模拟匹配过程
await new Promise(resolve => setTimeout(resolve, 2000))
setMatchResult({
name: '创业者小王',
mbti: 'ENTJ',
interests: ['私域运营', '内容创业'],
matchRate: 85
})
setIsMatching(false)
}
return (
{/* 星空背景 */}
{/* 中央星球 */}
{/* 标题 */}
寻找创业合作伙伴
{/* 匹配按钮或结果 */}
{!matchResult ? (
) : (
)}
{/* 快捷操作 */}
{}}
onJoinGroup={() => {}}
/>
)
}
```
### 2.2 关键组件
**星空背景**:
```typescript
function StarfieldBackground() {
const canvasRef = useRef(null)
useEffect(() => {
const canvas = canvasRef.current
const ctx = canvas?.getContext('2d')
if (!canvas || !ctx) return
// 创建星星
const stars = Array.from({ length: 100 }, () => ({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
radius: Math.random() * 2,
opacity: Math.random()
}))
// 绘制动画
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height)
stars.forEach(star => {
ctx.beginPath()
ctx.arc(star.x, star.y, star.radius, 0, Math.PI * 2)
ctx.fillStyle = `rgba(255, 255, 255, ${star.opacity})`
ctx.fill()
})
requestAnimationFrame(animate)
}
animate()
}, [])
return
}
```
---
## 3. 阅读模块
**路径**: `/app/read/[id]/page.tsx`
### 3.1 核心功能
```typescript
export default async function ReadPage({ params }: Props) {
const { id } = params
const section = await getSection(id)
if (!section) {
notFound()
}
return (
{/* 返回按钮 */}
{/* 章节标题 */}
{section.title}
{/* 章节信息 */}
{/* Markdown内容 */}
{/* 章节导航 */}
{/* 分享按钮 */}
)
}
```
### 3.2 Markdown渲染
```typescript
import { marked } from 'marked'
function MarkdownContent({ content }: { content: string }) {
const html = marked(content)
return (
)
}
// CSS样式
.prose {
@apply text-gray-300 leading-relaxed;
}
.prose h1 {
@apply text-3xl font-bold text-white mt-8 mb-4;
}
.prose h2 {
@apply text-2xl font-bold text-white mt-6 mb-3;
}
.prose p {
@apply mb-4;
}
.prose ul {
@apply list-disc list-inside mb-4;
}
.prose code {
@apply bg-gray-800 px-2 py-1 rounded text-[var(--app-brand)];
}
```
---
## 4. 我的模块
**路径**: `/app/my/page.tsx`
### 4.1 核心功能
```typescript
export default function MyPage() {
const { user, isLoggedIn } = useStore()
if (!isLoggedIn) {
return
}
return (
{/* 用户信息卡片 */}
{/* 阅读统计 */}
{/* 分销中心(重点突出) */}
{/* 功能菜单 */}
)
}
```
### 4.2 分销中心
```typescript
function ReferralCenter({ code, earnings, referralCount }: Props) {
return (
分销中心
{/* 收益概览 */}
¥{earnings.toFixed(2)}
累计收益
{/* 邀请码 */}
{/* 生成海报 */}
)
}
```
---
## 5. 支付模块
**路径**: `/components/payment-modal.tsx`
### 5.1 核心流程
```typescript
export function PaymentModal({
isOpen,
amount,
type,
onSuccess
}: Props) {
const [paymentMethod, setPaymentMethod] = useState('alipay')
const [showQRCode, setShowQRCode] = useState(false)
const [isProcessing, setIsProcessing] = useState(false)
// 发起支付
const handlePayment = async () => {
setShowQRCode(true)
// 调用支付API
const order = await createOrder({
amount,
type,
paymentMethod
})
// 展示支付二维码
showPaymentQRCode(order.qrCode)
}
// 确认支付
const confirmPayment = async () => {
setIsProcessing(true)
// 购买逻辑
const success = await purchaseItem(type)
if (success) {
onSuccess()
// 自动跳转到读者群
openWechatGroup()
}
setIsProcessing(false)
}
return (
{!showQRCode ? (
) : (
)}
)
}
```
### 5.2 支付方式组件
```typescript
function PaymentMethodSelection({ selected, onSelect, onConfirm }: Props) {
const methods = [
{
id: 'wechat',
name: '微信支付',
icon: ,
color: '#07C160'
},
{
id: 'alipay',
name: '支付宝',
icon: ,
color: '#1677FF'
},
{
id: 'usdt',
name: 'USDT (TRC20)',
icon: ,
color: '#26A17B'
}
]
return (
{methods.map(method => (
))}
)
}
```
---
## 6. 后台管理模块
**路径**: `/app/admin/page.tsx`
### 6.1 概览页面
```typescript
export default function AdminDashboard() {
const [stats, setStats] = useState(null)
useEffect(() => {
fetchStats()
}, [])
async function fetchStats() {
const res = await fetch('/api/admin', {
headers: {
'Authorization': `Bearer ${getAdminToken()}`
}
})
const data = await res.json()
setStats(data)
}
if (!stats) return
return (
)
}
```
### 6.2 内容管理
```typescript
function ContentManagement() {
const [chapters, setChapters] = useState([])
return (
{/* 操作栏 */}
内容管理
{/* 章节列表 */}
| 章节ID |
标题 |
状态 |
价格 |
操作 |
{chapters.map(chapter => (
| {chapter.id} |
{chapter.title} |
{chapter.isFree ? '免费' : '付费'}
|
¥{chapter.price} |
|
))}
)
}
```
---
## 7. 通用组件库
### 7.1 Button组件
```typescript
interface ButtonProps {
children: React.ReactNode
onClick?: () => void
loading?: boolean
disabled?: boolean
variant?: 'primary' | 'secondary' | 'ghost'
size?: 'sm' | 'md' | 'lg'
}
export function Button({
children,
onClick,
loading,
disabled,
variant = 'primary',
size = 'md'
}: ButtonProps) {
const baseClasses = 'rounded-xl font-semibold transition-all'
const variantClasses = {
primary: 'bg-[var(--app-brand)] text-white hover:opacity-90',
secondary: 'bg-[var(--app-bg-secondary)] text-white',
ghost: 'bg-transparent text-[var(--app-brand)] hover:bg-[var(--app-brand-light)]'
}
const sizeClasses = {
sm: 'px-4 py-2 text-sm',
md: 'px-6 py-3 text-base',
lg: 'px-8 py-4 text-lg'
}
return (
)
}
```
### 7.2 Modal组件
```typescript
export function Modal({
isOpen,
onClose,
children
}: ModalProps) {
if (!isOpen) return null
return (
{/* 背景蒙层 */}
{/* 内容区域 */}
{/* 顶部把手 (仅移动端) */}
{/* 关闭按钮 */}
{/* 内容 */}
{children}
)
}
```
---
**总结**: 前端模块以**组件化**为核心,每个模块职责清晰,组件可复用。核心模块包括首页(展示)、匹配(社交)、阅读(内容)、我的(用户中心)、支付(变现)、后台(管理)。所有模块都遵循统一的设计规范和交互模式。