'use client'; import { useState, useEffect, useRef } from 'react'; import Image from 'next/image'; import { Card, CardBody } from '@heroui/react'; import { useLanguage } from '@/contexts/LanguageContext'; export default function SecuritySection() { const { t } = useLanguage(); const [animate, setAnimate] = useState(false); const sectionRef = useRef(null); const [cardHovers, setCardHovers] = useState<{[key: number]: {x: number, y: number} | null}>({}); useEffect(() => { const currentRef = sectionRef.current; if (!currentRef) return; const observer = new IntersectionObserver( (entries) => { if (entries[0].isIntersecting) { setAnimate(true); observer.disconnect(); } }, { threshold: 0.3 } ); observer.observe(currentRef); return () => observer.disconnect(); }, []); const handleCardMouseMove = (e: React.MouseEvent, index: number) => { const rect = e.currentTarget.getBoundingClientRect(); const x = ((e.clientX - rect.left) / rect.width) * 100; const y = ((e.clientY - rect.top) / rect.height) * 100; setCardHovers(prev => ({...prev, [index]: {x, y}})); }; const handleCardMouseLeave = (index: number) => { setCardHovers(prev => ({...prev, [index]: null})); }; const getBorderGradients = (index: number) => { const hover = cardHovers[index]; if (!hover) return { showTop: false, showRight: false, showBottom: false, showLeft: false, topGradient: '', rightGradient: '', bottomGradient: '', leftGradient: '' }; const { x, y } = hover; // 判断鼠标靠近哪两个边 const nearTop = y < 50; const nearLeft = x < 50; // 计算渐变:以鼠标位置为中心向两边扩散 const spreadRange = 25; // 扩散范围百分比 // 上/下边框:以鼠标 x 位置为中心 const horizontalGradient = `linear-gradient(to right, transparent 0%, rgba(136,136,136,0.3) ${Math.max(0, x - spreadRange)}%, rgba(136,136,136,1) ${x}%, rgba(136,136,136,0.3) ${Math.min(100, x + spreadRange)}%, transparent 100%)`; // 左/右边框:以鼠标 y 位置为中心 const verticalGradient = `linear-gradient(to bottom, transparent 0%, rgba(136,136,136,0.3) ${Math.max(0, y - spreadRange)}%, rgba(136,136,136,1) ${y}%, rgba(136,136,136,0.3) ${Math.min(100, y + spreadRange)}%, transparent 100%)`; return { showTop: nearTop, showRight: !nearLeft, showBottom: !nearTop, showLeft: nearLeft, topGradient: horizontalGradient, rightGradient: verticalGradient, bottomGradient: horizontalGradient, leftGradient: verticalGradient }; }; const features = [ { icon: '/interface-search-magnifying-glass0.svg', titleKey: 'security.audited.title', descKey: 'security.audited.desc', position: 'top-left' }, { icon: '/navigation-building-010.svg', titleKey: 'security.segregated.title', descKey: 'security.segregated.desc', position: 'top-right' }, { icon: '/interface-chart-bar-vertical-010.svg', titleKey: 'security.transparency.title', descKey: 'security.transparency.desc', position: 'bottom-left' }, { icon: '/component-10.svg', titleKey: 'security.partners.title', descKey: null, position: 'bottom-right', special: true } ]; return (

{t('security.title')}

{t('security.subtitle')}

{features.map((feature, index) => { const borders = getBorderGradients(index); return (
handleCardMouseMove(e, index)} onMouseLeave={() => handleCardMouseLeave(index)} > {/* 上边框渐变 */} {borders.showTop && (
)} {/* 右边框渐变 */} {borders.showRight && (
)} {/* 下边框渐变 */} {borders.showBottom && (
)} {/* 左边框渐变 */} {borders.showLeft && (
)} {feature.special ? (

{t(feature.titleKey)}

Icon
) : (
{t(feature.titleKey)}

{t(feature.titleKey)}

{feature.descKey && t(feature.descKey)}

)}
); })}
Logo
); }