Jiarenxiang | 3672848 | 2025-06-07 21:51:26 +0800 | [diff] [blame] | 1 | import React, { useState } from 'react'; |
| 2 | |
| 3 | const planets = [ |
| 4 | { name: 'Mercury', desc: 'The smallest planet.', img: 'https://images.unsplash.com/photo-1462331940025-496dfbfc7564?auto=format&fit=crop&w=400&q=80' }, |
| 5 | { name: 'Venus', desc: 'The hottest planet.', img: 'https://images.unsplash.com/photo-1465101046530-73398c7f28ca?auto=format&fit=crop&w=400&q=80' }, |
| 6 | { name: 'Earth', desc: 'Our home planet.', img: 'https://images.unsplash.com/photo-1465101178521-c1a9136a3b99?auto=format&fit=crop&w=400&q=80' }, |
| 7 | { name: 'Mars', desc: 'The red planet.', img: 'https://images.unsplash.com/photo-1462331940025-496dfbfc7564?auto=format&fit=crop&w=400&q=80' }, |
| 8 | { name: 'Jupiter', desc: 'The largest planet.', img: 'https://images.unsplash.com/photo-1465101178521-c1a9136a3b99?auto=format&fit=crop&w=400&q=80' }, |
| 9 | ]; |
| 10 | |
| 11 | const navItems = ['首页', '资源', '关于', '联系']; |
| 12 | |
| 13 | const Home: React.FC = () => { |
| 14 | const [search, setSearch] = useState(''); |
| 15 | |
| 16 | const filteredPlanets = planets.filter(p => |
| 17 | p.name.toLowerCase().includes(search.toLowerCase()) |
| 18 | ); |
| 19 | |
| 20 | return ( |
| 21 | <div style={{ fontFamily: 'sans-serif', background: 'linear-gradient(to bottom, #0f2027, #2c5364)', minHeight: '100vh', color: '#fff' }}> |
| 22 | {/* 导航栏 */} |
| 23 | <nav style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '24px 48px', background: 'rgba(0,0,0,0.4)' }}> |
| 24 | <div style={{ fontWeight: 'bold', fontSize: 28, letterSpacing: 2 }}>🌌 PT星球</div> |
| 25 | <div> |
| 26 | {navItems.map(item => ( |
| 27 | <a |
| 28 | key={item} |
| 29 | href="#" |
| 30 | style={{ |
| 31 | color: '#fff', |
| 32 | margin: '0 18px', |
| 33 | textDecoration: 'none', |
| 34 | fontSize: 18, |
| 35 | transition: 'color 0.2s', |
| 36 | }} |
| 37 | > |
| 38 | {item} |
| 39 | </a> |
| 40 | ))} |
| 41 | </div> |
| 42 | </nav> |
| 43 | |
| 44 | {/* 搜索框 */} |
| 45 | <div style={{ display: 'flex', justifyContent: 'center', margin: '48px 0 32px 0' }}> |
| 46 | <input |
| 47 | type="text" |
| 48 | placeholder="搜索星球资源..." |
| 49 | value={search} |
| 50 | onChange={e => setSearch(e.target.value)} |
| 51 | style={{ |
| 52 | width: 360, |
| 53 | padding: '12px 20px', |
| 54 | borderRadius: 24, |
| 55 | border: 'none', |
| 56 | fontSize: 18, |
| 57 | outline: 'none', |
| 58 | boxShadow: '0 2px 12px rgba(0,0,0,0.2)', |
| 59 | }} |
| 60 | /> |
| 61 | </div> |
| 62 | |
| 63 | {/* 资源卡片 */} |
| 64 | <div style={{ |
| 65 | display: 'flex', |
| 66 | flexWrap: 'wrap', |
| 67 | justifyContent: 'center', |
| 68 | gap: '32px', |
| 69 | padding: '0 48px 48px 48px' |
| 70 | }}> |
| 71 | {filteredPlanets.map(planet => ( |
| 72 | <div |
| 73 | key={planet.name} |
| 74 | style={{ |
| 75 | background: 'rgba(255,255,255,0.08)', |
| 76 | borderRadius: 18, |
| 77 | width: 260, |
| 78 | boxShadow: '0 4px 24px rgba(0,0,0,0.18)', |
| 79 | overflow: 'hidden', |
| 80 | transition: 'transform 0.2s', |
| 81 | }} |
| 82 | > |
| 83 | <img src={planet.img} alt={planet.name} style={{ width: '100%', height: 140, objectFit: 'cover' }} /> |
| 84 | <div style={{ padding: 20 }}> |
| 85 | <div style={{ fontWeight: 'bold', fontSize: 22, marginBottom: 8 }}>{planet.name}</div> |
| 86 | <div style={{ fontSize: 16, color: '#cfd8dc' }}>{planet.desc}</div> |
| 87 | </div> |
| 88 | </div> |
| 89 | ))} |
| 90 | </div> |
| 91 | </div> |
| 92 | ); |
| 93 | }; |
| 94 | |
| 95 | export default Home; |