From a7b5e4d5f1c13a4d3744036c504cac9b6f930752 Mon Sep 17 00:00:00 2001 From: qiuchenfan <2035024011@qq.com> Date: Tue, 18 Nov 2025 15:11:13 +0800 Subject: [PATCH] 11181511 --- app/components/untils/Carousel.tsx | 90 +++++++++++++++++++++++------- app/routes/news.tsx | 4 +- package.json | 1 + pnpm-lock.yaml | 12 ++++ 4 files changed, 84 insertions(+), 23 deletions(-) diff --git a/app/components/untils/Carousel.tsx b/app/components/untils/Carousel.tsx index 8ddf9f9..fabc5f2 100755 --- a/app/components/untils/Carousel.tsx +++ b/app/components/untils/Carousel.tsx @@ -1,32 +1,80 @@ -import * as React from "react" +// src/components/CarouselDemo.tsx +import * as React from "react"; +import Autoplay from "embla-carousel-autoplay"; -import { Card, CardContent } from "@/components/ui/card" +import { Card, CardContent } from "@/components/ui/card"; import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, -} from "@/components/ui/carousel" + type CarouselApi, +} from "@/components/ui/carousel"; export function CarouselDemo() { + const [api, setApi] = React.useState(); + const [current, setCurrent] = React.useState(0); + const [count, setCount] = React.useState(0); + + const totalSlides = 6; + + React.useEffect(() => { + if (!api) return; + + setCount(api.scrollSnapList().length); + setCurrent(api.selectedScrollSnap()); + + api.on("select", () => { + setCurrent(api.selectedScrollSnap()); + }); + }, [api]); + return ( - - - {Array.from({ length: 5 }).map((_, index) => ( - -
- - - {index + 1} - - -
-
+
+ + + {Array.from({ length: totalSlides }).map((_, index) => ( + +
+ + + {index + 1} + + +
+
+ ))} +
+ + +
+ + {/* 分页指示器 - 右下角 */} +
+ {Array.from({ length: count }).map((_, index) => ( +
+
+ ); +} \ No newline at end of file diff --git a/app/routes/news.tsx b/app/routes/news.tsx index 6820291..e0acc43 100755 --- a/app/routes/news.tsx +++ b/app/routes/news.tsx @@ -1,4 +1,4 @@ -import { Carousel } from "@/components/ui/carousel"; +import { CarouselDemo } from "@/components/untils/Carousel"; import type { Route } from "./+types/news"; @@ -10,5 +10,5 @@ export function meta({}: Route.MetaArgs) { } export default function Home() { - return ; + return ; } diff --git a/package.json b/package.json index 1daccf6..a6398ff 100755 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "dayjs": "^1.11.19", + "embla-carousel-autoplay": "^8.6.0", "embla-carousel-react": "^8.6.0", "immer": "^10.2.0", "isbot": "^5.1.31", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee43459..8313dcb 100755 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,6 +41,9 @@ importers: dayjs: specifier: ^1.11.19 version: 1.11.19 + embla-carousel-autoplay: + specifier: ^8.6.0 + version: 8.6.0(embla-carousel@8.6.0) embla-carousel-react: specifier: ^8.6.0 version: 8.6.0(react@19.2.0) @@ -1475,6 +1478,11 @@ packages: electron-to-chromium@1.5.255: resolution: {integrity: sha512-Z9oIp4HrFF/cZkDPMpz2XSuVpc1THDpT4dlmATFlJUIBVCy9Vap5/rIXsASP1CscBacBqhabwh8vLctqBwEerQ==} + embla-carousel-autoplay@8.6.0: + resolution: {integrity: sha512-OBu5G3nwaSXkZCo1A6LTaFMZ8EpkYbwIaH+bPqdBnDGQ2fh4+NbzjXjs2SktoPNKCtflfVMc75njaDHOYXcrsA==} + peerDependencies: + embla-carousel: 8.6.0 + embla-carousel-react@8.6.0: resolution: {integrity: sha512-0/PjqU7geVmo6F734pmPqpyHqiM99olvyecY7zdweCw+6tKEXnrE90pBiBbMMU8s5tICemzpQ3hi5EpxzGW+JA==} peerDependencies: @@ -4203,6 +4211,10 @@ snapshots: electron-to-chromium@1.5.255: {} + embla-carousel-autoplay@8.6.0(embla-carousel@8.6.0): + dependencies: + embla-carousel: 8.6.0 + embla-carousel-react@8.6.0(react@19.2.0): dependencies: embla-carousel: 8.6.0