fix: 从配置读取刷新间隔,保存设置后立即生效
This commit is contained in:
@@ -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();
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user