mirror of
https://github.com/ClovertaTheTrilobita/cellpose-web.git
synced 2026-04-01 23:14:50 +00:00
69 lines
No EOL
2.5 KiB
HTML
69 lines
No EOL
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="UTF-8" />
|
|
<h1>运行结果预览</h1>
|
|
<p id="none-exist" hidden></p>
|
|
<div id="gallery"></div>
|
|
<button onclick="downloadTif()">下载tif</button>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
<script src="api.js"></script>
|
|
<script type="module">
|
|
|
|
const API_STATUS = API_BASE + "status";
|
|
const API_PIC = API_BASE + "preview";
|
|
const API_DL = API_BASE + "dl";
|
|
const params = new URLSearchParams(window.location.search);
|
|
const ID = params.get("id");
|
|
|
|
const msg = document.getElementById("none-exist");
|
|
|
|
if (!ID) {
|
|
msg.textContent = "missing id in URL";
|
|
msg.hidden = false;
|
|
} else {
|
|
try {
|
|
const res = await axios.get(API_STATUS + "?id=" + encodeURIComponent(ID));
|
|
console.log(res);
|
|
const { exists, status } = res.data; // exists: boolean, status: "running" | "success" | "failed"...
|
|
|
|
if (!exists) {
|
|
msg.textContent = `id "${ID}" 不存在`;
|
|
msg.hidden = false;
|
|
}
|
|
else if (status == "running"){
|
|
msg.textContent = `id "${ID}" 仍在运行中,请耐心等待片刻后刷新。`;
|
|
msg.hidden = false;
|
|
}
|
|
else {
|
|
msg.hidden = true;
|
|
axios.get(API_PIC + "?id=" + encodeURIComponent(ID)).then(res => {
|
|
if (res.data.ok) {
|
|
const gallery = document.getElementById("gallery");
|
|
res.data.images.forEach(img => {
|
|
const el = document.createElement("img");
|
|
el.src = "data:image/png;base64," + img.image;
|
|
el.alt = img.filename;
|
|
el.style.width = "200px"; // 缩略图大小
|
|
gallery.appendChild(el);
|
|
});
|
|
} else {
|
|
alert(res.data.error);
|
|
}
|
|
});
|
|
}
|
|
} catch (e) {
|
|
msg.textContent = "请求失败";
|
|
msg.hidden = false;
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
window.downloadTif = function () {
|
|
const a = document.createElement("a");
|
|
a.href = API_DL + "?id=" + encodeURIComponent(ID);
|
|
a.download = ID; // 留空:文件名由服务端决定;可写具体名称
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
}
|
|
</script> |