67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import { mockNewsData } from './NewsData'; // 导入新闻数据
|
|
|
|
interface NewsProps {
|
|
title?: string;
|
|
time?: string;
|
|
url?: string;
|
|
}
|
|
|
|
const NewsItem: React.FC<NewsProps> = ({ title = '', time = '', url = '' }) => {
|
|
return (
|
|
<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>
|
|
);
|
|
};
|
|
|
|
// 使用新闻数据渲染列表
|
|
const NewsList: React.FC = () => {
|
|
// 按类型过滤新闻
|
|
const techNews = mockNewsData.filter((news) => news.type === "科技");
|
|
const educationNews = mockNewsData.filter((news) => news.type === "教育");
|
|
|
|
return (
|
|
<div className="bg-gray-100 p-6 rounded-lg shadow-md w-4/5 mx-auto">
|
|
<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">
|
|
{techNews.map((news) => (
|
|
<NewsItem key={news.id} 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">
|
|
{educationNews.map((news) => (
|
|
<NewsItem key={news.id} title={news.title} time={news.time} url={news.url} />
|
|
))}
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default NewsList; |