wu | eb6e6ca | 2025-06-15 10:35:32 +0800 | [diff] [blame^] | 1 | import React, { useState } from 'react' |
| 2 | import { ThumbsUp } from 'lucide-react' |
| 3 | import '../style/HomeFeed.css' |
| 4 | |
| 5 | const mockItems = Array.from({ length: 20 }).map((_, i) => ({ |
| 6 | id: i, |
| 7 | title: `示例标题 ${i + 1}`, |
| 8 | author: `作者 ${i + 1}`, |
| 9 | avatar: `https://i.pravatar.cc/40?img=${i + 1}`, |
| 10 | img: `https://picsum.photos/seed/${i}/300/200`, |
| 11 | likes: Math.floor(Math.random() * 1000) |
| 12 | })) |
| 13 | |
| 14 | const categories = [ |
| 15 | '推荐','穿搭','美食','彩妆','影视', |
| 16 | '职场','情感','家居','游戏','旅行','健身' |
| 17 | ] |
| 18 | |
| 19 | export default function HomeFeed() { |
| 20 | const [activeCat, setActiveCat] = useState('推荐') |
| 21 | const items = mockItems.filter(() => true) // 可按 activeCat 过滤 |
| 22 | |
| 23 | return ( |
| 24 | <div className="home-feed"> |
| 25 | {/* 顶部分类 */} |
| 26 | <nav className="feed-tabs"> |
| 27 | {categories.map(cat => ( |
| 28 | <button |
| 29 | key={cat} |
| 30 | className={cat === activeCat ? 'tab active' : 'tab'} |
| 31 | onClick={() => setActiveCat(cat)} |
| 32 | > |
| 33 | {cat} |
| 34 | </button> |
| 35 | ))} |
| 36 | </nav> |
| 37 | |
| 38 | {/* 瀑布流卡片区 */} |
| 39 | <div className="feed-grid"> |
| 40 | {items.map(item => ( |
| 41 | <div key={item.id} className="feed-card"> |
| 42 | {/* 封面图 */} |
| 43 | <img |
| 44 | className="card-img" |
| 45 | src={item.img} |
| 46 | alt={item.title} |
| 47 | /> |
| 48 | |
| 49 | {/* 标题 */} |
| 50 | <h3 className="card-title">{item.title}</h3> |
| 51 | |
| 52 | {/* 底部作者 + 点赞 */} |
| 53 | <div className="card-footer"> |
| 54 | <div className="card-author"> |
| 55 | <img |
| 56 | className="avatar" |
| 57 | src={item.avatar} |
| 58 | alt={item.author} |
| 59 | /> |
| 60 | <span className="username">{item.author}</span> |
| 61 | </div> |
| 62 | <div className="card-likes"> |
| 63 | <ThumbsUp size={16} /> |
| 64 | <span className="likes-count">{item.likes}</span> |
| 65 | </div> |
| 66 | </div> |
| 67 | </div> |
| 68 | ))} |
| 69 | </div> |
| 70 | </div> |
| 71 | ) |
| 72 | } |