2023-10-27 17:29:50 +08:00
|
|
|
import Image from "next/image";
|
2023-11-06 17:27:50 +08:00
|
|
|
import trumpetIcon from "@/app/_assets/trumpet-icon.png";
|
|
|
|
import styles from "@/app/_assets/page.module.css";
|
2023-10-27 17:29:50 +08:00
|
|
|
import Link from "next/link";
|
2023-11-06 17:27:50 +08:00
|
|
|
import request from "@/app/_lib/request";
|
|
|
|
import { listArticles } from "@/app/_services/articles";
|
2023-11-01 17:27:06 +08:00
|
|
|
import dayjs from "dayjs";
|
2023-10-27 17:29:50 +08:00
|
|
|
|
|
|
|
interface ArticleLink {
|
|
|
|
title: string;
|
|
|
|
date?: string;
|
|
|
|
href: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ArticleBlock = async ({
|
|
|
|
title,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
category,
|
|
|
|
linkPrefix,
|
2023-11-01 17:27:06 +08:00
|
|
|
showDate,
|
2023-10-27 17:29:50 +08:00
|
|
|
}: {
|
|
|
|
title: string;
|
|
|
|
height?: number | string;
|
|
|
|
width?: number | string;
|
|
|
|
category: string;
|
|
|
|
linkPrefix: string;
|
2023-11-01 17:27:06 +08:00
|
|
|
showDate?: boolean;
|
2023-10-27 17:29:50 +08:00
|
|
|
}) => {
|
|
|
|
const data = await listArticles({ cid: category });
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
}}
|
2023-11-01 17:27:06 +08:00
|
|
|
className={"flex flex-col overflow-hidden"}
|
2023-10-27 17:29:50 +08:00
|
|
|
>
|
|
|
|
<div
|
2023-11-03 17:25:10 +08:00
|
|
|
className={`title-bar flex items-center px-2 font-bold text-white ${styles.articleBlockTitleBar} relative`}
|
2023-10-27 17:29:50 +08:00
|
|
|
>
|
|
|
|
<Image width={30} height={30} src={trumpetIcon} alt={"trumpet icon"} />
|
|
|
|
<span className={"ml-2 text-[14px]"}>{title}</span>
|
2023-11-01 17:27:06 +08:00
|
|
|
<Link
|
2023-11-03 17:25:10 +08:00
|
|
|
className={"absolute right-3 text-xs text-white"}
|
2023-11-01 17:27:06 +08:00
|
|
|
href={`${linkPrefix}/pages/1`}
|
|
|
|
>
|
|
|
|
更多+
|
|
|
|
</Link>
|
2023-10-27 17:29:50 +08:00
|
|
|
</div>
|
2023-11-03 17:25:10 +08:00
|
|
|
<div className={`${styles.articlesList} flex-1 bg-[#e1f1fd]`}>
|
2023-10-27 17:29:50 +08:00
|
|
|
<ul>
|
2023-11-01 22:25:06 +08:00
|
|
|
{data.lists?.map((article) => (
|
2023-11-01 17:27:06 +08:00
|
|
|
<li className={"h-8"} key={article.id}>
|
2023-10-27 17:29:50 +08:00
|
|
|
<Link
|
2023-11-01 17:27:06 +08:00
|
|
|
className={
|
2023-11-03 17:25:10 +08:00
|
|
|
"flex h-full w-full items-center justify-between px-1 text-xs"
|
2023-11-01 17:27:06 +08:00
|
|
|
}
|
2023-10-27 17:29:50 +08:00
|
|
|
href={`${linkPrefix}/${article.id}`}
|
|
|
|
>
|
2023-11-01 17:27:06 +08:00
|
|
|
<span className={"flex-1 truncate"}>{article.title}</span>
|
|
|
|
{showDate && (
|
|
|
|
<span>{dayjs(article.createTime).format("YYYY-MM-DD")}</span>
|
|
|
|
)}
|
2023-10-27 17:29:50 +08:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ArticleBlock;
|