2025-09-16 19:43:06 +00:00
|
|
|
<!DOCTYPE html>
|
2025-09-17 19:43:36 +00:00
|
|
|
<meta charset="UTF-8" />
|
2025-09-17 21:12:10 +00:00
|
|
|
<h1>运行结果预览</h1>
|
2025-09-17 20:46:25 +00:00
|
|
|
<p id="none-exist" hidden></p>
|
|
|
|
|
<div id="gallery"></div>
|
2025-09-17 21:12:10 +00:00
|
|
|
<button onclick="downloadTif()">下载tif</button>
|
2025-09-17 19:43:36 +00:00
|
|
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
|
|
|
<script type="module">
|
2025-09-17 21:12:10 +00:00
|
|
|
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");
|
2025-09-17 19:43:36 +00:00
|
|
|
|
2025-09-17 21:12:10 +00:00
|
|
|
const msg = document.getElementById("none-exist");
|
2025-09-17 19:43:36 +00:00
|
|
|
|
2025-09-17 21:12:10 +00:00
|
|
|
if (!ID) {
|
|
|
|
|
msg.textContent = "missing id in URL";
|
|
|
|
|
msg.hidden = false;
|
|
|
|
|
} else {
|
2025-09-17 20:46:25 +00:00
|
|
|
try {
|
2025-09-17 21:12:10 +00:00
|
|
|
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 = "请求失败";
|
2025-09-17 20:46:25 +00:00
|
|
|
msg.hidden = false;
|
2025-09-17 21:12:10 +00:00
|
|
|
console.error(e);
|
2025-09-17 20:46:25 +00:00
|
|
|
}
|
2025-09-17 19:43:36 +00:00
|
|
|
}
|
2025-09-17 21:12:10 +00:00
|
|
|
|
|
|
|
|
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>
|