监控页:后端 30s 缓存 + 前端 loading 态

This commit is contained in:
2569718930@qq.com
2026-05-14 00:29:51 +08:00
parent 2202f8e211
commit c5fdb93ae5
2 changed files with 18 additions and 2 deletions
@@ -33,7 +33,7 @@ function parseRunway(html: string): RunwayPair[] {
}
export default function MonitorPanel() {
const [cities, setCities] = useState<CitySnapshot[]>([]);
const [cities, setCities] = useState<CitySnapshot[] | null>(null);
const [time, setTime] = useState("");
const [notify, setNotify] = useState(
() => typeof window !== "undefined" && localStorage.getItem("monitor_notify") !== "off"
@@ -87,6 +87,11 @@ export default function MonitorPanel() {
</div>
{/* Card Grid */}
{cities === null ? (
<div style={{ color: "#5a6170", textAlign: "center", padding: 60, fontSize: 15 }}>
Loading
</div>
) : (
<div style={{
display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(340px, 1fr))",
gap: 14,
@@ -173,6 +178,7 @@ export default function MonitorPanel() {
);
})}
</div>
)}
</div>
);
}
+11 -1
View File
@@ -118,6 +118,16 @@ def _build_cards() -> list:
return cards
_cache = None
_cache_ts = 0
@router.get("/m/json")
async def monitor_json():
return _build_cards()
global _cache, _cache_ts
now = __import__("time").time()
if _cache is not None and now - _cache_ts < 30:
return _cache
_cache = _build_cards()
_cache_ts = now
return _cache