diff --git a/frontend/src/pages/YichensBoard.jsx b/frontend/src/pages/YichensBoard.jsx
index 802cc0b..85d80e0 100644
--- a/frontend/src/pages/YichensBoard.jsx
+++ b/frontend/src/pages/YichensBoard.jsx
@@ -53,8 +53,28 @@ export default function YichensBoard() {
const res = await fetch(url)
if (!res.ok) throw new Error('posts API error: ' + res.status)
let data = await res.json() || []
+ // 确保data是数组
+ if (!Array.isArray(data)) {
+ data = data.posts || data.data || []
+ }
console.log('YichensBoard: posts data count', data.length)
- if (currentCat) {
+ if (currentCat && Array.isArray(data)) {
+ if (currentCat === '龙') {
+ data = data.filter(p => p.category && (p.category.includes('龙') || p.category.includes('纪念钞')))
+ } else if (currentCat === '蛇') {
+ data = data.filter(p => p.category && p.category.includes('蛇'))
+ } else if (currentCat === '马') {
+ data = data.filter(p => p.category && p.category.includes('马'))
+ } else if (currentCat === '其他') {
+ data = data.filter(p => p.category && !p.category.includes('龙') && !p.category.includes('纪念钞') && !p.category.includes('蛇') && !p.category.includes('马'))
+ }
+ }
+ // 确保data是数组
+ if (!Array.isArray(data)) {
+ data = data.posts || data.data || []
+ }
+ console.log('YichensBoard: posts data count', data.length)
+ if (currentCat && Array.isArray(data)) {
if (currentCat === '龙') {
data = data.filter(p => p.category && (p.category.includes('龙') || p.category.includes('纪念钞')))
} else if (currentCat === '蛇') {
@@ -66,7 +86,7 @@ export default function YichensBoard() {
}
}
// 支持新格式 {posts:[], total:xxx} 或旧格式 [{},{}]
- const postsArray = data.posts || data
+ const postsArray = Array.isArray(data) ? data : (data.posts || [])
const totalCount = data.total || todayStats.total || postsArray.length
setPosts(postsArray)
setTotalPosts(totalCount)
@@ -74,26 +94,27 @@ export default function YichensBoard() {
console.error('YichensBoard: fetchPosts error', e)
setError(e.message)
setPosts([])
+ } finally {
+ setLoading(false)
}
- setLoading(false)
}
useEffect(() => {
if (todayStats.total > 0) {
- // fetchTodayCategory()
- fetchPosts(1, '')
+ fetchPosts(1, categoryFilter, searchKeyword)
}
- }, [todayStats])
+ }, [todayStats, categoryFilter, postTypeFilter])
useEffect(() => {
setPage(1)
- fetchPosts(1, '')
+ fetchPosts(1, categoryFilter, searchKeyword)
}, [searchKeyword])
const togglePost = id => setExpandedPosts(p => ({ ...p, [id]: !p[id] }))
const StatCard = ({ label, value, color, onClick }) => (
-
{ setLoading(true); if (onClick) onClick(); }}
+ style={{
background: 'linear-gradient(145deg, #1f2937 0%, #111827 100%)',
borderRadius: 12, padding: '12px 8px', border: '1px solid #374151',
cursor: onClick ? 'pointer' : 'default',
@@ -122,10 +143,10 @@ export default function YichensBoard() {
📈 连体钞/纪念钞 {dateStr}
- { setPostTypeFilter('all'); setCategoryFilter(''); setPage(1); fetchPosts(1, '') }} />
- { setPostTypeFilter('deal'); setCategoryFilter(''); setPage(1); fetchPosts(1, '') }} />
- { setPostTypeFilter('want'); setCategoryFilter(''); setPage(1); fetchPosts(1, '') }} />
- { setPostTypeFilter('other'); setCategoryFilter(''); setPage(1); fetchPosts(1, '') }} />
+ { setPostTypeFilter('all'); setCategoryFilter(''); setPage(1); }} />
+ { setPostTypeFilter('deal'); setCategoryFilter(''); setPage(1); }} />
+ { setPostTypeFilter('want'); setCategoryFilter(''); setPage(1); }} />
+ { setPostTypeFilter('other'); setCategoryFilter(''); setPage(1); }} />
{[{key:'all',label:'全部'},{key:'deal',label:'出售'},{key:'want',label:'求购'},{key:'other',label:'其他'}].map(k => (
-