cellpose-web/frontend/preview.html
2025-09-18 00:12:10 +03:00

62 lines
No EOL
2.3 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 type="module">
const API_BASE = "http://10.147.18.141:5000/";
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));
const { exists, status } = res.data; // exists: boolean, status: "running" | "success" | "failed"...
if (!exists) {
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>