fix: 切换学时依据后立刻刷新,历史页不再拉整页首页

This commit is contained in:
2026-11-16 15:25:16 +08:00
parent 05f2396e35
commit 33640f7da8
4 changed files with 62 additions and 6 deletions
+26 -3
View File
@@ -378,10 +378,18 @@ def fetch_home_trainings(db: Session, employee_id: str, client_factory=EunivClie
def fetch_exam_detail(db: Session, employee_id: str, path: str, client_factory=EunivClient) -> dict:
from euniv.client import exam_path_ok
if not exam_path_ok(path):
raise RuntimeError("考试明细无法打开")
return _live(db, employee_id, client_factory, lambda client: client.exam_detail(path))
def fetch_training_detail(db: Session, employee_id: str, path: str, client_factory=EunivClient) -> dict:
from euniv.client import training_path_ok
if not training_path_ok(path):
raise RuntimeError("培训明细无法打开")
return _live(db, employee_id, client_factory, lambda client: client.training_detail(path))
@@ -420,7 +428,8 @@ def _api_hour_fields(client) -> dict:
if hours_source_of() == "history":
return {}
summary = client.home_summary()
reader = getattr(client, "hour_fields", None)
summary = reader() if reader is not None else client.home_summary()
return {
"year_hours": summary.get("year_hours"),
"month_hours": summary.get("month_hours"),
@@ -636,16 +645,22 @@ class _RefreshGate:
self._reason = "wake"
self._event.set()
def refresh_now(self) -> None:
with self._lock:
if self._reason != "stop":
self._reason = "now"
self._event.set()
def wait(self, seconds: float) -> str:
self._event.wait(timeout=max(0.0, seconds))
with self._lock:
reason = self._reason
if reason == "stop":
return "stop"
if reason == "wake":
if reason in {"wake", "now"}:
self._reason = ""
self._event.clear()
return "wake"
return reason
return "timeout"
@@ -664,6 +679,14 @@ def notify_refresh_interval_changed() -> None:
_gate.wake()
def notify_hours_source_changed() -> None:
"""学时依据变了,立刻再刷新一轮已保存的学时。"""
if _gate is not None:
_gate.refresh_now()
return
threading.Thread(target=refresh_stored_credentials, name="euniv-hours-source", daemon=True).start()
def start_credential_refresh() -> _RefreshGate:
global _gate
gate = _RefreshGate()