diff --git a/src/app/article/page.tsx b/src/app/article/page.tsx new file mode 100644 index 0000000..6e6e0f9 --- /dev/null +++ b/src/app/article/page.tsx @@ -0,0 +1,58 @@ +/** + * 文章页面 + */ +'use client'; + +import { useState, useEffect, useMemo } from 'react'; + +import Image from 'next/image'; + +// 获取文章信息 +async function getArticleInfo(journalId: string) { + // const res = await fetch(`http://api.indie.cn:9012/luoo-music/article/${journalId}`); TODO: + const res = await fetch(`http://39.103.180.196:9012/luoo-music/article/${journalId}`); + return res.json(); +} + +export default function Article() { + const [articleInfo, setArticleInfo] = useState({}); + + useEffect(() => { + const { searchParams } = new URL(window.location.href); + getArticleInfo((searchParams as any)?.get('id')).then((res) => { + setArticleInfo(res?.data || {}); + }); + }, []); + + const displayDate = useMemo(() => { + if (!articleInfo?.date) return ''; + const date = new Date(articleInfo?.date); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}.${month}.${day}`; + }, [articleInfo?.date]); + + return ( +
+

{articleInfo?.title}

+ {(articleInfo?.userName || displayDate) && ( +

+ {articleInfo?.userName} + {displayDate} +

+ )} + {articleInfo?.image && ( +
+ cover +
+ )} + {articleInfo?.content && ( +

+ )} +

+ ); +}