import { useState, useMemo } from 'react' import Taro from '@tarojs/taro' import { View, Text, ScrollView } from '@tarojs/components' import { Search, Grid, GridItem } from '@antmjs/vantui' import ForumPostCard from '@/components/ForumPostCard' import { getForumPostsBySubCategory } from '@/mock/forum' import type { Article, ForumSubCategory } from '@/types/article' import './index.less' /** 获取状态栏 + 导航栏高度 */ function getNavBarHeight() { const systemInfo = Taro.getSystemInfoSync() const statusBarHeight = systemInfo.statusBarHeight || 20 const navBarHeight = 44 return { statusBarHeight, navBarHeight, totalHeight: statusBarHeight + navBarHeight } } /** 论坛 5 个子分类 */ const FORUM_CATEGORIES: { id: ForumSubCategory; label: string; icon: string }[] = [ { id: 'life', label: '校园生活', icon: '🌸' }, { id: 'study', label: '学习交流', icon: '📚' }, { id: 'lost-found', label: '失物招领', icon: '🔍' }, { id: 'secondhand', label: '二手交易', icon: '🛍' }, { id: 'tree-hole', label: '树洞', icon: '🌳' }, ] export default function Forum() { const [activeCategory, setActiveCategory] = useState('life') const navBarHeight = useMemo(() => getNavBarHeight(), []) /** 按当前子分类过滤帖子 */ const filteredPosts = useMemo( () => getForumPostsBySubCategory(activeCategory), [activeCategory], ) /** 搜索 */ const handleSearch = () => { Taro.navigateTo({ url: '/pages/search/index' }) } /** 帖子点击 */ const handlePostClick = (post: Article) => { Taro.navigateTo({ url: `/pages/article/index?id=${post.id}` }) } /** 发布帖子 */ const handlePublish = () => { Taro.showToast({ title: '发布功能即将上线', icon: 'none' }) } return ( {/* ========== 自定义导航栏(标题 + 发布) ========== */} 校园论坛 ✏️ {/* 占位 */} {/* ========== 主体内容(搜索 + 分类 + 列表)全部可滚动 ========== */} {/* 搜索栏(主体内容区顶部) */} {/* 5 个子分类导航 */} {FORUM_CATEGORIES.map((cat) => ( setActiveCategory(cat.id)} /> ))} {/* 列表头 */} {FORUM_CATEGORIES.find((c) => c.id === activeCategory)?.label || ''} ·{' '} {filteredPosts.length} 条 {/* 帖子列表 */} {filteredPosts.map((post) => ( ))} {filteredPosts.length === 0 && ( 该板块下暂无帖子 )} ) }