diff --git a/backend/flaskApp.py b/backend/flaskApp.py index 03b85bf..83f558f 100644 --- a/backend/flaskApp.py +++ b/backend/flaskApp.py @@ -71,6 +71,7 @@ def upload(): print("cpt:" + str(cellprob_threshold)) print("flow:" + str(flow_threshold)) + print("diameter:" + str(diameter)) # 将文件保存在本地目录中 ts = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + f"-{int(time.time()*1000)%1000:03d}" diff --git a/frontend/index.html b/frontend/index.html index 87e82b1..ed90868 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,69 +1,140 @@ - - - - -


- -

- -

- -

- + + - - + + + \ No newline at end of file + + document.getElementById("uploadBtn").addEventListener("click", async () => { + const input = document.getElementById("fileInput"); + if (!input.files.length) return alert("请选择文件"); + + const fd = new FormData(); + for (const f of input.files) fd.append("files", f); + + const bar = document.getElementById("bar"); + try { + const URL = buildUrl(); + const res = await axios.post(URL, fd, { + onUploadProgress: (e) => { + if (e.total) bar.value = Math.round((e.loaded * 100) / e.total); + }, + }); + // alert("上传成功:" + JSON.stringify(res.data)); + + // 创建一个提示元素 + const notice = document.createElement("div"); + notice.style.position = "fixed"; + notice.style.top = "20px"; + notice.style.left = "50%"; + notice.style.transform = "translateX(-50%)"; + notice.style.padding = "10px 20px"; + notice.style.background = "#4caf50"; + notice.style.color = "white"; + notice.style.borderRadius = "8px"; + notice.style.fontSize = "16px"; + notice.style.zIndex = "9999"; + + let seconds = 3; + notice.textContent = `上传成功!${seconds} 秒后跳转预览页面…`; + document.body.appendChild(notice); + + const timer = setInterval(() => { + seconds--; + if (seconds > 0) { + notice.textContent = `上传成功!${seconds} 秒后跳转预览页面…`; + } else { + clearInterval(timer); + document.body.removeChild(notice); + window.location.href = `preview.html?id=${encodeURIComponent(res.data['id'])}`; + } + }, 1000); + } catch (e) { + alert("上传失败:" + (e.response?.data?.message || e.message)); + } finally { + bar.value = 0; + } + }); + + + + \ No newline at end of file diff --git a/frontend/preview.html b/frontend/preview.html index 6645602..9f08313 100644 --- a/frontend/preview.html +++ b/frontend/preview.html @@ -22,12 +22,18 @@ } 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 { + } + 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) {