feat: 管理界面新增数据浏览页(服务端分页)

- 新增「数据」页:按制式筛选、CGI/小区名称搜索、四种排序,每页 20/50/100 条,数据库端 LIMIT/OFFSET 分页,越界页自动回退到最后一页
- 点击行查看详情:基础字段与 1 公里内高干扰小区数的本期/上期分制式对比
- 首次打开该页才加载,新批次入库后自动刷新;加载中状态与过期请求丢弃,避免界面卡顿
- 新增 GET /api/data 接口(仅管理员),读取失败返回 502
- MySQL 直连与 Metrix 接口两种模式都支持只读查询,接口模式浏览查询超时 20 秒;两种模式数值格式统一
- 搜索词转义引号与 LIKE 通配符,制式、排序、页大小走白名单
- 补充单元测试与中英文文案
This commit is contained in:
2026-11-06 18:02:36 +08:00
parent b487a54b94
commit 4fb44ab27a
10 changed files with 603 additions and 7 deletions
+16
View File
@@ -11,6 +11,7 @@ from fastapi.responses import HTMLResponse, JSONResponse, PlainTextResponse
from .auth import Identity, require_admin
from .config import SettingsError, data_dir, public_view
from .data import DataQuery
from .service import EtlService
LANDING_HTML = """<!doctype html>
@@ -82,6 +83,21 @@ def build_api(service: EtlService) -> FastAPI:
def cancel_run(_: Identity = Depends(require_admin)) -> dict[str, bool]:
return {"cancelled": service.runner.cancel()}
@api.get("/api/data", response_model=None)
def data(
page: int = 1,
page_size: int = 20,
network: str = "",
q: str = "",
sort: str = "interference",
_: Identity = Depends(require_admin),
) -> Any:
query = DataQuery(page=page, page_size=page_size, network=network, keyword=q, sort=sort)
try:
return service.data.browse(query)
except Exception as exc:
return JSONResponse(status_code=502, content={"error": "data_unavailable", "detail": str(exc)[:500]})
@api.get("/api/runs/{run_id}/log", response_class=PlainTextResponse)
def run_log(run_id: int, _: Identity = Depends(require_admin)) -> str:
if service.runs.get(run_id) is None: