From 71373839c6e9179b2f0741e02c1cb271c0e69d35 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Wed, 18 Nov 2026 10:22:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E9=A1=B5=EF=BC=8C=E9=80=80=E5=87=BA=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E9=BB=98=E8=AE=A4=E9=80=89=E9=80=80=E5=87=BA=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/euniv/api.py | 13 ++++++- backend/tests/test_api.py | 9 +++++ web/src/App.vue | 6 +++- web/src/features/notice/NoticeView.vue | 49 ++++++++++++++++++++++++++ web/src/shell/Shell.vue | 5 ++- web/src/styles.css | 42 ++++++++++++++++++++++ 6 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 web/src/features/notice/NoticeView.vue diff --git a/backend/euniv/api.py b/backend/euniv/api.py index df6c8b3..c97993a 100644 --- a/backend/euniv/api.py +++ b/backend/euniv/api.py @@ -17,7 +17,7 @@ logging.getLogger("httpcore").setLevel(logging.WARNING) from fastapi import Depends, FastAPI, HTTPException, Request, Response, WebSocket, WebSocketDisconnect from fastapi.exceptions import RequestValidationError -from fastapi.responses import JSONResponse +from fastapi.responses import FileResponse, JSONResponse from fastapi.staticfiles import StaticFiles from pydantic import BaseModel, Field from sqlalchemy.orm import Session @@ -674,5 +674,16 @@ class _WebFiles(StaticFiles): _dist = Path(__file__).resolve().parents[2] / "web" / "dist" + + +@app.get("/msg01", include_in_schema=False) +@app.get("/msg01/", include_in_schema=False) +def notice_page() -> FileResponse: + index = _dist / "index.html" + if not index.is_file(): + raise HTTPException(status_code=404, detail="页面不存在") + return FileResponse(index, headers={"Cache-Control": "no-cache"}) + + if _dist.is_dir(): app.mount("/", _WebFiles(directory=_dist, html=True), name="web") diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 36f5b0a..f7b903a 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -1220,3 +1220,12 @@ def test_exam_list_rejects_unrecognized_page() -> None: client.client = HTTP() with pytest.raises(RuntimeError, match="考试列表没有获取到"): client.my_exams() + + +def test_notice_page_is_reachable_only_by_its_address() -> None: + import euniv.api as api_module + + response = TestClient(api_module.app).get("/msg01") + assert response.status_code == 200 + assert 'id="app"' in response.text + assert response.headers["cache-control"] == "no-cache" diff --git a/web/src/App.vue b/web/src/App.vue index dc76800..44d6ec7 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -3,6 +3,7 @@ import { onMounted, onUnmounted, ref } from "vue"; import { apiFetch, setSessionDenied } from "./shared/http"; import { darkTheme, dateZhCN, NButton, NConfigProvider, NDialogProvider, zhCN } from "naive-ui"; import LoginView from "./features/auth/LoginView.vue"; +import NoticeView from "./features/notice/NoticeView.vue"; import Shell from "./shell/Shell.vue"; import AdminShell from "./shell/AdminShell.vue"; import { isDark, themeOverrides } from "./shared/theme"; @@ -11,6 +12,7 @@ import { sessionFromPayload, type AppSession } from "./shared/session"; const ready = ref(false); const session = ref(null); const sessionError = ref(""); +const isNotice = window.location.pathname.replace(/\/+$/, "") === "/msg01"; function applyPayload(payload: unknown) { if (!payload || typeof payload !== "object") return null; @@ -44,6 +46,7 @@ async function loadSession() { } onMounted(() => { + if (isNotice) return; setSessionDenied(() => { void loadSession(); }); @@ -109,7 +112,8 @@ function onLogin(next: AppSession) {