import React, { useEffect, useState, useRef } from 'react'; import { Card, Row, Col, Tag, Button, Spin, Typography, Carousel } from 'antd'; import { RocketOutlined, RightOutlined, LeftOutlined, RightCircleOutlined } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom'; import { motion } from 'framer-motion'; import { getConfigs, getHomePageConfig } from '../api'; import ActivityList from '../components/activity/ActivityList'; import './Home.css'; const { Title, Paragraph } = Typography; const Home = () => { const [products, setProducts] = useState([]); const [loading, setLoading] = useState(true); const [typedText, setTypedText] = useState(''); const [isTypingComplete, setIsTypingComplete] = useState(false); const [currentSlide, setCurrentSlide] = useState(0); const [currentSlide2, setCurrentSlide2] = useState(0); const [homeConfig, setHomeConfig] = useState(null); const [carousel1Items, setCarousel1Items] = useState([]); const [carousel2Items, setCarousel2Items] = useState([]); const fullText = "未来已来 AI 核心驱动"; const navigate = useNavigate(); const carouselRef = useRef(null); const carouselRef2 = useRef(null); useEffect(() => { fetchProducts(); fetchHomePageConfig(); let i = 0; const typingInterval = setInterval(() => { i++; setTypedText(fullText.slice(0, i)); if (i >= fullText.length) { clearInterval(typingInterval); setIsTypingComplete(true); } }, 150); return () => clearInterval(typingInterval); }, []); const fetchProducts = async () => { try { const response = await getConfigs(); setProducts(response.data); } catch (error) { console.error('Failed to fetch products:', error); } finally { setLoading(false); } }; const fetchHomePageConfig = async () => { try { const response = await getHomePageConfig(); const data = response.data; setHomeConfig(data); setCarousel1Items(data.carousel1_items || []); setCarousel2Items(data.carousel2_items || []); } catch (error) { console.error('Failed to fetch homepage config:', error); } }; const cardVariants = { hidden: { opacity: 0, y: 50 }, visible: (i) => ({ opacity: 1, y: 0, transition: { delay: i * 0.1, duration: 0.5, type: "spring", stiffness: 100 } }), hover: { scale: 1.05, rotateX: 5, rotateY: 5, transition: { duration: 0.3 } } }; if (loading) { return (
加载硬件配置中...
); } return (
首页Banner

{homeConfig?.main_title || '"创赢未来"云南2026创业大赛'}

{/* 轮播图 */} {/* 标题区域 */}
{homeConfig?.carousel1_title || '"创赢未来"云南2026创业大赛'} EVENTS
{/* 箭头导航 */}
carouselRef.current?.prev()} onMouseEnter={(e) => { e.currentTarget.style.background = '#1890ff'; e.currentTarget.querySelector('svg').style.color = '#fff'; }} onMouseLeave={(e) => { e.currentTarget.style.background = 'transparent'; e.currentTarget.querySelector('svg').style.color = '#1890ff'; }} style={{ width: 44, height: 44, borderRadius: '50%', background: 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', border: '2px solid #1890ff', transition: 'all 0.3s' }} >
carouselRef.current?.next()} onMouseEnter={(e) => { e.currentTarget.style.background = '#1890ff'; e.currentTarget.querySelector('svg').style.color = '#fff'; }} onMouseLeave={(e) => { e.currentTarget.style.background = 'transparent'; e.currentTarget.querySelector('svg').style.color = '#1890ff'; }} style={{ width: 44, height: 44, borderRadius: '50%', background: 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', border: '2px solid #1890ff', transition: 'all 0.3s' }} >
{/* 轮播图主体 */}
setCurrentSlide(next)} > {(carousel1Items.length > 0 ? carousel1Items : []).map((image, index) => (
{image.title} { e.target.style.display = 'none'; }} /> {/* 渐变遮罩 */}
{/* 标题区域 - 图片上方 */}

{image.title}

{image.subtitle}

{/* 底部信息 */}
{image.status} {image.location}

{image.title}

📅 {image.date} 📍 {image.location}

))} {/* 自定义分页指示器 */}
{(carousel1Items.length > 0 ? carousel1Items : []).map((_, index) => (
carouselRef.current?.goTo(index)} style={{ width: currentSlide === index ? 32 : 10, height: 10, borderRadius: 5, background: currentSlide === index ? '#fff' : 'rgba(255,255,255,0.4)', cursor: 'pointer', transition: 'all 0.3s', }} /> ))}
{/* 第二个轮播图 */} {/* 标题区域 */}
{homeConfig?.carousel2_title || '"七彩云南创业福地"创业主题系列活动'} ACTIVITIES
{/* 箭头导航 */}
carouselRef2.current?.prev()} onMouseEnter={(e) => { e.currentTarget.style.background = '#1890ff'; e.currentTarget.querySelector('svg').style.color = '#fff'; }} onMouseLeave={(e) => { e.currentTarget.style.background = 'transparent'; e.currentTarget.querySelector('svg').style.color = '#1890ff'; }} style={{ width: 44, height: 44, borderRadius: '50%', background: 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', border: '2px solid #1890ff', transition: 'all 0.3s' }} >
carouselRef2.current?.next()} onMouseEnter={(e) => { e.currentTarget.style.background = '#1890ff'; e.currentTarget.querySelector('svg').style.color = '#fff'; }} onMouseLeave={(e) => { e.currentTarget.style.background = 'transparent'; e.currentTarget.querySelector('svg').style.color = '#1890ff'; }} style={{ width: 44, height: 44, borderRadius: '50%', background: 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', border: '2px solid #1890ff', transition: 'all 0.3s' }} >
{/* 轮播图主体 */}
setCurrentSlide2(next)} > {(carousel2Items.length > 0 ? carousel2Items : []).map((image, index) => (
{image.title} { e.target.style.display = 'none'; }} /> {/* 渐变遮罩 */}
{/* 标题区域 - 图片上方 */}

{image.title}

{image.subtitle}

{/* 底部信息 */}
{image.status} {image.location}

{image.title}

📅 {image.date} 📍 {image.location}

))} {/* 自定义分页指示器 */}
{(carousel2Items.length > 0 ? carousel2Items : []).map((_, index) => (
carouselRef2.current?.goTo(index)} style={{ width: currentSlide2 === index ? 32 : 10, height: 10, borderRadius: 5, background: currentSlide2 === index ? '#fff' : 'rgba(255,255,255,0.4)', cursor: 'pointer', transition: 'all 0.3s', }} /> ))}
{products.map((product, index) => ( {product.static_image_url ? ( {product.name} ) : ( )}
} onClick={() => navigate(`/product/${product.id}`)} >
{product.name}
{product.description}
{product.chip_type} {product.has_camera && Camera} {product.has_microphone && Mic}
¥{product.price}
))}
{/* 主办单位信息 */}

主办单位:{homeConfig?.organizer || '云南省人力资源和社会保障厅'} | 承办单位:{homeConfig?.undertaker || '云南省就业局'}

); }; export default Home;