This commit is contained in:
hailin 2025-03-31 13:20:19 +08:00
parent 56ea3878a2
commit bce1281d1d
1 changed files with 17 additions and 32 deletions

View File

@ -16,8 +16,6 @@ import { Header, NavBack, TimeP } from "@/components/header";
import { baseTitle, baseURL, keywordsRoot } from "@/lib/metadata";
import { useTranslation } from "react-i18next";
import { useState, useEffect } from 'react';
import { DetailPageHeader } from '@/components/header'
export const runtime = "nodejs";
@ -92,39 +90,26 @@ 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<string>('未知');
const [progress, setProgress] = useState<string>('0%');
// 发起部署请求
const res = await fetch("/api/v1/deploy/status", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: frontmatter.id, // 假设 frontmatter.id 是你需要的标识符
}),
});
// 在组件加载时发起部署请求
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();
const json = await res.json();
// 根据 API 返回值更新状态文本
let statusText = '';
let progress = '0%';
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 改变时重新请求
if (json?.header?.code === 0) {
statusText = `${json.header.message || "操作成功"}`;
} else {
statusText = `${json.header.message || "操作失败(后端返回错误)"}`;
}