From d61dec87cf2dbaccc533fa369994d4f49b831ea5 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期日, 30 八月 2026 19:22:30 +0800
Subject: [PATCH] 修复模拟器开机控制页响应处理

---
 ruoyi-admin/src/main/resources/static/dev/bts-simulator.html |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ruoyi-admin/src/main/resources/static/dev/bts-simulator.html b/ruoyi-admin/src/main/resources/static/dev/bts-simulator.html
index 47f4a13..95d4197 100644
--- a/ruoyi-admin/src/main/resources/static/dev/bts-simulator.html
+++ b/ruoyi-admin/src/main/resources/static/dev/bts-simulator.html
@@ -133,10 +133,13 @@
       const response = await fetch(api + path, { ...options, headers: { 'Content-Type': 'application/json' } });
       if (!response.ok) {
         let message = `请求失败 (${response.status})`;
-        try { message = (await response.json()).message || message; } catch (_) { }
+        try { const error = await response.json(); message = error?.msg || error?.message || message; } catch (_) { }
         throw new Error(message);
       }
-      return response.json();
+      const payload = await response.json();
+      if (payload && payload.data && typeof payload.data === 'object'
+        && !Array.isArray(payload.devices) && payload.data.devices) return payload.data;
+      return payload;
     }
 
     function showError(error) {
@@ -146,6 +149,14 @@
 
     function render(state) {
       errorBox.classList.remove('visible');
+      if (!state || typeof state !== 'object') throw new Error('模拟器响应缺少状态数据');
+      if (state.data && typeof state.data === 'object' && !Array.isArray(state.devices)) state = state.data;
+      state = {
+        ...state,
+        devices: Array.isArray(state.devices) ? state.devices : [],
+        collectors: Array.isArray(state.collectors) ? state.collectors : [],
+        recentRequests: Array.isArray(state.recentRequests) ? state.recentRequests : [],
+      };
       const runtime = document.querySelector('#runtime');
       runtime.textContent = state.running ? '运行中' : '已停止';
       runtime.classList.toggle('online', state.running);

--
Gitblit v1.7.1