"use client" import { useRef, useState, useEffect } from "react" import Image from "next/image" import Link from "next/link" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { ChevronLeft, ChevronRight, Info } from "lucide-react" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" import { robots } from "@/lib/robot-data" export default function RobotsShowcase() { const scrollContainerRef = useRef(null) const [activeIndex, setActiveIndex] = useState(0) // 创建一个循环数组,用于无限滚动 const displayRobots = [...robots] const scroll = (direction: "left" | "right") => { if (scrollContainerRef.current) { const { current: container } = scrollContainerRef const cardWidth = container.querySelector(".robot-card")?.clientWidth || 350 // 更新活跃索引 if (direction === "left") { setActiveIndex((prev) => (prev === 0 ? robots.length - 1 : prev - 1)) } else { setActiveIndex((prev) => (prev === robots.length - 1 ? 0 : prev + 1)) } // 滚动到新的活跃卡片 const newScrollPosition = activeIndex * (cardWidth + 24) // 24 是 gap-6 container.scrollTo({ left: newScrollPosition, behavior: "smooth", }) } } // 使用 useEffect 监听活跃索引变化,滚动到对应位置 useEffect(() => { if (scrollContainerRef.current) { const cardWidth = scrollContainerRef.current.querySelector(".robot-card")?.clientWidth || 350 const newScrollPosition = activeIndex * (cardWidth + 24) // 24 是 gap-6 scrollContainerRef.current.scrollTo({ left: newScrollPosition, behavior: "smooth", }) } }, [activeIndex]) return (

机器人

ROBOTS

探索我们为 RoboMaster 竞赛设计的尖端机器人,每款机器人都针对赛场上的特定战术角色而设计。

{displayRobots.map((robot, index) => (
{robot.displayName}
{robot.category}

{`0${index + 1}/0${robots.length}`}

{robot.displayName}

技术参数:

    {robot.simpleSpecs.map((spec, specIndex) => (
  • {spec}
  • ))}

{robot.shortDescription}

))}
{/* 添加索引指示器 */}
{robots.map((_, index) => (
) }