import React, { useState, useCallback } from 'react'; import { useTranslation } from '../js/i18n'; import SEO from './SEO'; import styled from 'styled-components'; import { usePageLoading } from '../hooks/usePageLoading'; import LoadingOverlay from './LoadingOverlay'; // 复用相同的样式组件 const Container = styled.div` min-height: 100vh; background: linear-gradient(135deg, #f5f7ff 0%, #ffffff 100%); padding: 4rem 2rem 2rem; position: relative; &::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: linear-gradient(90deg, rgba(99, 102, 241, 0.05) 1px, transparent 1px), linear-gradient(rgba(99, 102, 241, 0.05) 1px, transparent 1px); background-size: 20px 20px; pointer-events: none; } `; const ContentWrapper = styled.div` max-width: 1400px; margin: 0 auto; position: relative; z-index: 1; `; const Title = styled.h2` font-size: 1.8rem; margin-bottom: 1.5rem; background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 700; letter-spacing: -0.02em; text-align: center; `; function UrlEncoderDecoder() { const { t } = useTranslation(); const isLoading = usePageLoading(); const [input, setInput] = useState(''); const [resultText, setResultText] = useState(''); const [isCopied, setIsCopied] = useState(false); const [mode, setMode] = useState('decode'); const handleModeChange = (e) => { setMode(e.target.value); setInput(''); setResultText(''); }; const handleInputChange = (e) => { const inputValue = e.target.value; setInput(inputValue); try { let result; if (mode === 'decode') { result = decodeURIComponent(inputValue); } else { result = encodeURIComponent(inputValue); } setResultText(result); } catch (error) { setResultText('Invalid input'); } }; const handleCopy = useCallback(() => { navigator.clipboard.writeText(resultText).then(() => { setIsCopied(true); setTimeout(() => setIsCopied(false), 2000); }); }, [resultText]); return ( <> {isLoading && } {t('tools.urlEncodeDecode.title')}