diff --git a/app/components/Carousel.tsx b/app/components/Carousel.tsx index 51c40f0..47bafc3 100755 --- a/app/components/Carousel.tsx +++ b/app/components/Carousel.tsx @@ -1,48 +1,53 @@ -// src/components/CarouselDemo.tsx import * as React from "react"; -import Autoplay from "embla-carousel-autoplay";//实现轮播图的自动播放功能 +import Autoplay from "embla-carousel-autoplay"; import { Card, CardContent } from "@/ui/card"; import { - Carousel,//主体 - CarouselContent,//内容容器 - CarouselItem,//单个轮播项 + Carousel, + CarouselContent, + CarouselItem, CarouselNext, CarouselPrevious, type CarouselApi, } from "@/ui/carousel"; +const imageUrls = [ + "/images/carousel-1.jpg", + "/images/carousel-2.jpg", + "/images/carousel-3.jpg", + "/images/carousel-4.jpg", + "/images/carousel-5.jpg", + "/images/carousel-6.jpg", +]; export function CarouselDemo() { const [api, setApi] = React.useState(); const [current, setCurrent] = React.useState(0); const [count, setCount] = React.useState(0); - - const totalSlides = 6; - + const totalSlides = imageUrls.length; React.useEffect(() => { if (!api) return; setCount(api.scrollSnapList().length); - setCurrent(api.selectedScrollSnap());//获取当前选中的轮播项的索引 + setCurrent(api.selectedScrollSnap()); + api.on("select", () => { setCurrent(api.selectedScrollSnap()); }); - }, [api]);//当api改变时,执行此函数 水平居中 循环 自动播放 回传状态 + }, [api]); return ( -
+
{Array.from({ length: totalSlides }).map((_, index) => ( @@ -75,8 +80,9 @@ export function CarouselDemo() { key={index} onClick={() => api?.scrollTo(index)} className={`h-2 w-2 rounded-full transition-colors ${ - index === current ? "bg-black" : "bg-black/50" + index === current ? "bg-white" : "bg-white/50" }`} + aria-label={`Go to slide ${index + 1}`} /> ))}
diff --git a/app/components/body/AutoCarousel.tsx b/app/components/body/AutoCarousel.tsx new file mode 100644 index 0000000..01a32b1 --- /dev/null +++ b/app/components/body/AutoCarousel.tsx @@ -0,0 +1,82 @@ +// src/components/CarouselDemo.tsx +import * as React from "react"; +import Autoplay from "embla-carousel-autoplay"; + +import { Card, CardContent } from "@/ui/card"; +import { + Carousel, + CarouselContent, + CarouselItem, + CarouselNext, + CarouselPrevious, +} from "@/ui/carousel"; + +const imageUrls = [ + "/images/carousel-1.jpg", + "/images/carousel-2.jpg", + "/images/carousel-3.jpg", + "/images/carousel-4.jpg", + "/images/carousel-5.jpg", + "/images/carousel-6.jpg", +]; + +export function AutoCarouselDemo() { + return ( +
+ {/* 相对定位 宽度100% 水平居中 隐藏溢出 */} +
+
+ {/* 绝对定位 上下与父对齐 水平左对齐 背景渐变从左 从黑70%到透明 */} + + + {imageUrls.map((src, index) => ( + + {/* 基宽 中屏 大屏 防止收缩 相对定位 + 内边距 过渡500ms 鼠标悬停时放大1.05倍 鼠标手型 + 隐藏溢出 移除边框 中等阴影 + 弹性布局 正方形 垂直居中 水平居中 内边距0 相对 + */} +
+ + + {`Slide + + +
+
+ ))} +
+ + {/* 左右箭头控制 */} + + +
+
+ ); +} \ No newline at end of file diff --git a/app/components/body/FireNews/FireNewsList.tsx b/app/components/body/FireNews/FireNewsList.tsx new file mode 100644 index 0000000..77601c8 --- /dev/null +++ b/app/components/body/FireNews/FireNewsList.tsx @@ -0,0 +1,63 @@ +import React from 'react'; + +interface NewsItem { + content: string; +} + +export function FireNewsList() { + const newsItems: NewsItem[] = [ + { + content: "记者从16日召开的海南省政府新闻发布会上获悉,2018年,海南旅游总收入达1,262万人次,支出达399.7亿元...", + }, + { + content: "记者从16日召开的海南省政府新闻发布会上获悉,2018年,海南旅游总收入达1,262万人次,支出达399.7亿元...", + }, + { + content: "记者从16日召开的海南省政府新闻发布会上获悉,2018年,海南旅游总收入达1,262万人次,支出达399.7亿元...", + }, + { + content: "记者从16日召开的海南省政府新闻发布会上获悉,2018年,海南旅游总收入达1,262万人次,支出达399.7亿元...", + }, + { + content: "记者从16日召开的海南省政府新闻发布会上获悉,2018年,海南旅游总收入达1,262万人次,支出达399.7亿元...", + }, + { + content: "记者从16日召开的海南省政府新闻发布会上获悉,2018年,海南旅游总收入达1,262万人次,支出达399.7亿元...", + }, + ]; + + return ( +
+ {/* 标题栏 */} +
+

烽火要闻

+ + 查看更多 {'>'} + +
+ + {/* 新闻列表 */} +
+ {newsItems.map((item, index) => ( +
+ + {/* 内容部分 */} +
+

+ {item.content} + + [MORE] + +

+
+
+ ))} +
+
+ ); +}; diff --git a/app/components/body/FireNews/fhjt.tsx b/app/components/body/FireNews/fhjt.tsx new file mode 100644 index 0000000..6ab127b --- /dev/null +++ b/app/components/body/FireNews/fhjt.tsx @@ -0,0 +1,39 @@ + +import { CarouselDemo } from "@/components/Carousel"; +import {FireNewsList} from "./FireNewsList"; + + +export function FhjtPage() { + return( +
+ {/* 轮播背景图 */} +
+ +
+ +
+ {/* 标题部分 */} +
+

烽火讲堂

+ {/* 蓝色装饰线 */} +
+
+ {/* 列表 */} +
+ +
+ 一等奖 +
+ +
+ 二等奖 +
+ +
+ 三等奖 +
+
+
+
+ ) +} \ No newline at end of file diff --git a/app/components/body/FireNews/fhrx.tsx b/app/components/body/FireNews/fhrx.tsx new file mode 100644 index 0000000..a9f9f4f --- /dev/null +++ b/app/components/body/FireNews/fhrx.tsx @@ -0,0 +1,39 @@ + +import { CarouselDemo } from "@/components/Carousel"; +import {FireNewsList} from "./FireNewsList"; + + +export function FhrxPage() { + return( +
+ {/* 轮播背景图 */} +
+ +
+ +
+ {/* 标题部分 */} +
+

烽火热线

+ {/* 蓝色装饰线 */} +
+
+ {/* 列表 */} +
+ +
+ 信箱 +
+ +
+ 问答 +
+ +
+ 心灵 +
+
+
+
+ ) +} \ No newline at end of file diff --git a/app/components/body/FireNews/fhws.tsx b/app/components/body/FireNews/fhws.tsx new file mode 100644 index 0000000..14f0832 --- /dev/null +++ b/app/components/body/FireNews/fhws.tsx @@ -0,0 +1,38 @@ + +import { CarouselDemo } from "@/components/Carousel"; +import {FireNewsList} from "./FireNewsList"; + + +export function FhwsPage() { + return( +
+
+ {/* 标题部分 */} +
+

烽火微视

+ {/* 蓝色装饰线 */} +
+
+ {/* 列表 */} +
+ +
+ 一 +
+ +
+ 二 +
+ +
+ 三 +
+
+
+ {/* 轮播背景图 */} +
+ +
+
+ ) +} \ No newline at end of file diff --git a/app/components/body/FireNews/fhyw.tsx b/app/components/body/FireNews/fhyw.tsx new file mode 100644 index 0000000..a160ee1 --- /dev/null +++ b/app/components/body/FireNews/fhyw.tsx @@ -0,0 +1,21 @@ + + +import { CarouselDemo } from "@/components/Carousel"; +import {FireNewsList} from "./FireNewsList"; + + +export function FhywPage() { + return( +
+ {/* 轮播背景图 */} +
+ +
+ + {/* 固定的烽火要闻 */} +
+ +
+
+ ) +} \ No newline at end of file diff --git a/app/components/news/body/FireNews/fhjt.tsx b/app/components/news/body/FireNews/fhjt.tsx index 0a2c55a..59cac6c 100644 --- a/app/components/news/body/FireNews/fhjt.tsx +++ b/app/components/news/body/FireNews/fhjt.tsx @@ -4,7 +4,7 @@ import {FireNewsList} from "./FireNewsList"; export function FhjtPage() { return( -
+
{/* 轮播背景图 */}
diff --git a/app/components/news/body/FireNews/fhrx.tsx b/app/components/news/body/FireNews/fhrx.tsx index b9e6639..4f4070e 100644 --- a/app/components/news/body/FireNews/fhrx.tsx +++ b/app/components/news/body/FireNews/fhrx.tsx @@ -4,11 +4,14 @@ import {FireNewsList} from "./FireNewsList"; export function FhrxPage() { return( -
- {/* 轮播背景图 */} -
- -
+
+
+ {/* 轮播背景图 */} +
+ +
+
+
{/* 标题部分 */} diff --git a/app/components/news/body/FireNews/fhws.tsx b/app/components/news/body/FireNews/fhws.tsx index bf4bba0..0c3be2c 100644 --- a/app/components/news/body/FireNews/fhws.tsx +++ b/app/components/news/body/FireNews/fhws.tsx @@ -4,7 +4,7 @@ import {FireNewsList} from "./FireNewsList"; export function FhwsPage() { return( -
+
{/* 标题部分 */}
@@ -28,10 +28,13 @@ export function FhwsPage() {
- {/* 轮播背景图 */} -
- -
+
+ {/* 轮播背景图 */} +
+ +
+
+
) } \ No newline at end of file diff --git a/app/components/news/body/ImageGridSection.tsx b/app/components/news/body/ImageGridSection.tsx index c71f167..8b92687 100644 --- a/app/components/news/body/ImageGridSection.tsx +++ b/app/components/news/body/ImageGridSection.tsx @@ -1,109 +1,102 @@ -import { CarouselDemo } from "@/components/Carousel"; -const ImageGridSection = () => { - - const elements = [ - "/images/carousel-1.jpg", - , - "/images/carousel-2.jpg", - "/images/carousel-3.jpg" - ]; - {/* 最外 左右两列间 内边 内容最大宽 水平居 微软雅黑 - 2 列+ 2 行 格子间距 固定宽高 - */} +import { CarouselDemo } from '@/components/Carousel'; +import React from 'react'; - const listItems = [ - '新闻标题一:重要政策发布', - '新闻标题二:经济数据稳步回升', - '新闻标题三:科技创新成果显著', - '新闻标题四:民生工程持续推进', - '新闻标题五:国际交流合作深化' +const LearnPage = () => { + const newsList = [ + '中华人民共和国监察法', + '2024年国办印发意见部门工作人员党听全国两...', + '十四届全国人大二次会议闭幕贺词', + '7天人代会:"小片段"折射民主"大全景"', + '全国政协十四届二次会议共收到提案5800多件', + '两会观察丨从两会八个高频词看中国', + '两会"清单"上新这些民生发展温度', + '"选择中国"——世界从中国两会读出心动机号', + '中国经济信心说丨新玛合信心从哪里来', ]; + return ( -
- - {/* 左侧:3张图片 + 1个轮播图 2x2 网格 圆 防溢 拉伸填满 - 保持比例填充 消除底部空白*/} -
+
+ {/* 顶部 Logo */} +
+

学习进行时

+
- {elements.map((element, index) => ( -
- {typeof element === 'string' ? ( + {/* 主内容区:固定高度,紧凑布局 */} +
+ {/* 左侧图片区 */} +
+
+ {/* 上左:第一张图 */} +
{`图片 - ) : ( - element // 占据剩余空间 最小宽度;与左侧高度对齐;垂直布局;内容在垂直方向均匀分布 - // 背景色、圆角、阴影、内边距 防撑大 - )} +
+ + {/* 上右:轮播图 */} +
+ +
+ + {/* 下三图 */} + {[3, 4, 5].map((i) => ( +
+ {`Image +
+ ))}
- ))} -
-
-
    - {listItems.map((item, index) => ( -
  • - - {item} -
  • - ))} -
-
+
+ + + {/* 右侧新闻列表 */} +
+
    + {newsList.map((item, index) => ( +
  • + + {item} +
  • + ))} +
+
+
+
+
+
+ {/* 左边容器内容 */} +
+

+ 习近平新时代中国特色社会 +
+ 主义思想专题数据库 +

+
+
+
+
+ {/* 右边容器内容 */} +
+

习近平著作选读

+
+
+
); }; -export default ImageGridSection; \ No newline at end of file + +export default LearnPage; \ No newline at end of file diff --git a/app/components/news/header/TopNav.tsx b/app/components/news/header/TopNav.tsx index f5dfd1f..b40a7ad 100644 --- a/app/components/news/header/TopNav.tsx +++ b/app/components/news/header/TopNav.tsx @@ -1,16 +1,11 @@ import { Search } from 'lucide-react'; -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; interface MenuItem { label: string; key: string; } -// 定义 TopNavProps 接口,描述组件的 props 类型 -// menuItems? 菜单项数组 -// activeKey: 当前激活的菜单项 -// onSearch: 搜索回调函数 -// onItemClick: 菜单点击回调函数 interface TopNavProps { menuItems?: MenuItem[]; activeKey?: string; @@ -18,11 +13,6 @@ interface TopNavProps { onItemClick?: (key: string) => void; } -//定义 TopNav 组件,类型为 React 函数组件,接收 TopNavProps 类型的 props -//解构并设置 menuItems 默认值,如果父组件没有传入则使用默认的6个菜单项 -// activeKey: 当前激活的菜单项 -// onSearch: 搜索回调函数 -// onItemClick: 菜单点击回调函数 export function TopNav({ menuItems = [ { label: '首页', key: 'home' }, @@ -32,35 +22,37 @@ export function TopNav({ { label: '联系热线', key: 'hotline' }, { label: '综合服务', key: 'service' }, ], - activeKey: externalActiveKey, // 从外部传入的 activeKey + activeKey: externalActiveKey, onSearch, onItemClick, }: TopNavProps){ - // 使用外部传入的 activeKey,如果没有则使用内部状态 - // 创建内部状态 internalActiveKey,默认值为 'home',用于内部管理激活状态 const [internalActiveKey, setInternalActiveKey] = useState('home'); - // 如果外部传入了 activeKey 则使用外部的,否则使用内部状态(支持受控和非受控模式) const currentActiveKey = externalActiveKey !== undefined ? externalActiveKey : internalActiveKey; - // 创建搜索关键词状态,初始为空字符串 const [searchKeyword, setSearchKeyword] = useState(''); - // 处理搜索提交事件, 阻止默认表单提交行为,调用搜索回调函数 + const [activeIndex, setActiveIndex] = useState(0); + const [prevIndex, setPrevIndex] = useState(0); + + // 监听激活项变化,更新索引和动画方向 + useEffect(() => { + const currentIndex = menuItems.findIndex(item => item.key === currentActiveKey); + setPrevIndex(activeIndex); + setActiveIndex(currentIndex); + }, [currentActiveKey, menuItems, activeIndex]); + const handleSearchSubmit = (e: React.FormEvent) => { e.preventDefault(); - onSearch?.(searchKeyword); // .? 可选链操作符,确保 onSearch 存在时才调用 + onSearch?.(searchKeyword); }; - // 定义菜单项点击处理函数,如果外部没有传入 activeKey 则更新内部状态,调用点击回调函数 const handleItemClick = (item: MenuItem) => { - // 更新内部状态(如果使用内部状态) if (externalActiveKey === undefined) { setInternalActiveKey(item.key); } - // 调用外部回调函数 - onItemClick?.(item.key); // .? 可选链操作符,确保 onItemClick 存在时才调用 + onItemClick?.(item.key); }; return ( -
+
{/* 搜索框与导航菜单组合 */}
{/* 搜索框 */} @@ -71,26 +63,42 @@ export function TopNav({ value={searchKeyword} onChange={(e) => setSearchKeyword(e.target.value)} placeholder="搜索..." - className="pl-10 pr-4 py-2 text-sm rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent w-64 transition-all duration-200 hover:shadow-sm" + className="pl-10 pr-4 py-2 text-sm border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent w-64 transition-all duration-200 hover:shadow-sm" />
- + {/* 导航菜单 */} -
    - {menuItems.map((item) => { - const isActive = currentActiveKey === item.key; // 判断当前项是否激活 +
      + {/* 滑动背景层 */} +
      + + {menuItems.map((item, index) => { + const isActive = currentActiveKey === item.key; return ( -
    • +
); -}; +}; \ No newline at end of file diff --git a/app/routes/news.tsx b/app/routes/news.tsx index 0fac963..6daf3fb 100755 --- a/app/routes/news.tsx +++ b/app/routes/news.tsx @@ -12,6 +12,7 @@ import { FhjtPage } from "@/components/news/body/FireNews/fhjt"; import { FhwsPage } from "@/components/news/body/FireNews/fhws"; import { FhrxPage } from "@/components/news/body/FireNews/fhrx"; import { AutoCarouselDemo } from "@/components/AutoCarousel"; + export function meta( ) { return [ { title: "New React Router App" }, diff --git a/public/images/book1.png b/public/images/book1.png new file mode 100644 index 0000000..c74ffd8 Binary files /dev/null and b/public/images/book1.png differ diff --git a/public/images/book2.png b/public/images/book2.png new file mode 100644 index 0000000..4e6ea37 Binary files /dev/null and b/public/images/book2.png differ