修复监控页面bug

This commit is contained in:
jinchao 2025-06-09 14:39:29 +08:00
parent 4743606222
commit d53274288a
5 changed files with 54 additions and 102 deletions

Binary file not shown.

View File

@ -89,26 +89,26 @@ class DataMonitor extends HTMLElement {
if (this.isActive) return; // 如果已经激活,直接返回 if (this.isActive) return; // 如果已经激活,直接返回
this.isActive = true; this.isActive = true;
this.initializeComponent(); this.initializeComponent();
// 重新启动定时器
this.startDataUpdateTimer();
} }
async initializeComponent() { async initializeComponent() {
try { try {
// 初始化DDS监控
await this.initializeDDSMonitor();
// 更新所有行的监控状态 // 更新所有行的监控状态
this.tableData.forEach(row => { this.tableData.forEach(row => {
row.isMonitoring = true; row.isMonitoring = true;
}); });
// 更新状态显示 // 初始状态设置为未监控
const statusIndicator = this.shadowRoot.getElementById('statusIndicator'); const statusIndicator = this.shadowRoot.getElementById('statusIndicator');
const statusText = this.shadowRoot.getElementById('statusText'); const statusText = this.shadowRoot.getElementById('statusText');
if (statusIndicator) { if (statusIndicator) {
statusIndicator.classList.add('active'); statusIndicator.classList.remove('active', 'error');
statusIndicator.classList.add('inactive');
} }
if (statusText) { if (statusText) {
statusText.textContent = '监控'; statusText.textContent = '监控';
} }
this.renderTable(); this.renderTable();
@ -117,6 +117,7 @@ class DataMonitor extends HTMLElement {
const statusIndicator = this.shadowRoot.getElementById('statusIndicator'); const statusIndicator = this.shadowRoot.getElementById('statusIndicator');
const statusText = this.shadowRoot.getElementById('statusText'); const statusText = this.shadowRoot.getElementById('statusText');
if (statusIndicator) { if (statusIndicator) {
statusIndicator.classList.remove('active', 'inactive');
statusIndicator.classList.add('error'); statusIndicator.classList.add('error');
} }
if (statusText) { if (statusText) {
@ -231,51 +232,6 @@ class DataMonitor extends HTMLElement {
} }
} }
/**
* @description 初始化DDS监控服务
* @returns {Promise<boolean>} 初始化是否成功
*/
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 按结构体名称分组获取接口数据 * @description 按结构体名称分组获取接口数据
* @returns {Object} 按结构体名称分组的接口数据 * @returns {Object} 按结构体名称分组的接口数据
@ -331,6 +287,43 @@ class DataMonitor extends HTMLElement {
this.dataUpdateTimer = setInterval(async () => { this.dataUpdateTimer = setInterval(async () => {
try { 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(); const groupedInterfaces = this.getGroupedInterfaces();
// 对每个结构体启动监控并获取数据 // 对每个结构体启动监控并获取数据
@ -662,6 +655,10 @@ class DataMonitor extends HTMLElement {
background: #ff4d4f; background: #ff4d4f;
} }
.status-indicator.inactive {
background: #d9d9d9;
}
.global-monitor-btn { .global-monitor-btn {
padding: 6px 16px; padding: 6px 16px;
border: none; border: none;

View File

@ -131,37 +131,19 @@ class ModelMonitor extends HTMLElement {
} }
try { 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监控状态 // 首先检查DDS监控状态
const ddsStatusResponse = await fetch('/api/dds-monitor/status'); const ddsStatusResponse = await fetch('/api/dds-monitor/status');
const ddsStatusData = await ddsStatusResponse.json(); const ddsStatusData = await ddsStatusResponse.json();
// 如果DDS监控未初始化直接返回等待下次定时器运行时再检查 // 如果DDS监控未初始化直接返回等待下次定时器运行时再检查
if (!ddsStatusData.isInitialized) { if (!ddsStatusData.isInitialized) {
console.log('DDS监控未初始化等待下次检查'); //console.log('DDS监控未初始化等待下次检查');
return; return;
} }
// 启动模型监控 // 启动模型监控
const response = await fetch('/api/model-monitor/start', { const response = await fetch('/api/model-monitor/start', {
method: 'POST', method: 'POST'
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ domainId })
}); });
const data = await response.json(); const data = await response.json();
if (response.ok) { if (response.ok) {
@ -314,7 +296,7 @@ class ModelMonitor extends HTMLElement {
// 如果监控未运行,直接返回 // 如果监控未运行,直接返回
if (!statusData.isMonitoring) { if (!statusData.isMonitoring) {
console.log('监控未运行,无需关闭'); //console.log('监控未运行,无需关闭');
return; return;
} }

View File

@ -1225,15 +1225,6 @@ class RunSim extends HTMLElement {
this.currentSimulationId = null; this.currentSimulationId = null;
this.showSuccess('仿真已停止'); this.showSuccess('仿真已停止');
// 关闭系统监控
try {
await fetch('/api/system-monitor/stop', {
method: 'POST'
});
} catch (error) {
}
// 关闭DDS监控 // 关闭DDS监控
try { try {
await fetch('/api/dds-monitor/unregister', { await fetch('/api/dds-monitor/unregister', {

View File

@ -123,37 +123,19 @@ class SimulationMonitor extends HTMLElement {
} }
try { 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监控状态 // 首先检查DDS监控状态
const ddsStatusResponse = await fetch('/api/dds-monitor/status'); const ddsStatusResponse = await fetch('/api/dds-monitor/status');
const ddsStatusData = await ddsStatusResponse.json(); const ddsStatusData = await ddsStatusResponse.json();
// 如果DDS监控未初始化直接返回等待下次定时器运行时再检查 // 如果DDS监控未初始化直接返回等待下次定时器运行时再检查
if (!ddsStatusData.isInitialized) { if (!ddsStatusData.isInitialized) {
console.log('DDS监控未初始化等待下次检查'); //console.log('DDS监控未初始化等待下次检查');
return; return;
} }
// 启动系统监控 // 启动系统监控
const response = await fetch('/api/system-monitor/start', { const response = await fetch('/api/system-monitor/start', {
method: 'POST', method: 'POST'
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ domainId })
}); });
const data = await response.json(); const data = await response.json();
if (response.ok) { if (response.ok) {
@ -385,7 +367,7 @@ class SimulationMonitor extends HTMLElement {
// 如果监控未运行,直接返回 // 如果监控未运行,直接返回
if (!statusData.isMonitoring) { if (!statusData.isMonitoring) {
console.log('监控未运行,无需关闭'); //console.log('监控未运行,无需关闭');
return; return;
} }