import React, { useEffect, useState } from "react"; import axios from "axios"; import ReactDOM from "react-dom"; export default function SocialLinks() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [showQRCode, setShowQRCode] = useState(false); const [activeLink, setActiveLink] = useState(null); const [isMobile, setIsMobile] = useState(false); useEffect(() => { const checkMobile = () => { setIsMobile(window.innerWidth <= 768); }; checkMobile(); window.addEventListener('resize', checkMobile); return () => window.removeEventListener('resize', checkMobile); }, []); useEffect(() => { if (showQRCode && isMobile) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = ''; } return () => { document.body.style.overflow = ''; }; }, [showQRCode, isMobile]); useEffect(() => { async function fetchData() { try { setLoading(true); const res = await axios.get("/api/get-component-data", { params: { component_name: "SocialLinks" }, }); setData(res.data.data); } catch (err) { setError("获取SocialLinks数据失败"); } finally { setLoading(false); } } fetchData(); }, []); const handleClose = () => { setShowQRCode(false); setActiveLink(null); }; if (loading) return null; if (error) return null; if (!data || !Array.isArray(data.items) || !data.items.length) return null; return ( ); } function QrCodeModal({ open, onClose, image }) { if (!open) return null; return ReactDOM.createPortal(
e.stopPropagation()} > 微信二维码
扫码关注公众号
, document.body ); }