feat: 增加升级说明页,退出弹窗默认选退出系统

This commit is contained in:
Nixevol
2026-11-18 10:22:53 +08:00
parent 3670a76dfe
commit 71373839c6
6 changed files with 119 additions and 5 deletions
+12 -1
View File
@@ -17,7 +17,7 @@ logging.getLogger("httpcore").setLevel(logging.WARNING)
from fastapi import Depends, FastAPI, HTTPException, Request, Response, WebSocket, WebSocketDisconnect from fastapi import Depends, FastAPI, HTTPException, Request, Response, WebSocket, WebSocketDisconnect
from fastapi.exceptions import RequestValidationError from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse from fastapi.responses import FileResponse, JSONResponse
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
@@ -674,5 +674,16 @@ class _WebFiles(StaticFiles):
_dist = Path(__file__).resolve().parents[2] / "web" / "dist" _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(): if _dist.is_dir():
app.mount("/", _WebFiles(directory=_dist, html=True), name="web") app.mount("/", _WebFiles(directory=_dist, html=True), name="web")
+9
View File
@@ -1220,3 +1220,12 @@ def test_exam_list_rejects_unrecognized_page() -> None:
client.client = HTTP() client.client = HTTP()
with pytest.raises(RuntimeError, match="考试列表没有获取到"): with pytest.raises(RuntimeError, match="考试列表没有获取到"):
client.my_exams() 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"
+5 -1
View File
@@ -3,6 +3,7 @@ import { onMounted, onUnmounted, ref } from "vue";
import { apiFetch, setSessionDenied } from "./shared/http"; import { apiFetch, setSessionDenied } from "./shared/http";
import { darkTheme, dateZhCN, NButton, NConfigProvider, NDialogProvider, zhCN } from "naive-ui"; import { darkTheme, dateZhCN, NButton, NConfigProvider, NDialogProvider, zhCN } from "naive-ui";
import LoginView from "./features/auth/LoginView.vue"; import LoginView from "./features/auth/LoginView.vue";
import NoticeView from "./features/notice/NoticeView.vue";
import Shell from "./shell/Shell.vue"; import Shell from "./shell/Shell.vue";
import AdminShell from "./shell/AdminShell.vue"; import AdminShell from "./shell/AdminShell.vue";
import { isDark, themeOverrides } from "./shared/theme"; import { isDark, themeOverrides } from "./shared/theme";
@@ -11,6 +12,7 @@ import { sessionFromPayload, type AppSession } from "./shared/session";
const ready = ref(false); const ready = ref(false);
const session = ref<AppSession | null>(null); const session = ref<AppSession | null>(null);
const sessionError = ref(""); const sessionError = ref("");
const isNotice = window.location.pathname.replace(/\/+$/, "") === "/msg01";
function applyPayload(payload: unknown) { function applyPayload(payload: unknown) {
if (!payload || typeof payload !== "object") return null; if (!payload || typeof payload !== "object") return null;
@@ -44,6 +46,7 @@ async function loadSession() {
} }
onMounted(() => { onMounted(() => {
if (isNotice) return;
setSessionDenied(() => { setSessionDenied(() => {
void loadSession(); void loadSession();
}); });
@@ -109,7 +112,8 @@ function onLogin(next: AppSession) {
<template> <template>
<n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides"> <n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
<n-dialog-provider> <NoticeView v-if="isNotice" />
<n-dialog-provider v-else>
<div v-if="ready && sessionError && !session" class="gate"> <div v-if="ready && sessionError && !session" class="gate">
<section class="gate-card"> <section class="gate-card">
<p class="session-note">暂时无法确认登录状态</p> <p class="session-note">暂时无法确认登录状态</p>
+49
View File
@@ -0,0 +1,49 @@
<script setup lang="ts">
import { ref } from "vue";
import { NButton } from "naive-ui";
const toolUrl = "https://euniv.asio.asia";
const copied = ref(false);
let copiedTimer = 0;
async function copyUrl() {
try {
await navigator.clipboard.writeText(toolUrl);
} catch {
const box = document.createElement("textarea");
box.value = toolUrl;
box.setAttribute("readonly", "");
box.style.position = "fixed";
box.style.left = "-9999px";
document.body.appendChild(box);
box.select();
document.execCommand("copy");
box.remove();
}
copied.value = true;
window.clearTimeout(copiedTimer);
copiedTimer = window.setTimeout(() => {
copied.value = false;
}, 2000);
}
function openTool() {
const opened = window.open(toolUrl, "_blank", "noopener");
if (!opened) window.location.assign(toolUrl);
}
</script>
<template>
<main class="notice-page">
<section class="notice-card">
<h1>旧版工具已失效</h1>
<p>因目标平台升级,旧版工具已失效,无法登录使用。</p>
<p>新版工具已上线,请访问:</p>
<p class="notice-url">{{ toolUrl }}</p>
<div class="notice-actions">
<n-button type="primary" @click="openTool">打开新版工具</n-button>
<n-button @click="copyUrl">{{ copied ? "已复制" : "复制地址" }}</n-button>
</div>
</section>
</main>
</template>
+2 -3
View File
@@ -15,7 +15,7 @@ const page = ref<PageKey>(pageFromHash());
const collapsed = ref(window.innerWidth < 800); const collapsed = ref(window.innerWidth < 800);
const holdOpen = ref(false); const holdOpen = ref(false);
const leaveOpen = ref(false); const leaveOpen = ref(false);
const leaveChoice = ref<"logout" | "revoke" | null>(null); const leaveChoice = ref<"logout" | "revoke">("logout");
const pages = new Set<PageKey>(["home", "history", "exams", "trainings"]); const pages = new Set<PageKey>(["home", "history", "exams", "trainings"]);
function hashName() { function hashName() {
@@ -79,7 +79,7 @@ function onMenu(key: string) {
} }
function openLeave() { function openLeave() {
leaveChoice.value = null; leaveChoice.value = "logout";
leaveOpen.value = true; leaveOpen.value = true;
} }
@@ -163,7 +163,6 @@ function confirmLeave() {
<n-button @click="leaveOpen = false">取消</n-button> <n-button @click="leaveOpen = false">取消</n-button>
<n-button <n-button
:type="leaveChoice === 'revoke' ? 'error' : 'primary'" :type="leaveChoice === 'revoke' ? 'error' : 'primary'"
:disabled="leaveChoice === null"
@click="confirmLeave" @click="confirmLeave"
> >
{{ leaveChoice === "revoke" ? "注销账号" : "退出系统" }} {{ leaveChoice === "revoke" ? "注销账号" : "退出系统" }}
+42
View File
@@ -1657,6 +1657,48 @@ select {
line-height: 1.6; line-height: 1.6;
} }
.notice-page {
min-height: 100%;
display: grid;
place-items: center;
padding: 32px 16px;
}
.notice-card {
width: min(440px, 100%);
padding: 28px 24px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
}
.notice-card h1 {
margin: 0 0 16px;
font-size: 22px;
font-weight: 650;
}
.notice-card p {
margin: 0 0 12px;
line-height: 1.6;
}
.notice-url {
margin: 0 0 20px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--elevated);
color: var(--accent);
word-break: break-all;
user-select: all;
}
.notice-actions {
display: flex;
gap: 8px;
}
.app-root { .app-root {
position: relative; position: relative;
} }