Compare commits
4 Commits
e31bbdf78e
...
3b6d64df92
| Author | SHA1 | Date |
|---|---|---|
|
|
3b6d64df92 | |
|
|
7fbeca06bb | |
|
|
e73c01dc48 | |
|
|
42a0d3a16c |
|
|
@ -2,21 +2,22 @@ import React from 'react';
|
|||
import { mockNewsData } from './NewsData'; // 导入新闻数据
|
||||
|
||||
interface NewsProps {
|
||||
title?: string;
|
||||
description?: string;
|
||||
time?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
time?: string;
|
||||
type?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
const NewsItem: React.FC<NewsProps> = ({ title = '', time = '', url = '' }) => {
|
||||
return (
|
||||
<div>
|
||||
<div onClick={() => url && window.open(url)}
|
||||
className="flex items-center justify-between hover:text-blue-500
|
||||
cursor-pointer w-96">
|
||||
<h3 >{title}</h3>
|
||||
<p >{time}</p>
|
||||
<div className="mb-4">
|
||||
<div
|
||||
onClick={() => url && window.open(url)}
|
||||
className="flex items-center justify-between hover:text-blue-600 cursor-pointer transition duration-300 ease-in-out"
|
||||
>
|
||||
<h3 className="text-lg font-semibold text-gray-800">{title}</h3>
|
||||
<p className="text-sm text-gray-500">{time}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
@ -25,16 +26,40 @@ const NewsItem: React.FC<NewsProps> = ({ title = '', time = '', url = '' }) => {
|
|||
// 使用新闻数据渲染列表
|
||||
const NewsList: React.FC = () => {
|
||||
return (
|
||||
<div>
|
||||
<ul className="flex flex-col justify-center items-center h-screen">
|
||||
{mockNewsData.map((news) => (
|
||||
<NewsItem title={news.title} time={news.time} url={news.url} />
|
||||
))}
|
||||
</ul>
|
||||
<div className="bg-gray-100 p-6 rounded-lg shadow-md">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
{/* 科技新闻 */}
|
||||
<div className="bg-white p-6 rounded-lg shadow-sm">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<p className="text-xl font-bold text-gray-900">科技新闻</p>
|
||||
<button className="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-md transition duration-300 ease-in-out">
|
||||
更多科技新闻
|
||||
</button>
|
||||
</div>
|
||||
<ul className="space-y-4">
|
||||
{mockNewsData.map((news, index) => (
|
||||
<NewsItem key={index} title={news.title} time={news.time} url={news.url} />
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* 社会新闻 */}
|
||||
<div className="bg-white p-6 rounded-lg shadow-sm">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<p className="text-xl font-bold text-gray-900">社会新闻</p>
|
||||
<button className="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-md transition duration-300 ease-in-out">
|
||||
更多社会新闻
|
||||
</button>
|
||||
</div>
|
||||
<ul className="space-y-4">
|
||||
{mockNewsData.map((news, index) => (
|
||||
<NewsItem key={index} title={news.title} time={news.time} url={news.url} />
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
export default NewsList;
|
||||
|
|
@ -31,7 +31,7 @@ export function CarouselDemo() {
|
|||
}, [api]);
|
||||
|
||||
return (
|
||||
<div className="relative w-full max-w-4xl mx-auto">
|
||||
<div className="relative w-full max-w-xs">
|
||||
<Carousel
|
||||
opts={{
|
||||
loop: true,
|
||||
|
|
@ -43,24 +43,15 @@ export function CarouselDemo() {
|
|||
}),
|
||||
]}
|
||||
setApi={setApi}
|
||||
className="w-full"
|
||||
>
|
||||
<CarouselContent className="h-full w-full">
|
||||
<CarouselContent>
|
||||
{Array.from({ length: totalSlides }).map((_, index) => (
|
||||
<CarouselItem key={index} className="w-full h-full">
|
||||
<CarouselItem key={index}>
|
||||
<div className="p-1">
|
||||
<Card>
|
||||
<CardContent className="flex aspect-square items-center justify-center ">
|
||||
<div
|
||||
className="w-full h-full relative"
|
||||
style={{
|
||||
backgroundImage: "url('/app/images/header.png')",
|
||||
backgroundSize: '100% 100%',
|
||||
}}
|
||||
>
|
||||
<div className="absolute top-1 right-1 h-full bg-black">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<CardContent className="flex aspect-square items-center justify-center p-6">
|
||||
<span className="text-4xl font-semibold">{index + 1}</span>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import { CarouselDemo } from "@/components/untils/Carousel";
|
||||
import type { Route } from "./+types/news";
|
||||
import { Header } from "@/components/header/Header";
|
||||
import { TopNav } from "@/components/header/TopNav";
|
||||
import {Header} from "@/components/header/Header";
|
||||
import {TopNav} from "@/components/header/TopNav";
|
||||
import NewsList from "@/components/list/NewsList";
|
||||
|
||||
|
||||
export function meta( ) {
|
||||
return [
|
||||
{ title: "New React Router App" },
|
||||
|
|
@ -18,7 +16,7 @@ export default function Home() {
|
|||
<Header />
|
||||
<TopNav />
|
||||
<CarouselDemo />
|
||||
<NewsList/>
|
||||
<NewsList />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue