feat: 添加刷新间隔时间设置,支持自定义刷新频率
This commit is contained in:
29
app.py
29
app.py
@@ -248,6 +248,13 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
<button onclick="refreshAll()" class="btn bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded-lg flex items-center gap-2">
|
||||
<i class="ri-refresh-line"></i> 刷新状态
|
||||
</button>
|
||||
<div class="flex items-center gap-1">
|
||||
<span class="text-gray-400 text-xs">间隔:</span>
|
||||
<input type="number" id="refreshInterval" value="30" min="5" max="300"
|
||||
class="bg-gray-700 text-gray-200 px-2 py-1 rounded text-xs w-12"
|
||||
onchange="updateRefreshInterval()" title="刷新间隔(秒)">
|
||||
<span class="text-gray-500 text-xs">s</span>
|
||||
</div>
|
||||
<span id="updateTime" class="text-gray-400 text-sm"></span>
|
||||
<div id="connectionStatus" class="flex items-center gap-1 px-2 py-1 rounded bg-green-500/20">
|
||||
<div class="w-2 h-2 rounded-full bg-green-400 animate-pulse"></div>
|
||||
@@ -740,8 +747,26 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
|
||||
loadProjects();
|
||||
loadCrons();
|
||||
|
||||
// 每30秒自动刷新
|
||||
setInterval(loadProjects, 30000);
|
||||
// 动态刷新间隔
|
||||
let refreshIntervalMs = parseInt(localStorage.getItem('refreshInterval') || '30') * 1000;
|
||||
document.getElementById('refreshInterval').value = refreshIntervalMs / 1000;
|
||||
|
||||
let refreshTimer = setInterval(loadProjects, refreshIntervalMs);
|
||||
|
||||
function updateRefreshInterval() {
|
||||
const seconds = parseInt(document.getElementById('refreshInterval').value) || 30;
|
||||
const clampedSeconds = Math.max(5, Math.min(300, seconds)); // 限制5-300秒
|
||||
document.getElementById('refreshInterval').value = clampedSeconds;
|
||||
|
||||
localStorage.setItem('refreshInterval', clampedSeconds);
|
||||
refreshIntervalMs = clampedSeconds * 1000;
|
||||
|
||||
// 清除旧定时器,设置新定时器
|
||||
clearInterval(refreshTimer);
|
||||
refreshTimer = setInterval(loadProjects, refreshIntervalMs);
|
||||
|
||||
console.log('刷新间隔已更新为:', clampedSeconds, '秒');
|
||||
}
|
||||
|
||||
// 每10秒检查连接状态
|
||||
setInterval(checkConnection, 10000);
|
||||
|
||||
Reference in New Issue
Block a user