'use client'; import { useState, useMemo, useRef, ChangeEvent } from 'react'; import { useInView } from 'framer-motion'; import { NEWS } from '@/lib/constants'; import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { PageHeader } from '@/components/ui/page-header'; import { Search, Calendar, Filter, ChevronLeft, ChevronRight, ArrowRight } from 'lucide-react'; import { StaticLink } from '@/components/ui/static-link'; import { motion } from 'framer-motion'; const categories = ['全部', '公司新闻', '产品发布']; const ITEMS_PER_PAGE = 9; export default function NewsListPage() { const [selectedCategory, setSelectedCategory] = useState('全部'); const [searchQuery, setSearchQuery] = useState(''); const [currentPage, setCurrentPage] = useState(1); const contentRef = useRef(null); const isContentInView = useInView(contentRef, { once: true, margin: '-100px' }); const filteredNews = useMemo(() => { return NEWS.filter((newsItem) => { const matchesCategory = selectedCategory === '全部' || newsItem.category === selectedCategory; const matchesSearch = newsItem.title.toLowerCase().includes(searchQuery.toLowerCase()) || newsItem.excerpt.toLowerCase().includes(searchQuery.toLowerCase()); return matchesCategory && matchesSearch; }); }, [selectedCategory, searchQuery]); const totalPages = Math.ceil(filteredNews.length / ITEMS_PER_PAGE); const paginatedNews = useMemo(() => { const startIndex = (currentPage - 1) * ITEMS_PER_PAGE; const endIndex = startIndex + ITEMS_PER_PAGE; return filteredNews.slice(startIndex, endIndex); }, [filteredNews, currentPage]); const handlePageChange = (page: number) => { setCurrentPage(page); window.scrollTo({ top: 0, behavior: 'smooth' }); }; const handleCategoryChange = (category: string) => { setSelectedCategory(category); setCurrentPage(1); }; const handleSearchChange = (e: ChangeEvent) => { setSearchQuery(e.target.value); setCurrentPage(1); }; return (
分类筛选:
{categories.map((category) => ( ))}
{paginatedNews.length === 0 ? (

没有找到相关新闻

) : ( <>
{paginatedNews.map((newsItem, index) => ( {newsItem.image ? (
{newsItem.title}
) : (
📰
)}
{newsItem.category}
{newsItem.date}

{newsItem.title}

{newsItem.excerpt}

阅读更多
))}
{totalPages > 1 && (
{Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => ( ))}
)}
显示 {paginatedNews.length} 条,共 {filteredNews.length} 条新闻
)}
); }