From a7c0fd91e215f40ff281f2049dc95e74d6a6419a Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 31 Mar 2025 13:11:50 +0800 Subject: [PATCH] . --- .../app/[locale]/details/[slug]/page.tsx | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/apps/blogai/app/[locale]/details/[slug]/page.tsx b/apps/blogai/app/[locale]/details/[slug]/page.tsx index e2e393f..0179396 100644 --- a/apps/blogai/app/[locale]/details/[slug]/page.tsx +++ b/apps/blogai/app/[locale]/details/[slug]/page.tsx @@ -75,6 +75,12 @@ export async function generateMetadata({ params }: Props): Promise { }; } + + + + + + const BlogArticleWrapper = async ({ params }: { params: { slug: string, locale: string, } }) => { const { serialized, frontmatter, headings } = await getPostContent(params.locale, params.slug); @@ -83,6 +89,44 @@ const BlogArticleWrapper = async ({ params }: { params: { slug: string, locale: const defaultImage = "https://gimg3.baidu.com/search/src=http%3A%2F%2Fpics3.baidu.com%2Ffeed%2F4ec2d5628535e5dd7c7cdc23847e08e2cc1b62c4.jpeg%40f_auto%3Ftoken%3D38327d5cbefb2cd45af58f8d47c0a0b5&refer=http%3A%2F%2Fwww.baidu.com&app=2021&size=f360,240&n=0&g=0n&q=75&fmt=auto?sec=1710435600&t=eafc0a27ff3295bb5b0b9065fc33a523" + + // 新增状态来存储部署状态和状态文本 + const [statusText, setStatusText] = useState('未知'); + const [progress, setProgress] = useState('0%'); + + // 在组件加载时发起部署请求 + useEffect(() => { + async function fetchDeployStatus() { + try { + const res = await fetch("/api/v1/deploy/status", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + id: frontmatter.id, // 假设 frontmatter.id 是你需要的标识符 + }), + }); + + const json = await res.json(); + + if (json?.header?.code === 0) { + setStatusText(`${json.header.message || "操作成功"}`); + } else { + setStatusText(`${json.header.message || "操作失败(后端返回错误)"}`); + } + + } catch (error) { + console.error('部署状态请求失败', error); + setStatusText('请求失败'); + setProgress('0%'); + } + } + + fetchDeployStatus(); + }, [frontmatter.id]); // 依赖于 frontmatter.id,每次 id 改变时重新请求 + + + + return ( <> {/* */} @@ -94,8 +138,8 @@ const BlogArticleWrapper = async ({ params }: { params: { slug: string, locale: category: frontmatter.tags, updated_at: frontmatter.date, company: frontmatter.title, - progress: "75%", - statusText: "运行中" + progress: progress, + statusText: deployStatus }} />