This commit is contained in:
hailin 2025-04-01 10:48:30 +08:00
parent a4f71b047a
commit ca74fa086a
2 changed files with 73 additions and 38 deletions

View File

@ -90,46 +90,46 @@ 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"
// 请求部署状态
let statusText = '';
let progress = '0%';
let data: any;
// // 请求部署状态
// let statusText = '';
// let progress = '0%';
// let data: any;
try {
data = await service.post('/api/v1/deploy/status', {
id: frontmatter.id, // 假设 frontmatter.id 是你需要的标识符
}, {
headers: {
// 'Authorization': token // 如果需要身份验证,可以在这里加上 token
}
}).then((result: any) => {
console.log("==================>result:", result);
// try {
// data = await service.post('/api/v1/deploy/status', {
// id: frontmatter.id, // 假设 frontmatter.id 是你需要的标识符
// }, {
// headers: {
// // 'Authorization': token // 如果需要身份验证,可以在这里加上 token
// }
// }).then((result: any) => {
// console.log("==================>result:", result);
if (result && result.header.code !== 1006) {
statusText = result.header.message || '操作失败(后端返回错误)';
return; // 如果返回失败,不继续处理
}
if (result.header.code !== 1006){
// 如果请求成功
statusText = "";
// 设置部署状态数据
progress = '0%'; // 假设返回的数据里有进度
}
else{
// 如果请求成功
statusText = result.header.message || '操作成功';
// 设置部署状态数据
progress = result.data.progress || '0%'; // 假设返回的数据里有进度
}
// if (result && result.header.code !== 1006) {
// statusText = result.header.message || '操作失败(后端返回错误)';
// return; // 如果返回失败,不继续处理
// }
// if (result.header.code !== 1006){
// // 如果请求成功
// statusText = "";
// // 设置部署状态数据
// progress = '0%'; // 假设返回的数据里有进度
// }
// else{
// // 如果请求成功
// statusText = result.header.message || '操作成功';
// // 设置部署状态数据
// progress = result.data.progress || '0%'; // 假设返回的数据里有进度
// }
}).catch((err) => {
console.error('请求部署状态失败:', err);
statusText = '请求失败';
});
} catch (err) {
console.error('请求部署状态错误:', err);
statusText = '请求失败';
}
// }).catch((err) => {
// console.error('请求部署状态失败:', err);
// statusText = '请求失败';
// });
// } catch (err) {
// console.error('请求部署状态错误:', err);
// statusText = '请求失败';
// }

View File

@ -236,6 +236,41 @@ export function DetailPageHeader({ data }: { data: any }) {
};
useEffect(() => {
const fetchDeployStatus = async () => {
try {
const result = await fetch("/api/v1/deploy/status", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id: data?.id }),
}).then((res) => res.json());
console.log("==================>result:", result);
if (!result || result.header?.code !== 1006) {
setStatusText(result?.header?.message || "操作失败(后端返回错误)");
setShowDelete(false); // 非 1006 隐藏删除按钮
return;
}
// 如果成功返回
setStatusText(result.header.message || "部署成功");
setShowDelete(true); // code === 1006 可以显示删除按钮
// 如果还想设置进度的话,这里也可以 setProgress(result.data.progress || '0%')
} catch (err) {
console.error("请求部署状态失败:", err);
setStatusText("请求失败");
setShowDelete(false);
}
};
fetchDeployStatus();
}, [data?.id]); // id 变化时重新获取
// 处理图标路径
const isImagePath =
typeof data?.icon === "string" &&
@ -292,7 +327,7 @@ export function DetailPageHeader({ data }: { data: any }) {
</div>
{/* 条件显示删除按钮 */}
{true && (
{showDelete && (
<button
onClick={handleDelete}
className="hover:text-gray-700 transition self-end"