mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-20 03:30:50 +08:00
feat(logs): refresh on reconnect and section activation
This commit is contained in:
5
app.js
5
app.js
@@ -67,6 +67,7 @@ class CLIProxyManager {
|
|||||||
|
|
||||||
// 状态更新定时器
|
// 状态更新定时器
|
||||||
this.statusUpdateTimer = null;
|
this.statusUpdateTimer = null;
|
||||||
|
this.lastConnectionStatusEmitted = null;
|
||||||
|
|
||||||
// 日志自动刷新定时器
|
// 日志自动刷新定时器
|
||||||
this.logsRefreshTimer = null;
|
this.logsRefreshTimer = null;
|
||||||
@@ -150,6 +151,9 @@ class CLIProxyManager {
|
|||||||
this.initializeTheme();
|
this.initializeTheme();
|
||||||
this.registerSettingsListeners();
|
this.registerSettingsListeners();
|
||||||
this.registerUsageListeners();
|
this.registerUsageListeners();
|
||||||
|
if (typeof this.registerLogsListeners === 'function') {
|
||||||
|
this.registerLogsListeners();
|
||||||
|
}
|
||||||
if (typeof this.registerConfigEditorListeners === 'function') {
|
if (typeof this.registerConfigEditorListeners === 'function') {
|
||||||
this.registerConfigEditorListeners();
|
this.registerConfigEditorListeners();
|
||||||
}
|
}
|
||||||
@@ -164,7 +168,6 @@ class CLIProxyManager {
|
|||||||
this.updateLoginConnectionInfo();
|
this.updateLoginConnectionInfo();
|
||||||
// 检查主机名,如果不是 localhost 或 127.0.0.1,则隐藏 OAuth 登录框
|
// 检查主机名,如果不是 localhost 或 127.0.0.1,则隐藏 OAuth 登录框
|
||||||
this.checkHostAndHideOAuth();
|
this.checkHostAndHideOAuth();
|
||||||
|
|
||||||
if (typeof this.registerAuthFilesListeners === 'function') {
|
if (typeof this.registerAuthFilesListeners === 'function') {
|
||||||
this.registerAuthFilesListeners();
|
this.registerAuthFilesListeners();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,10 +215,14 @@ export const connectionModule = {
|
|||||||
this.updateConnectionInfo();
|
this.updateConnectionInfo();
|
||||||
|
|
||||||
if (this.events && typeof this.events.emit === 'function') {
|
if (this.events && typeof this.events.emit === 'function') {
|
||||||
|
const shouldEmit = this.lastConnectionStatusEmitted !== this.isConnected;
|
||||||
|
if (shouldEmit) {
|
||||||
this.events.emit('connection:status-changed', {
|
this.events.emit('connection:status-changed', {
|
||||||
isConnected: this.isConnected,
|
isConnected: this.isConnected,
|
||||||
apiBase: this.apiBase
|
apiBase: this.apiBase
|
||||||
});
|
});
|
||||||
|
this.lastConnectionStatusEmitted = this.isConnected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -325,9 +329,6 @@ export const connectionModule = {
|
|||||||
// 从配置中提取并设置各个设置项(现在传递keyStats)
|
// 从配置中提取并设置各个设置项(现在传递keyStats)
|
||||||
await this.updateSettingsFromConfig(config, keyStats);
|
await this.updateSettingsFromConfig(config, keyStats);
|
||||||
|
|
||||||
// 认证文件需要单独加载,因为不在配置中
|
|
||||||
await this.loadAuthFiles(keyStats);
|
|
||||||
|
|
||||||
if (this.events && typeof this.events.emit === 'function') {
|
if (this.events && typeof this.events.emit === 'function') {
|
||||||
this.events.emit('data:config-loaded', {
|
this.events.emit('data:config-loaded', {
|
||||||
config,
|
config,
|
||||||
|
|||||||
@@ -406,5 +406,29 @@ export const logsModule = {
|
|||||||
}
|
}
|
||||||
this.showNotification(i18n.t('logs.auto_refresh_disabled'), 'info');
|
this.showNotification(i18n.t('logs.auto_refresh_disabled'), 'info');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
registerLogsListeners() {
|
||||||
|
if (!this.events || typeof this.events.on !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.events.on('connection:status-changed', (event) => {
|
||||||
|
const detail = event?.detail || {};
|
||||||
|
if (detail.isConnected) {
|
||||||
|
// 仅在日志页激活时刷新,避免非日志页面触发请求
|
||||||
|
const logsSection = document.getElementById('logs');
|
||||||
|
if (logsSection && logsSection.classList.contains('active')) {
|
||||||
|
this.refreshLogs(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.latestLogTimestamp = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.events.on('navigation:section-activated', (event) => {
|
||||||
|
const detail = event?.detail || {};
|
||||||
|
if (detail.sectionId === 'logs' && this.isConnected) {
|
||||||
|
this.refreshLogs(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ export const navigationModule = {
|
|||||||
section.classList.add('active');
|
section.classList.add('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sectionId === 'logs') {
|
if (sectionId === 'config-management') {
|
||||||
this.refreshLogs(false);
|
|
||||||
} else if (sectionId === 'config-management') {
|
|
||||||
this.loadConfigFileEditor();
|
this.loadConfigFileEditor();
|
||||||
this.refreshConfigEditor();
|
this.refreshConfigEditor();
|
||||||
}
|
}
|
||||||
|
if (this.events && typeof this.events.emit === 'function') {
|
||||||
|
this.events.emit('navigation:section-activated', { sectionId });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user