From 064f67a2b95ec87fdb957a6c93248ee4e90884ff Mon Sep 17 00:00:00 2001 From: tone Date: Fri, 19 Dec 2025 21:18:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=8D=9A?= =?UTF-8?q?=E5=AE=A2=E5=88=97=E8=A1=A8=E8=AF=AD=E4=B9=89=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/(with-header-footer)/blog/page.tsx | 60 +++++++++++++------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/apps/frontend/app/(with-header-footer)/blog/page.tsx b/apps/frontend/app/(with-header-footer)/blog/page.tsx index 979f739..72de2ec 100644 --- a/apps/frontend/app/(with-header-footer)/blog/page.tsx +++ b/apps/frontend/app/(with-header-footer)/blog/page.tsx @@ -7,22 +7,33 @@ import { import { AlertCircle } from "lucide-react"; import { base62 } from "@/lib/utils"; import { BlogAPI } from "@/lib/api/server"; +import { handleAPIError } from "@/lib/api/common"; + +const formatNumber = (num: number): string => { + if (num >= 1_000_000) { + return (num / 1_000_000).toFixed(1) + 'M'; + } + if (num >= 1_000) { + return (num / 1_000).toFixed(1) + 'K'; + } + return num.toString(); +}; + +const getBlogDetailUrl = (id: string): string => { + const cleanId = id.replace(/-/g, ''); + const encoded = base62.encode(Buffer.from(cleanId, 'hex')); + return `/blog/${encoded}`; +}; export default async function Blog() { - const formatNumber = useCallback((num: number) => { - if (num >= 1000) { - return (num / 1000).toFixed(1) + 'K'; - } else if (num >= 1000000) { - return (num / 1000000).toFixed(1) + 'M'; - } - return num.toString(); - }, []); - let errorMsg = ''; - const blogs = await BlogAPI.list().catch(e => { errorMsg = `${e}`; return null }); + const blogs = await BlogAPI.list().catch(e => { + handleAPIError(e, ({ message }) => { errorMsg = message }); + return null; + }); return ( -
+
{ errorMsg && ( @@ -36,13 +47,28 @@ export default async function Blog() { } { blogs && blogs.map((blog) => ( -
- {blog.title} -

{blog.description}

-

{new Date(blog.createdAt).toLocaleString()} · {formatNumber(blog.viewCount)} 次访问

-
+
+

+ + {blog.title} + +

+

{blog.description}

+ +
)) } -
+ ) } \ No newline at end of file