import React, { useState, useEffect } from "react"; import { useNavigate } from 'react-router-dom'; import { getGvgTeamList, GvgTeam, GvgTeamQueryParams } from '../api/gvg'; const Lineup: React.FC = () => { const [selectedDifficulty, setSelectedDifficulty] = useState("All"); const [selectedTags, setSelectedTags] = useState([]); const [searchTerm, setSearchTerm] = useState(""); const [lineups, setLineups] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [pageNum, setPageNum] = useState(1); const [pageSize, setPageSize] = useState(10); const [total, setTotal] = useState(0); const navigate = useNavigate(); // Fetch data from API useEffect(() => { const fetchLineups = async () => { setLoading(true); try { const params: GvgTeamQueryParams = { pageNum, pageSize, // Add other filters as needed }; const response = await getGvgTeamList(params); setLineups(response.list); setTotal(response.total); setError(null); } catch (err) { console.error('Failed to fetch lineups:', err); setError('获取阵容数据失败,请稍后再试'); // Use mock data as fallback setLineups(mockLineups); } finally { setLoading(false); } }; fetchLineups(); }, [pageNum, pageSize]); // Mock data for fallback const mockLineups: GvgTeam[] = [ { id: 1, defenseHeroes: ["暗影刺客", "元素法师", "圣骑士", "治疗师"], attackHeroes: ["暗影刺客", "元素法师", "圣骑士", "治疗师"], equipmentInfo: "攻击套 + 暴击套", artifacts: "攻击力 + 暴击率", battleStrategy: "以高爆发伤害为主的阵容,适合快速结束战斗", prerequisites: "需要高星级角色和优质装备", importantNotes: "注意控制技能释放时机", createTime: "2023-01-01", updateTime: "2023-01-01" }, { id: 2, defenseHeroes: ["龙骑士", "冰霜法师", "守护者", "圣光牧师"], attackHeroes: ["龙骑士", "冰霜法师", "守护者", "圣光牧师"], equipmentInfo: "生命套 + 防御套", artifacts: "生命值 + 防御力", battleStrategy: "以持续输出和防御为主的阵容,适合持久战", prerequisites: "需要高生命值和防御力的角色", importantNotes: "注意保持治疗技能的持续释放", createTime: "2023-01-02", updateTime: "2023-01-02" } ]; const difficulties = ["简单", "中等", "困难"]; const availableTags = ["PVP", "PVE", "爆发", "控制", "持续", "防守", "快速"]; const filteredLineups = lineups.filter(lineup => { const matchesSearch = lineup.battleStrategy.toLowerCase().includes(searchTerm.toLowerCase()) || lineup.defenseHeroes.some((hero: string) => hero.toLowerCase().includes(searchTerm.toLowerCase())) || lineup.attackHeroes.some((hero: string) => hero.toLowerCase().includes(searchTerm.toLowerCase())); // Since we don't have difficulty in the API data, we'll use a simple filter const matchesDifficulty = selectedDifficulty === "All" || (selectedDifficulty === "简单" && lineup.id % 3 === 1) || (selectedDifficulty === "中等" && lineup.id % 3 === 2) || (selectedDifficulty === "困难" && lineup.id % 3 === 0); // Since we don't have tags in the API data, we'll use a simple filter const matchesTags = selectedTags.length === 0 || selectedTags.some(tag => lineup.battleStrategy.toLowerCase().includes(tag.toLowerCase())); return matchesSearch && matchesDifficulty && matchesTags; }); const handleLineupClick = (id: number) => { navigate(`/lineup/${id}`); }; const handlePageChange = (newPage: number) => { setPageNum(newPage); }; const handlePageSizeChange = (newSize: number) => { setPageSize(newSize); setPageNum(1); // Reset to first page when changing page size }; return (
{/* 背景装饰 */}

对战阵容推荐

{/* 搜索和筛选组件 */}
setSearchTerm(e.target.value)} />
{/* 难度筛选 */}
{difficulties.map((difficulty) => ( ))}
{/* 标签筛选 */}
{availableTags.map((tag) => ( ))}
{/* 加载状态 */} {loading && (
)} {/* 错误提示 */} {error && (
{error}
)} {/* 阵容列表 - 列表格式 */} {!loading && (
{filteredLineups.map((lineup) => (
handleLineupClick(lineup.id)} >

阵容 #{lineup.id}

{lineup.battleStrategy}

创建时间: {lineup.createTime}
{/* 防守阵容 */}

防守阵容

{lineup.defenseHeroes.map((hero: string, index: number) => ( {hero} ))}
{/* 进攻阵容 */}

进攻阵容

{lineup.attackHeroes.map((hero: string, index: number) => ( {hero} ))}
{/* 装备信息 */}

装备信息

{lineup.equipmentInfo}

{/* 神器信息 */}

神器信息

{lineup.artifacts}

{/* 前置条件 */}

前置条件

{lineup.prerequisites}

{/* 重要提示 */}

重要提示

{lineup.importantNotes}

))}
)} {/* 分页控件 */} {!loading && total > 0 && (
{Array.from({ length: Math.ceil(total / pageSize) }, (_, i) => i + 1) .filter(page => page === 1 || page === Math.ceil(total / pageSize) || (page >= pageNum - 1 && page <= pageNum + 1) ) .map((page, index, array) => { // Add ellipsis if there's a gap if (index > 0 && page - array[index - 1] > 1) { return ( ... ); } return ( ); })}
每页显示:
)}
); }; export default Lineup;