'use client' import { useState, useEffect } from 'react' import { motion } from 'framer-motion' import { Calendar, Eye, ArrowRight, Loader2 } from 'lucide-react' import { Card, CardContent } from '@/components/ui/card' import Link from 'next/link' type News = { id: number title: string category: string excerpt: string createdAt: string views: number } const categories = ["全部", "公司新闻", "荣誉获奖", "产品发布", "媒体报道", "行业洞察"] export default function NewsPage() { const [news, setNews] = useState([]) const [isLoading, setIsLoading] = useState(true) const [activeCategory, setActiveCategory] = useState("全部") useEffect(() => { const fetchNews = async () => { try { const url = activeCategory === "全部" ? '/api/news' : `/api/news?category=${encodeURIComponent(activeCategory)}` const res = await fetch(url) if (res.ok) { const data = await res.json() setNews(data.news) } } catch (error) { console.error('加载新闻失败', error) } finally { setIsLoading(false) } } fetchNews() }, [activeCategory]) return (
{/* Header */}

最新动态

了解白马家园最新资讯,分享我们的成长与思考

{/* Category Filter */}
{categories.map((category) => ( ))}
{/* Loading State */} {isLoading ? (
) : news.length === 0 ? (
该分类下暂无动态
) : ( /* News Grid */
{news.map((item, index) => ( {/* Placeholder Color Block */}
{item.id}
{item.category}
{new Date(item.createdAt).toLocaleDateString()}

{item.title}

{item.excerpt}

{item.views} 次阅读
阅读详情
))}
)}
) }