waveshaker commited on
Commit
3eadeab
·
verified ·
1 Parent(s): c4023e0

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +22 -10
app.js CHANGED
@@ -502,7 +502,7 @@ async function loadInitialData() {
502
  document.querySelectorAll('.lora-card').forEach(c => c.classList.remove('selected'));
503
 
504
  renderBaseLoras(targetModel);
505
-
506
  // 🌟 核心修改:如果 URL 没有指定 lora 参数,说明是普通进入,开启动画
507
  const isPlainEntry = !loraParam;
508
  await fetchAndRenderGallery(targetModel, isPlainEntry);
@@ -588,7 +588,14 @@ async function loadInitialData() {
588
  console.error("❌ 初始化加载失败:", e);
589
  selectEl.innerHTML = `<option value="">🔴 Backend Offline</option>`;
590
  } finally {
591
- document.getElementById('unet-select').disabled = false;
 
 
 
 
 
 
 
592
  }
593
  }
594
 
@@ -1243,29 +1250,34 @@ document.getElementById('generate-btn').addEventListener('click', async () => {
1243
  // 🚀 Initialization
1244
  // ==========================================================================
1245
  document.addEventListener("DOMContentLoaded", async () => {
1246
- console.log("🔥 触发后端唤醒机制...");
1247
- fetch(`${API_BASE_URL}/api/health`, { cache: 'no-store' })
1248
- .then(() => console.log("✅ 唤醒请求已发送"))
1249
- .catch(() => console.log("⏳ 后端正在启动中,请稍候..."));
1250
-
1251
  setUIState(false);
1252
-
1253
  try {
 
 
1254
  const isHealthy = await BackendAPI.checkHealth();
1255
 
1256
  if (isHealthy) {
 
1257
  backendState.isReady = true;
1258
  document.getElementById('backend-status-dot').className = "status-dot online";
1259
  setUIState(false);
1260
  await loadInitialData();
1261
  } else {
1262
- console.warn("⚠️ 心跳检测未通过,尝试强制加载一次数据...");
1263
  document.getElementById('backend-status-dot').className = "status-dot offline";
1264
- await loadInitialData();
 
 
1265
  startHealthPolling();
 
 
 
1266
  }
1267
  } catch (error) {
1268
  console.error("❌ 初始化发生严重错误:", error);
 
1269
  startHealthPolling();
1270
  }
1271
  });
 
502
  document.querySelectorAll('.lora-card').forEach(c => c.classList.remove('selected'));
503
 
504
  renderBaseLoras(targetModel);
505
+
506
  // 🌟 核心修改:如果 URL 没有指定 lora 参数,说明是普通进入,开启动画
507
  const isPlainEntry = !loraParam;
508
  await fetchAndRenderGallery(targetModel, isPlainEntry);
 
588
  console.error("❌ 初始化加载失败:", e);
589
  selectEl.innerHTML = `<option value="">🔴 Backend Offline</option>`;
590
  } finally {
591
+ document.getElementById('unet-select').disabled = false;
592
+
593
+ // 🌟 核心:隐藏加载遮罩
594
+ const mask = document.getElementById('global-loading-mask');
595
+ if (mask) {
596
+ mask.style.opacity = '0';
597
+ setTimeout(() => mask.remove(), 300); // 300ms 后彻底从 DOM 移除
598
+ }
599
  }
600
  }
601
 
 
1250
  // 🚀 Initialization
1251
  // ==========================================================================
1252
  document.addEventListener("DOMContentLoaded", async () => {
1253
+ console.log("🔥 触发初始化,开始检查后端状态...");
 
 
 
 
1254
  setUIState(false);
1255
+
1256
  try {
1257
+ // 🌟 1. 直接只发一次请求,代替之前的“唤醒”+“检查”
1258
+ // checkHealth 内部已经带了 3 秒超时兜底
1259
  const isHealthy = await BackendAPI.checkHealth();
1260
 
1261
  if (isHealthy) {
1262
+ console.log("✅ 后端在线,开始拉取数据");
1263
  backendState.isReady = true;
1264
  document.getElementById('backend-status-dot').className = "status-dot online";
1265
  setUIState(false);
1266
  await loadInitialData();
1267
  } else {
1268
+ console.warn("⚠️ 首次心跳失败(后端可能在启动中),尝试静默重试...");
1269
  document.getElementById('backend-status-dot').className = "status-dot offline";
1270
+
1271
+ // 🌟 2. 如果失败,不要立刻强拉数据(会报错),而是先启动轮询
1272
+ // 让 startHealthPolling 去后台默默重试
1273
  startHealthPolling();
1274
+
1275
+ // 仍然保留你原来的兜底:强行加载一次 UI(即使没数据)
1276
+ await loadInitialData();
1277
  }
1278
  } catch (error) {
1279
  console.error("❌ 初始化发生严重错误:", error);
1280
+ document.getElementById('backend-status-dot').className = "status-dot offline";
1281
  startHealthPolling();
1282
  }
1283
  });