diff --git a/src/api/routes.py b/src/api/routes.py index 762b4c5..fe9ee86 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -156,8 +156,18 @@ async def get_status(task_id: str, db_session: AsyncSession = Depends(get_db_ses geometry_json: Optional[Dict[str, Any]] = None if file_with_data.get("geometry_data"): - # save_geometry_data 支持两种格式,这里直接拿回来的就是几何字典 - geometry_json = file_with_data["geometry_data"] + # save_geometry_data 保存时可能有两种格式: + # 1. 直接保存 geometry_data 字典 + # 2. 保存 {"geometry_data": {...}} 格式 + # get_stp_file_with_data 返回的是从RustFS下载的原始JSON + geo_raw = file_with_data["geometry_data"] + if isinstance(geo_raw, dict): + # 如果是包装格式,提取内部数据 + if "geometry_data" in geo_raw: + geometry_json = geo_raw["geometry_data"] + else: + # 直接就是几何数据字典 + geometry_json = geo_raw cavity_json: Optional[Dict[str, Any]] = file_with_data.get("mold_cavity_data") diff --git a/static/style.css b/static/style.css index 010855a..64fdfac 100644 --- a/static/style.css +++ b/static/style.css @@ -790,7 +790,8 @@ body { color: #e5e7eb; } -.upload-dropzone:hover { +.upload-dropzone:hover, +.upload-dropzone.drag-over { border-color: #60a5fa; background: linear-gradient(135deg, rgba(15, 23, 42, 1), rgba(37, 99, 235, 0.6)); } @@ -800,6 +801,23 @@ body { margin-bottom: 6px; } +.clear-file-btn { + margin-top: 8px; + padding: 4px 12px; + font-size: 0.8rem; + background: rgba(239, 68, 68, 0.2); + color: #fca5a5; + border: 1px solid rgba(239, 68, 68, 0.4); + border-radius: 6px; + cursor: pointer; + transition: all 0.2s ease; +} + +.clear-file-btn:hover { + background: rgba(239, 68, 68, 0.3); + border-color: rgba(239, 68, 68, 0.6); +} + .upload-btn { background: linear-gradient(135deg, #3b82f6, #6366f1); color: white; @@ -947,6 +965,11 @@ body { text-transform: none; } +.status-pending { + background: rgba(148, 163, 184, 0.15); + color: #94a3b8; +} + .status-processing { background: rgba(250, 204, 21, 0.15); color: #facc15; diff --git a/static/vue-app.js b/static/vue-app.js index 7dbe93a..2e7d671 100644 --- a/static/vue-app.js +++ b/static/vue-app.js @@ -287,12 +287,26 @@ const DashboardView = { const startPolling = async (taskId) => { state.polling = true; + let pollCount = 0; + const maxPolls = 300; // 最多轮询5分钟(300秒) + const poll = async () => { try { + pollCount++; const res = await fetch(`/status/${taskId}`, { method: "POST" }); - if (!res.ok) { - throw new Error("查询任务状态失败"); + + if (res.status === 404) { + // 任务不存在,停止轮询 + state.polling = false; + state.error = "任务不存在或已被删除"; + addNotification("任务不存在或已被删除", 'error'); + return; } + + if (!res.ok) { + throw new Error(`查询任务状态失败: ${res.status} ${res.statusText}`); + } + const task = await res.json(); state.currentTask = task; @@ -307,6 +321,11 @@ const DashboardView = { const errorMsg = task.error || "未知错误"; state.error = `分析失败: ${errorMsg}`; addNotification(`分析失败: ${errorMsg}`, 'error'); + } else if (pollCount >= maxPolls) { + // 超时停止轮询 + state.polling = false; + state.error = "任务处理超时,请稍后查看结果"; + addNotification("任务处理超时,请稍后查看结果", 'warning'); } else { setTimeout(poll, 1000); } @@ -365,50 +384,57 @@ const DashboardView = {

上传后系统会自动解析几何、生成模具型腔并计算关键工艺参数。

-