This commit is contained in:
parent
6e77f629e9
commit
04db5e7b0b
|
|
@ -169,6 +169,8 @@ export function DetailPageHeader({ data }: { data: any }) {
|
|||
const [downloadPercent, setDownloadPercent] = useState("0"); // 下载百分比(0 ~ 100)
|
||||
const [showDownloadBar, setShowDownloadBar] = useState(false);
|
||||
|
||||
const [newVersionLoading, setNewVersionLoading] = useState(false);
|
||||
|
||||
const socketRef = useRef<WebSocket | null>(null);
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
|
@ -443,6 +445,57 @@ export function DetailPageHeader({ data }: { data: any }) {
|
|||
};
|
||||
|
||||
|
||||
const handleDownloadNewVersion = async () => {
|
||||
const download_url = data?.extra_data?.download_url;
|
||||
const callback_url = data?.extra_data?.callback_url;
|
||||
const digest = data?.extra_data?.digest;
|
||||
const version = data?.extra_data?.version;
|
||||
const size = data?.extra_data?.size;
|
||||
const date1 = data?.extra_data?.date;
|
||||
const id = data?.org_id;
|
||||
|
||||
if (!download_url || !size || !id) {
|
||||
message.warning("缺少必要的下载参数");
|
||||
return;
|
||||
}
|
||||
|
||||
setNewVersionLoading(true);
|
||||
setShowDownloadBar(true); // 复用原进度条
|
||||
|
||||
try {
|
||||
const res = await fetch("https://ai.szaiai.com/api/v1/cloud/newversion", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
date: date1,
|
||||
url: download_url,
|
||||
callback_url,
|
||||
digest,
|
||||
version,
|
||||
size,
|
||||
id,
|
||||
}),
|
||||
});
|
||||
|
||||
const result = await res.json();
|
||||
|
||||
if (result?.header?.code === 0) {
|
||||
const percent = (parseFloat(result?.data?.percent ?? "0") * 100).toFixed(1);
|
||||
setDownloadPercent(percent);
|
||||
message.success(`📦 更新进度:${percent}%`);
|
||||
if (percent === "100.0") message.success("🎉 新版本下载完成!");
|
||||
} else {
|
||||
message.warning(`❌ 更新失败:${result?.header?.message || "未知错误"}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
message.error("请求出错,无法更新");
|
||||
} finally {
|
||||
setNewVersionLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
fetchDeployStatus();
|
||||
}, [data?.id]);
|
||||
|
|
@ -516,18 +569,37 @@ export function DetailPageHeader({ data }: { data: any }) {
|
|||
)}
|
||||
|
||||
{statusLoaded && (currentStatus === "running" || currentStatus === "stopped") && (
|
||||
<button
|
||||
onClick={handleSwitchStatus}
|
||||
disabled={switchLoading || loading}
|
||||
className="hover:text-gray-700 transition self-end text-sm border border-gray-300 rounded px-2 py-1 bg-white"
|
||||
title={currentStatus === "running" ? "停止运行" : "启动运行"}
|
||||
>
|
||||
{switchLoading
|
||||
? "处理中..."
|
||||
: currentStatus === "running"
|
||||
? "⏹ 停止"
|
||||
: "▶️ 启动"}
|
||||
</button>
|
||||
// <button
|
||||
// onClick={handleSwitchStatus}
|
||||
// disabled={switchLoading || loading}
|
||||
// className="hover:text-gray-700 transition self-end text-sm border border-gray-300 rounded px-2 py-1 bg-white"
|
||||
// title={currentStatus === "running" ? "停止运行" : "启动运行"}
|
||||
// >
|
||||
// {switchLoading
|
||||
// ? "处理中..."
|
||||
// : currentStatus === "running"
|
||||
// ? "⏹ 停止"
|
||||
// : "▶️ 启动"}
|
||||
// </button>
|
||||
<div className="flex flex-col items-center gap-[2px]">
|
||||
<button
|
||||
onClick={handleDownloadNewVersion}
|
||||
disabled={newVersionLoading || loading}
|
||||
className="hover:text-gray-700 transition self-end text-sm border border-gray-300 rounded px-2 py-1 bg-white mt-1"
|
||||
title="下载并安装新版本"
|
||||
>
|
||||
{newVersionLoading ? "处理中..." : "⬇️ 更新"}
|
||||
</button>
|
||||
|
||||
{showDownloadBar && (
|
||||
<div className="w-[20px] h-[4px] bg-gray-200 rounded overflow-hidden mt-1">
|
||||
<div
|
||||
className="h-full bg-blue-500 transition-all duration-300"
|
||||
style={{ width: `${downloadPercent}%` }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{statusLoaded && showDelete && (
|
||||
|
|
|
|||
Loading…
Reference in New Issue