This commit is contained in:
parent
bff7dafae0
commit
25e785fdd7
|
|
@ -490,15 +490,63 @@ export function DetailPageHeader({ data }: { data: any }) {
|
|||
}
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
const handleDelete = async () => {
|
||||
if (loading) return;
|
||||
if (window.confirm("确定要删除吗?")) {
|
||||
|
||||
const confirmed = window.confirm("确定要删除该部署吗?");
|
||||
if (!confirmed) return;
|
||||
|
||||
setLoading(true);
|
||||
console.log("模拟删除执行...");
|
||||
setStatusText("正在删除部署...");
|
||||
setProgressBarColor("bg-gray-400");
|
||||
|
||||
try {
|
||||
const userData = JSON.parse(localStorage.getItem("UserData") || "null");
|
||||
const userName = userData?.user_name;
|
||||
const id = data?.id;
|
||||
|
||||
if (!userName || !id) {
|
||||
setStatusText("缺少 user_name 或 id");
|
||||
return;
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 10_000); // ⏰ 10秒超时
|
||||
|
||||
const res = await fetch("/api/v1/deploy/delete", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
signal: controller.signal,
|
||||
body: JSON.stringify({ user_name: userName, id }),
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId); // ✅ 成功返回前清除 timeout
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP 请求失败: ${res.status}`);
|
||||
}
|
||||
|
||||
const json = await res.json();
|
||||
if (json?.header?.code === 0) {
|
||||
setStatusText("删除成功");
|
||||
setProgress("0%");
|
||||
setShowDelete(false); // 删除成功后隐藏按钮
|
||||
} else {
|
||||
setStatusText(json?.header?.message || "删除失败(后端返回错误)");
|
||||
}
|
||||
} catch (err) {
|
||||
if ((err as any).name === "AbortError") {
|
||||
setStatusText("请求超时(超过10秒)");
|
||||
} else {
|
||||
console.error("删除请求出错:", err);
|
||||
setStatusText("删除失败,请检查网络");
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDeployStatus = async () => {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue