From d53274288a00b9a179c202cb7255f8be755c9bfd Mon Sep 17 00:00:00 2001 From: jinchao <383321154@qq.com> Date: Mon, 9 Jun 2025 14:39:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=91=E6=8E=A7=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Release/database/XNSim.db | Bin 1224704 -> 1224704 bytes XNSimHtml/components/data-monitor.js | 99 ++++++++++----------- XNSimHtml/components/model-monitor.js | 24 +---- XNSimHtml/components/run-sim.js | 9 -- XNSimHtml/components/simulation-monitor.js | 24 +---- 5 files changed, 54 insertions(+), 102 deletions(-) diff --git a/Release/database/XNSim.db b/Release/database/XNSim.db index 4685e530b2a0458a78bfa58ee2ea810deab58621..d6b2cbdf5565ca018f03044a85d122b661cba154 100644 GIT binary patch delta 388 zcmZp8;MMTJYl1Xm(L@<%#-fc0OZ=I2_)I6W2Y4`=ZuSd!$~)O1j+4nqr`aK{-64)~ zyF(n4=0>Kw*3-}MFL*a7#Wxt=;h?68yOgx>Kd5o8d!!Hm{}Q_SeY2>8JJl_ zO)unTmY*)m&CE4Dl%JV@yT}8kzx-_q%xwxRZ3?Vy3T$l(>}?7hZ3>**6u4L}$nmnX zG4KoU74pvIdB>B@eURIkD~_|5;}=ID`!RO5&58m~*c=*dbvPsyWzCy}#SQd~^bCy< zmK&N_8CzHxm_OOS?&*@==d&k1>s$VE;ntUP7bTUZ8|pn@zWe3OCDU_$bIGL4YI(7t z`NjIFFZNA-+P>@ko*szglO4TJ_qV=S*7$r@%ah%UpD$>9+|a~jqz5ta+0+fsde_J^<=M0iFB^8h*f$ZVB{3y8Gq3&FcP=3224Wr{<^^ItAm#^Rf$hh> I3tH^}0P{1ZrT_o{ delta 209 zcmZp8;MMTJYl1Xm?nD`9#@vkwOZ=I&`5Y#*2Y74_40ysjF@U$(A+Fsaj&Zv~9Fyio zrj4P~&+su@tD2aYnH!s!m|E!NII~L8~1A DMcGBk diff --git a/XNSimHtml/components/data-monitor.js b/XNSimHtml/components/data-monitor.js index 368c7d5..b62e000 100644 --- a/XNSimHtml/components/data-monitor.js +++ b/XNSimHtml/components/data-monitor.js @@ -89,26 +89,26 @@ class DataMonitor extends HTMLElement { if (this.isActive) return; // 如果已经激活,直接返回 this.isActive = true; this.initializeComponent(); + // 重新启动定时器 + this.startDataUpdateTimer(); } async initializeComponent() { try { - // 初始化DDS监控 - await this.initializeDDSMonitor(); - // 更新所有行的监控状态 this.tableData.forEach(row => { row.isMonitoring = true; }); - // 更新状态显示 + // 初始状态设置为未监控 const statusIndicator = this.shadowRoot.getElementById('statusIndicator'); const statusText = this.shadowRoot.getElementById('statusText'); if (statusIndicator) { - statusIndicator.classList.add('active'); + statusIndicator.classList.remove('active', 'error'); + statusIndicator.classList.add('inactive'); } if (statusText) { - statusText.textContent = '监控中'; + statusText.textContent = '未监控'; } this.renderTable(); @@ -117,6 +117,7 @@ class DataMonitor extends HTMLElement { const statusIndicator = this.shadowRoot.getElementById('statusIndicator'); const statusText = this.shadowRoot.getElementById('statusText'); if (statusIndicator) { + statusIndicator.classList.remove('active', 'inactive'); statusIndicator.classList.add('error'); } if (statusText) { @@ -231,51 +232,6 @@ class DataMonitor extends HTMLElement { } } - /** - * @description 初始化DDS监控服务 - * @returns {Promise} 初始化是否成功 - */ - async initializeDDSMonitor() { - try { - // 获取当前选择的配置 - const selection = this.getCurrentSelection(); - const { domainId } = selection; - if (!domainId) { - throw new Error('未找到有效的域ID,请确保已选择构型并等待构型加载完成'); - } - - // 检查DDS监控状态 - const statusResponse = await fetch('/api/dds-monitor/status'); - if (!statusResponse.ok) { - throw new Error(`获取DDS监控状态失败: ${statusResponse.status} ${statusResponse.statusText}`); - } - const statusData = await statusResponse.json(); - - // 如果未初始化,则初始化 - if (!statusData.isInitialized) { - const initResponse = await fetch('/api/dds-monitor/initialize', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - domainId, - monitorId: this.monitorId - }) - }); - - if (!initResponse.ok) { - const errorData = await initResponse.json(); - throw new Error(`初始化DDS监控失败: ${errorData.error || initResponse.statusText}`); - } - } - - return true; - } catch (error) { - throw error; - } - } - /** * @description 按结构体名称分组获取接口数据 * @returns {Object} 按结构体名称分组的接口数据 @@ -331,6 +287,43 @@ class DataMonitor extends HTMLElement { this.dataUpdateTimer = setInterval(async () => { try { + // 检查DDS监控状态 + const statusResponse = await fetch('/api/dds-monitor/status'); + if (!statusResponse.ok) { + throw new Error(`获取DDS监控状态失败: ${statusResponse.status} ${statusResponse.statusText}`); + } + const statusData = await statusResponse.json(); + + // 更新状态显示 + const statusIndicator = this.shadowRoot.getElementById('statusIndicator'); + const statusText = this.shadowRoot.getElementById('statusText'); + + if (!statusData.isInitialized) { + if (statusIndicator) { + statusIndicator.classList.remove('active'); + statusIndicator.classList.add('inactive'); + } + if (statusText) { + statusText.textContent = '未监控'; + } + // 更新表格中所有数据的监控状态 + this.tableData.forEach(row => { + row.isMonitoring = false; + row.monitorData = ''; + }); + this.renderTable(); + return; // 未初始化时等待下一次循环 + } + + // DDS已初始化,更新状态显示 + if (statusIndicator) { + statusIndicator.classList.remove('inactive', 'error'); + statusIndicator.classList.add('active'); + } + if (statusText) { + statusText.textContent = '监控中'; + } + const groupedInterfaces = this.getGroupedInterfaces(); // 对每个结构体启动监控并获取数据 @@ -662,6 +655,10 @@ class DataMonitor extends HTMLElement { background: #ff4d4f; } + .status-indicator.inactive { + background: #d9d9d9; + } + .global-monitor-btn { padding: 6px 16px; border: none; diff --git a/XNSimHtml/components/model-monitor.js b/XNSimHtml/components/model-monitor.js index 07b36d6..942269a 100644 --- a/XNSimHtml/components/model-monitor.js +++ b/XNSimHtml/components/model-monitor.js @@ -131,37 +131,19 @@ class ModelMonitor extends HTMLElement { } try { - // 获取构型参数 - const configResponse = await fetch(`/api/configurations/${confID}`); - if (!configResponse.ok) { - throw new Error('获取构型参数失败'); - } - const configData = await configResponse.json(); - - // 从构型参数中提取域ID - const domainId = configData.DomainID; - if (!domainId) { - throw new Error('构型参数中未找到有效的域ID'); - } - this.domainId = domainId; - // 首先检查DDS监控状态 const ddsStatusResponse = await fetch('/api/dds-monitor/status'); const ddsStatusData = await ddsStatusResponse.json(); // 如果DDS监控未初始化,直接返回,等待下次定时器运行时再检查 if (!ddsStatusData.isInitialized) { - console.log('DDS监控未初始化,等待下次检查'); + //console.log('DDS监控未初始化,等待下次检查'); return; } // 启动模型监控 const response = await fetch('/api/model-monitor/start', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ domainId }) + method: 'POST' }); const data = await response.json(); if (response.ok) { @@ -314,7 +296,7 @@ class ModelMonitor extends HTMLElement { // 如果监控未运行,直接返回 if (!statusData.isMonitoring) { - console.log('监控未运行,无需关闭'); + //console.log('监控未运行,无需关闭'); return; } diff --git a/XNSimHtml/components/run-sim.js b/XNSimHtml/components/run-sim.js index 7a6c928..817da30 100644 --- a/XNSimHtml/components/run-sim.js +++ b/XNSimHtml/components/run-sim.js @@ -1225,15 +1225,6 @@ class RunSim extends HTMLElement { this.currentSimulationId = null; this.showSuccess('仿真已停止'); - // 关闭系统监控 - try { - await fetch('/api/system-monitor/stop', { - method: 'POST' - }); - } catch (error) { - - } - // 关闭DDS监控 try { await fetch('/api/dds-monitor/unregister', { diff --git a/XNSimHtml/components/simulation-monitor.js b/XNSimHtml/components/simulation-monitor.js index 3b2ecd1..d2bffca 100644 --- a/XNSimHtml/components/simulation-monitor.js +++ b/XNSimHtml/components/simulation-monitor.js @@ -123,37 +123,19 @@ class SimulationMonitor extends HTMLElement { } try { - // 获取构型参数 - const configResponse = await fetch(`/api/configurations/${confID}`); - if (!configResponse.ok) { - throw new Error('获取构型参数失败'); - } - const configData = await configResponse.json(); - - // 从构型参数中提取域ID - const domainId = configData.DomainID; - if (!domainId) { - throw new Error('构型参数中未找到有效的域ID'); - } - this.domainId = domainId; - // 首先检查DDS监控状态 const ddsStatusResponse = await fetch('/api/dds-monitor/status'); const ddsStatusData = await ddsStatusResponse.json(); // 如果DDS监控未初始化,直接返回,等待下次定时器运行时再检查 if (!ddsStatusData.isInitialized) { - console.log('DDS监控未初始化,等待下次检查'); + //console.log('DDS监控未初始化,等待下次检查'); return; } // 启动系统监控 const response = await fetch('/api/system-monitor/start', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ domainId }) + method: 'POST' }); const data = await response.json(); if (response.ok) { @@ -385,7 +367,7 @@ class SimulationMonitor extends HTMLElement { // 如果监控未运行,直接返回 if (!statusData.isMonitoring) { - console.log('监控未运行,无需关闭'); + //console.log('监控未运行,无需关闭'); return; }