监控页:后端 30s 缓存 + 前端 loading 态
This commit is contained in:
@@ -33,7 +33,7 @@ function parseRunway(html: string): RunwayPair[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function MonitorPanel() {
|
export default function MonitorPanel() {
|
||||||
const [cities, setCities] = useState<CitySnapshot[]>([]);
|
const [cities, setCities] = useState<CitySnapshot[] | null>(null);
|
||||||
const [time, setTime] = useState("");
|
const [time, setTime] = useState("");
|
||||||
const [notify, setNotify] = useState(
|
const [notify, setNotify] = useState(
|
||||||
() => typeof window !== "undefined" && localStorage.getItem("monitor_notify") !== "off"
|
() => typeof window !== "undefined" && localStorage.getItem("monitor_notify") !== "off"
|
||||||
@@ -87,6 +87,11 @@ export default function MonitorPanel() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Card Grid */}
|
{/* Card Grid */}
|
||||||
|
{cities === null ? (
|
||||||
|
<div style={{ color: "#5a6170", textAlign: "center", padding: 60, fontSize: 15 }}>
|
||||||
|
Loading…
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div style={{
|
<div style={{
|
||||||
display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(340px, 1fr))",
|
display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(340px, 1fr))",
|
||||||
gap: 14,
|
gap: 14,
|
||||||
@@ -173,6 +178,7 @@ export default function MonitorPanel() {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-1
@@ -118,6 +118,16 @@ def _build_cards() -> list:
|
|||||||
return cards
|
return cards
|
||||||
|
|
||||||
|
|
||||||
|
_cache = None
|
||||||
|
_cache_ts = 0
|
||||||
|
|
||||||
|
|
||||||
@router.get("/m/json")
|
@router.get("/m/json")
|
||||||
async def monitor_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
|
||||||
|
|||||||
Reference in New Issue
Block a user