From d216edd0e9931d71664f33e625cff6d8131a0fad Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 13 三月 2026 16:00:40 +0800
Subject: [PATCH] 重构: 实现前后端分离架构

---
 Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Index.cshtml |   41 +++++++++++++++++++++++++++++------------
 1 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Index.cshtml b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Index.cshtml
index e86b444..13cd2f0 100644
--- a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Index.cshtml
+++ b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Index.cshtml
@@ -11,9 +11,15 @@
         </h2>
         <p class="text-muted mb-0 mt-1">绠$悊鍜岀洃鎺� S7 PLC 浠跨湡鍣ㄥ疄渚�</p>
     </div>
-    <a asp-page="/Create" class="btn btn-primary">
-        <i class="bi bi-plus-lg me-1"></i>鍒涘缓瀹炰緥
-    </a>
+    <div class="d-flex align-items-center gap-3">
+        <div id="refreshIndicator" class="text-muted small" style="display: none;">
+            <i class="bi bi-arrow-clockwise spin-icon me-1"></i>
+            <span>鏇存柊涓�...</span>
+        </div>
+        <a asp-page="/Create" class="btn btn-primary">
+            <i class="bi bi-plus-lg me-1"></i>鍒涘缓瀹炰緥
+        </a>
+    </div>
 </div>
 
 <div id="instancesContainer">
@@ -41,18 +47,29 @@
     let autoRefreshInterval = null;
 
     document.addEventListener('DOMContentLoaded', function () {
-        loadInstances();
-        startAutoRefresh(loadInstances, 5000);
+        loadInstances(false); // 棣栨鍔犺浇鏄剧ず loading
+        startAutoRefresh(() => loadInstances(true), 2000); // 鑷姩鍒锋柊浣跨敤闈欓粯妯″紡锛屾瘡2绉掑埛鏂�
     });
 
-    async function loadInstances() {
+    async function loadInstances(silent = false) {
+        const refreshIndicator = document.getElementById('refreshIndicator');
+        if (silent && refreshIndicator) {
+            refreshIndicator.style.display = 'block';
+        }
+
         try {
-            const instances = await apiCall(`${API_BASE_URL}/SimulatorInstances`);
+            const instances = await apiCall(`${API_BASE_URL}/SimulatorInstances`, { silent: silent });
             renderInstances(instances);
         } catch (error) {
             console.error('Failed to load instances:', error);
-            document.getElementById('loadingState').classList.add('d-none');
-            document.getElementById('emptyState').classList.remove('d-none');
+            if (!silent) {
+                document.getElementById('loadingState').classList.add('d-none');
+                document.getElementById('emptyState').classList.remove('d-none');
+            }
+        } finally {
+            if (silent && refreshIndicator) {
+                refreshIndicator.style.display = 'none';
+            }
         }
     }
 
@@ -173,7 +190,7 @@
                     method: 'POST'
                 });
                 showToast(`瀹炰緥 "${id}" 鍚姩鍛戒护宸插彂閫乣, 'success');
-                setTimeout(() => loadInstances(), 1000);
+                setTimeout(() => loadInstances(false), 1000);
             } catch (error) {
                 console.error('Failed to start instance:', error);
             }
@@ -187,7 +204,7 @@
                     method: 'POST'
                 });
                 showToast(`瀹炰緥 "${id}" 鍋滄鍛戒护宸插彂閫乣, 'success');
-                setTimeout(() => loadInstances(), 1000);
+                setTimeout(() => loadInstances(false), 1000);
             } catch (error) {
                 console.error('Failed to stop instance:', error);
             }
@@ -201,7 +218,7 @@
                     method: 'DELETE'
                 });
                 showToast(`瀹炰緥 "${id}" 宸插垹闄, 'success');
-                loadInstances();
+                loadInstances(false);
             } catch (error) {
                 console.error('Failed to delete instance:', error);
             }

--
Gitblit v1.9.3