fix: 从配置读取刷新间隔,保存设置后立即生效

This commit is contained in:
2026-04-16 11:50:06 +08:00
parent 4eeb144da1
commit 6c7b180f2c

View File

@@ -6,15 +6,29 @@ var refreshTimer = null;
// Initialize
document.addEventListener('DOMContentLoaded', function() {
loadConfig();
refreshAll();
startAutoRefresh();
});
function startAutoRefresh() {
function loadConfig() {
fetch(API_BASE + '/api/config')
.then(function(res) { return res.json(); })
.then(function(config) {
var interval = config.refresh_interval || 5;
startAutoRefresh(interval);
document.getElementById('refresh-info').textContent = 'Refresh: ' + interval + 's';
})
.catch(function(e) {
console.error('Load config failed:', e);
startAutoRefresh(5);
});
}
function startAutoRefresh(intervalSeconds) {
if (refreshTimer) {
clearInterval(refreshTimer);
}
refreshTimer = setInterval(refreshAll, 5000);
refreshTimer = setInterval(refreshAll, intervalSeconds * 1000);
}
function refreshAll() {
@@ -323,6 +337,8 @@ function saveSettings() {
if (data.success) {
alert('Settings saved!');
closeSettingsModal();
// Reload config to apply new refresh interval
loadConfig();
refreshAll();
}
})