import React, { useState, useEffect, useRef } from 'react'; import { Swiper, SwiperSlide } from 'swiper/react'; import { EffectCoverflow, Pagination, Autoplay, Navigation } from 'swiper/modules'; // 导入 Swiper 样式 import 'swiper/css'; import 'swiper/css/effect-coverflow'; import 'swiper/css/pagination'; import 'swiper/css/navigation'; // 模拟数据接口 interface Article { id: number; cover: string; title: string; relative_link: string; } interface OptionPage { model_bg: { url: string; }; } const CulturePage: React.FC = () => { const [posts, setPosts] = useState([]); const [isPostsFetching, setIsPostsFetching] = useState(true); const [optionPage, setOptionPage] = useState(null); const [displayItems, setDisplayItems] = useState([]); // 模拟数据获取 useEffect(() => { // 模拟异步数据加载 const fetchData = async () => { setIsPostsFetching(true); // 模拟API延迟 await new Promise((resolve) => setTimeout(resolve, 1000)); // 模拟获取文章数据 const mockPosts: Article[] = [ { id: 1, cover: '/x4.png', title: '烽火文化活动1', relative_link: '/culture/1', }, { id: 2, cover: '/x4.png', title: '烽火文化活动2', relative_link: '/culture/2', }, { id: 3, cover: '/x4.png', title: '烽火文化活动3', relative_link: '/culture/3', }, { id: 4, cover: '/x4.png', title: '烽火文化活动4', relative_link: '/culture/4', }, { id: 5, cover: '/x4.png', title: '烽火文化活动5', relative_link: '/culture/5', }, ]; // 模拟选项页面数据 const mockOptionPage: OptionPage = { model_bg: { url: '/culture-bg.jpg', }, }; setPosts(mockPosts); setOptionPage(mockOptionPage); setIsPostsFetching(false); }; fetchData(); }, []); // 监听posts变化,过滤有封面的文章 useEffect(() => { if (posts.length > 0) { const filteredItems = posts.filter((post: Article) => post.cover); setDisplayItems(filteredItems); } }, [posts]); // 空状态组件 const EmptyState = () => (
📝

期待您的投稿!

); return ( <>

烽火文化

{/* 加载状态 */} {isPostsFetching && (

加载中...

)} {/* 空状态 */} {!isPostsFetching && displayItems.length === 0 && } {/* 轮播图 */} {!isPostsFetching && displayItems.length > 0 && ( )}
); }; export default CulturePage;