chore: sync local changes to Gitea
This commit is contained in:
21
frontend/index.html
Normal file
21
frontend/index.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
||||
<link rel="apple-touch-icon" href="/logo192.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#27ae60" />
|
||||
<meta name="description" content="大模型 API 可用性与首字延迟监控" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||
<meta name="apple-mobile-web-app-title" content="ModelPing" />
|
||||
<title>ModelPing</title>
|
||||
<!-- 字体改由 Vite 从本地 node_modules 打包,避免 jsdelivr 被跟踪防护拦截、减少首屏外链请求 -->
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
23
frontend/src/App.tsx
Normal file
23
frontend/src/App.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
|
||||
import { Layout } from "./components/Layout";
|
||||
import { PwaUpdatePrompt } from "./components/PwaUpdatePrompt";
|
||||
import { AppBootProvider } from "./context/AppBootContext";
|
||||
import { Admin } from "./pages/Admin";
|
||||
import { Dashboard } from "./pages/Dashboard";
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<AppBootProvider>
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route element={<Layout />}>
|
||||
<Route index element={<Dashboard />} />
|
||||
<Route path="admin" element={<Admin />} />
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<PwaUpdatePrompt />
|
||||
</BrowserRouter>
|
||||
</AppBootProvider>
|
||||
);
|
||||
}
|
||||
148
frontend/src/api.ts
Normal file
148
frontend/src/api.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
import type { GlobalProbeSettings, MonitorDto, MonitorProtocol } from "./types";
|
||||
import { getAdminToken } from "./types";
|
||||
|
||||
export async function fetchMonitors(): Promise<MonitorDto[]> {
|
||||
const r = await fetch("/api/monitors", { cache: "no-store" });
|
||||
if (!r.ok) throw new Error("failed_to_load");
|
||||
return r.json() as Promise<MonitorDto[]>;
|
||||
}
|
||||
|
||||
export type AdminPingResult =
|
||||
| { ok: true }
|
||||
| { ok: false; reason: "not_configured" | "unauthorized" | "network" };
|
||||
|
||||
export async function adminPing(token: string): Promise<AdminPingResult> {
|
||||
try {
|
||||
const r = await fetch("/api/admin/ping", {
|
||||
headers: { Authorization: `Bearer ${token.trim()}` },
|
||||
});
|
||||
if (r.ok) return { ok: true };
|
||||
if (r.status === 503) return { ok: false, reason: "not_configured" };
|
||||
return { ok: false, reason: "unauthorized" };
|
||||
} catch {
|
||||
return { ok: false, reason: "network" };
|
||||
}
|
||||
}
|
||||
|
||||
export async function adminListMonitors(): Promise<MonitorDto[]> {
|
||||
const t = getAdminToken();
|
||||
if (!t) throw new Error("no_token");
|
||||
const r = await fetch("/api/admin/monitors", {
|
||||
cache: "no-store",
|
||||
headers: { Authorization: `Bearer ${t}` },
|
||||
});
|
||||
if (!r.ok) throw new Error("admin_list_failed");
|
||||
return r.json() as Promise<MonitorDto[]>;
|
||||
}
|
||||
|
||||
export async function adminGetProbeSettings(): Promise<GlobalProbeSettings> {
|
||||
const t = getAdminToken();
|
||||
if (!t) throw new Error("no_token");
|
||||
const r = await fetch("/api/admin/probe-settings", { headers: { Authorization: `Bearer ${t}` } });
|
||||
if (!r.ok) throw new Error("settings_load_failed");
|
||||
return r.json() as Promise<GlobalProbeSettings>;
|
||||
}
|
||||
|
||||
export async function adminSaveProbeSettings(patch: Partial<GlobalProbeSettings>): Promise<void> {
|
||||
const t = getAdminToken();
|
||||
if (!t) throw new Error("no_token");
|
||||
const r = await fetch("/api/admin/probe-settings", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${t}` },
|
||||
body: JSON.stringify(patch),
|
||||
});
|
||||
let body: { error?: string; message?: string } = {};
|
||||
try {
|
||||
body = (await r.json()) as { error?: string; message?: string };
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
if (!r.ok) {
|
||||
const parts = [typeof body.error === "string" ? body.error : null, typeof body.message === "string" ? body.message : null]
|
||||
.filter(Boolean)
|
||||
.join(": ");
|
||||
throw new Error(parts || `保存失败(HTTP ${r.status})`);
|
||||
}
|
||||
}
|
||||
|
||||
type CreateBody = {
|
||||
display_name: string;
|
||||
api_base_url: string;
|
||||
api_key: string;
|
||||
model: string;
|
||||
protocol: MonitorProtocol;
|
||||
category?: string;
|
||||
enabled?: boolean;
|
||||
probe_stream?: boolean;
|
||||
show_on_dashboard?: boolean;
|
||||
};
|
||||
|
||||
export async function adminCreateMonitor(body: CreateBody): Promise<string> {
|
||||
const t = getAdminToken();
|
||||
if (!t) throw new Error("no_token");
|
||||
const r = await fetch("/api/admin/monitors", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${t}` },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!r.ok) throw new Error("create_failed");
|
||||
const j = (await r.json()) as { id: string };
|
||||
return j.id;
|
||||
}
|
||||
|
||||
export async function adminUpdateMonitor(
|
||||
id: string,
|
||||
patch: Partial<CreateBody> & { api_key?: string }
|
||||
): Promise<void> {
|
||||
const t = getAdminToken();
|
||||
if (!t) throw new Error("no_token");
|
||||
const r = await fetch(`/api/admin/monitors/${id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${t}` },
|
||||
body: JSON.stringify(patch),
|
||||
});
|
||||
let body: { error?: string; message?: string } = {};
|
||||
try {
|
||||
body = (await r.json()) as { error?: string; message?: string };
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
if (!r.ok) {
|
||||
const parts = [typeof body.error === "string" ? body.error : null, typeof body.message === "string" ? body.message : null]
|
||||
.filter(Boolean)
|
||||
.join(": ");
|
||||
throw new Error(parts || `保存失败(HTTP ${r.status})`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function adminDeleteMonitor(id: string): Promise<void> {
|
||||
const t = getAdminToken();
|
||||
if (!t) throw new Error("no_token");
|
||||
const r = await fetch(`/api/admin/monitors/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: { Authorization: `Bearer ${t}` },
|
||||
});
|
||||
if (!r.ok) throw new Error("delete_failed");
|
||||
}
|
||||
|
||||
export async function adminRunMonitor(id: string): Promise<void> {
|
||||
const t = getAdminToken();
|
||||
if (!t) throw new Error("no_token");
|
||||
const r = await fetch(`/api/admin/monitors/${id}/run`, {
|
||||
method: "POST",
|
||||
headers: { Authorization: `Bearer ${t}` },
|
||||
});
|
||||
let body: { ok?: boolean; error?: string } = {};
|
||||
try {
|
||||
body = (await r.json()) as { ok?: boolean; error?: string };
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
if (!r.ok) {
|
||||
const msg = typeof body.error === "string" && body.error ? body.error : "run_failed";
|
||||
throw new Error(msg);
|
||||
}
|
||||
if (body.ok === false) {
|
||||
throw new Error(typeof body.error === "string" && body.error ? body.error : "run_failed");
|
||||
}
|
||||
}
|
||||
BIN
frontend/src/assets/hero.png
Normal file
BIN
frontend/src/assets/hero.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
1
frontend/src/assets/react.svg
Normal file
1
frontend/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
1
frontend/src/assets/vite.svg
Normal file
1
frontend/src/assets/vite.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
93
frontend/src/components/AdminTokenDialog.tsx
Normal file
93
frontend/src/components/AdminTokenDialog.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||
import { adminPing } from "../api";
|
||||
import { setAdminToken } from "../types";
|
||||
|
||||
type Props = {
|
||||
onClose: () => void;
|
||||
onSuccess: () => void;
|
||||
};
|
||||
|
||||
function pingErrorMessage(result: Exclude<Awaited<ReturnType<typeof adminPing>>, { ok: true }>): string {
|
||||
if (result.ok) return "";
|
||||
switch (result.reason) {
|
||||
case "not_configured":
|
||||
return "服务端未配置 ADMIN_TOKEN";
|
||||
case "unauthorized":
|
||||
return "Token 不正确";
|
||||
case "network":
|
||||
return "无法连接校验接口";
|
||||
default:
|
||||
return "校验失败";
|
||||
}
|
||||
}
|
||||
|
||||
export function AdminTokenDialog({ onClose, onSuccess }: Props) {
|
||||
const [token, setToken] = useState("");
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
inputRef.current?.focus();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") onClose();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [onClose]);
|
||||
|
||||
const submit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
const trimmed = token.trim();
|
||||
if (!trimmed) {
|
||||
setErr("请输入 Token");
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setErr(null);
|
||||
const result = await adminPing(trimmed);
|
||||
setBusy(false);
|
||||
if (result.ok === true) {
|
||||
setAdminToken(trimmed);
|
||||
onSuccess();
|
||||
return;
|
||||
}
|
||||
setErr(pingErrorMessage(result));
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="modal-backdrop admin-token-backdrop"
|
||||
role="presentation"
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget) onClose();
|
||||
}}
|
||||
>
|
||||
<form className="modal admin-token-modal" onSubmit={(e) => void submit(e)} onClick={(e) => e.stopPropagation()}>
|
||||
<p className="modal-title admin-token-title">管理 Token</p>
|
||||
<input
|
||||
ref={inputRef}
|
||||
className="modal-input admin-token-input"
|
||||
type="password"
|
||||
value={token}
|
||||
onChange={(e) => setToken(e.target.value)}
|
||||
placeholder="Token"
|
||||
autoComplete="off"
|
||||
disabled={busy}
|
||||
/>
|
||||
{err ? <p className="modal-err">{err}</p> : null}
|
||||
<div className="modal-actions">
|
||||
<button type="button" className="btn ghost small" onClick={onClose} disabled={busy}>
|
||||
取消
|
||||
</button>
|
||||
<button type="submit" className="btn primary small" disabled={busy}>
|
||||
{busy ? "校验中…" : "进入"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
53
frontend/src/components/BrandLogo.tsx
Normal file
53
frontend/src/components/BrandLogo.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import { useRef, useState, type PointerEvent } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { AdminTokenDialog } from "./AdminTokenDialog";
|
||||
|
||||
const LOGO_CLICKS = 5;
|
||||
const LOGO_CLICK_WINDOW_MS = 2000;
|
||||
|
||||
export function BrandLogo() {
|
||||
const navigate = useNavigate();
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const clicks = useRef({ count: 0, lastAt: 0 });
|
||||
|
||||
const onLogoPointerDown = (e: PointerEvent<HTMLImageElement>) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const now = Date.now();
|
||||
if (now - clicks.current.lastAt > LOGO_CLICK_WINDOW_MS) {
|
||||
clicks.current.count = 0;
|
||||
}
|
||||
clicks.current.lastAt = now;
|
||||
clicks.current.count += 1;
|
||||
|
||||
if (clicks.current.count >= LOGO_CLICKS) {
|
||||
clicks.current.count = 0;
|
||||
setDialogOpen(true);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<img
|
||||
className="brand-logo"
|
||||
src="/logo.png"
|
||||
alt=""
|
||||
width={40}
|
||||
height={40}
|
||||
decoding="async"
|
||||
onPointerDown={onLogoPointerDown}
|
||||
/>
|
||||
{dialogOpen ? (
|
||||
<AdminTokenDialog
|
||||
onClose={() => setDialogOpen(false)}
|
||||
onSuccess={() => {
|
||||
setDialogOpen(false);
|
||||
window.dispatchEvent(new Event("modelping:admin-auth"));
|
||||
void navigate("/admin", { replace: true });
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
56
frontend/src/components/Layout.tsx
Normal file
56
frontend/src/components/Layout.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link, Outlet } from "react-router-dom";
|
||||
import { BrandLogo } from "./BrandLogo";
|
||||
|
||||
const RANDBG_ORIGIN = "https://randbg.smyhub.com";
|
||||
const RANDBG_RANDOM_JSON = `${RANDBG_ORIGIN}/api/random?format=json&mode=desktop`;
|
||||
|
||||
function resolveRandBgUrl(raw: string): string {
|
||||
return /^https?:/i.test(raw) ? raw : new URL(raw, `${RANDBG_ORIGIN}/`).href;
|
||||
}
|
||||
|
||||
export function Layout() {
|
||||
const [bgUrl, setBgUrl] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const r = await fetch(RANDBG_RANDOM_JSON, { cache: "no-store" });
|
||||
if (!r.ok) throw new Error("randbg_status");
|
||||
const data = (await r.json()) as { url?: string };
|
||||
const u = typeof data.url === "string" ? data.url.trim() : "";
|
||||
if (!cancelled && u) {
|
||||
setBgUrl(resolveRandBgUrl(u));
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
/* fallback: 302 直链仍可作为 img src */
|
||||
}
|
||||
if (!cancelled) {
|
||||
setBgUrl(`${RANDBG_ORIGIN}/api/random?mode=desktop`);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="app-shell">
|
||||
{bgUrl ? (
|
||||
<img className="app-rand-bg" src={bgUrl} alt="" decoding="async" fetchPriority="low" />
|
||||
) : null}
|
||||
<header className="topbar">
|
||||
<Link to="/" className="brand" title="ModelPing">
|
||||
<BrandLogo />
|
||||
<span className="brand-text">ModelPing</span>
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
<main className="main-area">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
265
frontend/src/components/MonitorCard.tsx
Normal file
265
frontend/src/components/MonitorCard.tsx
Normal file
@@ -0,0 +1,265 @@
|
||||
import { useRef, type ReactNode } from "react";
|
||||
import type { MonitorDto } from "../types";
|
||||
|
||||
function formatPct(v: number | null): string {
|
||||
if (v == null) return "—";
|
||||
return `${v.toFixed(2)}%`;
|
||||
}
|
||||
|
||||
function protocolLabel(p: MonitorDto["protocol"]): string {
|
||||
if (p === "claude") return "Anthropic(/messages)";
|
||||
if (p === "openai_responses") return "OpenAI Responses(/v1/responses)";
|
||||
return "OpenAI Chat Completions(/v1/chat/completions)";
|
||||
}
|
||||
|
||||
/** 卡片上下两行:模型一行,协议一行 */
|
||||
function protocolCardLines(p: MonitorDto["protocol"]): { name: string; path: string } {
|
||||
if (p === "claude") return { name: "Anthropic", path: "(/messages)" };
|
||||
if (p === "openai_responses") return { name: "OpenAI Responses", path: "(/v1/responses)" };
|
||||
return { name: "OpenAI Chat Completions", path: "(/v1/chat/completions)" };
|
||||
}
|
||||
|
||||
function httpStatusValueClass(st: number | undefined | null): string {
|
||||
if (st == null) return "card-metric-value card-metric-value-muted";
|
||||
if (st >= 200 && st < 300) return "card-metric-value card-accent-http-ok";
|
||||
if (st >= 300 && st < 400) return "card-metric-value card-accent-http-info";
|
||||
if (st >= 400 && st < 500) return "card-metric-value card-accent-http-client";
|
||||
if (st >= 500) return "card-metric-value card-accent-http-server";
|
||||
return "card-metric-value";
|
||||
}
|
||||
|
||||
function latencyValueClass(ms: number | undefined | null): string {
|
||||
if (ms == null) return "card-metric-value card-metric-value-muted";
|
||||
if (ms < 500) return "card-metric-value card-accent-latency-good";
|
||||
if (ms < 1500) return "card-metric-value card-accent-latency-mid";
|
||||
return "card-metric-value card-accent-latency-slow";
|
||||
}
|
||||
|
||||
/** 与「可用率」色带一致,用于 24h 与卡片中部大字 */
|
||||
function pctAccentClass(pct: number | null): string {
|
||||
if (pct == null) return "card-metric-value-muted";
|
||||
if (pct >= 99) return "card-accent-pct-high";
|
||||
if (pct >= 95) return "card-accent-pct-mid";
|
||||
if (pct >= 90) return "card-accent-pct-low";
|
||||
return "card-accent-pct-critical";
|
||||
}
|
||||
|
||||
function availabilityValueClass(pct: number | null): string {
|
||||
return `card-metric-value ${pctAccentClass(pct)}`;
|
||||
}
|
||||
|
||||
/** 时间条桶为上海时区 00–12 / 12–24(与 Worker 一致) */
|
||||
const TIMELINE_SHANGHAI_OFF = 8 * 3600;
|
||||
const HALF_DAY_SEC = 43200;
|
||||
|
||||
/** 当前时刻在上海时区属于上午还是下午(与时间条最右一格一致) */
|
||||
function shanghaiAmPmNow(): "上午" | "下午" {
|
||||
const nowSec = Math.floor(Date.now() / 1000);
|
||||
const L = nowSec + TIMELINE_SHANGHAI_OFF;
|
||||
const secInDay = ((L % 86400) + 86400) % 86400;
|
||||
return secInDay < HALF_DAY_SEC ? "上午" : "下午";
|
||||
}
|
||||
|
||||
function formatTimelineSlotLabel(t: number): string {
|
||||
const half = (t + TIMELINE_SHANGHAI_OFF) % 86400 === 0 ? "上午" : "下午";
|
||||
const dateStr = new Date(t * 1000).toLocaleDateString("zh-CN", {
|
||||
timeZone: "Asia/Shanghai",
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
});
|
||||
return `${dateStr} ${half}`;
|
||||
}
|
||||
|
||||
/** 时间条:无数据灰、全成功绿、部分成功黄、全失败红 */
|
||||
function timelineSegTone(d: MonitorDto["timelineDaily"][number]): "none" | "up" | "warn" | "down" {
|
||||
if (d.hasData === false) return "none";
|
||||
if (d.up) return "up";
|
||||
if (d.ratio <= 0) return "down";
|
||||
return "warn";
|
||||
}
|
||||
|
||||
function timelineSegTitle(d: MonitorDto["timelineDaily"][number]): string {
|
||||
const label = formatTimelineSlotLabel(d.t);
|
||||
if (d.hasData === false) return `${label} · 无探测`;
|
||||
return `${label} · ${(d.ratio * 100).toFixed(0)}%`;
|
||||
}
|
||||
|
||||
/** 与详情弹窗一致风格:2026年5月17日 19:42:45 */
|
||||
function formatLastProbeTime(ts: number): string {
|
||||
return new Date(ts * 1000).toLocaleString("zh-CN", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
hour12: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function MonitorCard({ m, footerExtra }: { m: MonitorDto; footerExtra?: ReactNode }) {
|
||||
const dlgRef = useRef<HTMLDialogElement>(null);
|
||||
const timelineDaily = Array.isArray(m.timelineDaily) ? m.timelineDaily : [];
|
||||
const ok = m.lastProbe?.ok === 1;
|
||||
const ft = m.lastProbe?.first_token_ms;
|
||||
const st = m.lastProbe?.http_status;
|
||||
const pct30 = m.availability30d;
|
||||
const probe = m.lastProbe;
|
||||
|
||||
const openDetail = () => dlgRef.current?.showModal();
|
||||
const closeDetail = () => dlgRef.current?.close();
|
||||
const protoLines = protocolCardLines(m.protocol);
|
||||
|
||||
return (
|
||||
<article className="card">
|
||||
<header className="card-head">
|
||||
<div className="card-title-row">
|
||||
<div>
|
||||
<h2 className="card-name">{m.display_name}</h2>
|
||||
<div className="card-sub card-sub-stack">
|
||||
<div className="card-sub-row card-sub-row-model">
|
||||
<span className="card-sub-model">{m.model}</span>
|
||||
</div>
|
||||
<div className="card-sub-col-protocol">
|
||||
<span className="card-sub-protocol">{protoLines.name}</span>
|
||||
<span className="card-sub-protocol-path">{protoLines.path}</span>
|
||||
{m.category?.trim() ? (
|
||||
<span className="card-sub-meta card-sub-meta-after">{m.category.trim()}</span>
|
||||
) : null}
|
||||
<span className="card-sub-meta card-sub-meta-after">
|
||||
{m.probe_stream !== 0 ? "流式" : "非流式"}
|
||||
</span>
|
||||
{m.show_on_dashboard === 0 ? (
|
||||
<span className="card-sub-meta card-sub-meta-after">首页隐藏</span>
|
||||
) : null}
|
||||
{m.enabled === 0 ? <span className="card-sub-paused card-sub-paused-after">已停用</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-head-right">
|
||||
<span className={`badge ${ok ? "badge-ok" : "badge-bad"}`}>
|
||||
{ok ? "运行正常" : m.lastProbe ? "异常" : "尚无数据"}
|
||||
</span>
|
||||
<button type="button" className="btn-detail" onClick={openDetail}>
|
||||
详情
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div
|
||||
className="timeline"
|
||||
role="img"
|
||||
aria-label={`约 30 天、上海时区每格半天(0–12 点为上午,12–24 点为下午),右侧为当前${shanghaiAmPmNow()}`}
|
||||
>
|
||||
{timelineDaily.length === 0 ? (
|
||||
<div className="timeline-empty">暂无历史条形数据</div>
|
||||
) : (
|
||||
timelineDaily.map((d) => (
|
||||
<span
|
||||
key={d.t}
|
||||
className={`tl-seg tl-${timelineSegTone(d)}`}
|
||||
title={timelineSegTitle(d)}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="card-mid">
|
||||
<span className="card-mid-edge">约 30 天前</span>
|
||||
<strong className={`card-mid-pct ${pctAccentClass(pct30)}`}>{formatPct(pct30)} 可用率</strong>
|
||||
<span className="card-mid-edge">{shanghaiAmPmNow()}</span>
|
||||
</div>
|
||||
|
||||
<footer className="card-foot">
|
||||
<div className="card-foot-cell">
|
||||
<span className="card-foot-label">状态</span>
|
||||
<span className={httpStatusValueClass(st ?? null)}>{st != null ? st : "—"}</span>
|
||||
</div>
|
||||
<div className="card-foot-cell">
|
||||
<span className="card-foot-label">首字延迟</span>
|
||||
<span className={latencyValueClass(ft ?? null)}>{ft != null ? `${ft} ms` : "—"}</span>
|
||||
</div>
|
||||
<div className="card-foot-cell">
|
||||
<span className="card-foot-label">24h 可用</span>
|
||||
<span className={availabilityValueClass(m.availability24h)}>{formatPct(m.availability24h)}</span>
|
||||
</div>
|
||||
<div className="card-foot-cell card-foot-probe-time">
|
||||
<span className="card-foot-label">探测时间</span>
|
||||
<span
|
||||
className={probe ? "card-foot-probe-value" : "card-foot-probe-value card-metric-value-muted"}
|
||||
>
|
||||
{probe ? formatLastProbeTime(probe.ts) : "—"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="card-foot-wide card-foot-count-row">
|
||||
<span className="card-foot-label">探测次数</span>
|
||||
<span className="card-foot-count-value">{m.probe_count}</span>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{footerExtra ? <div className="card-admin-footer">{footerExtra}</div> : null}
|
||||
|
||||
<dialog ref={dlgRef} className="probe-detail-dialog">
|
||||
<div className="probe-detail-inner">
|
||||
<header className="probe-detail-head">
|
||||
<h3 className="probe-detail-title">最近探测详情</h3>
|
||||
<button type="button" className="probe-detail-close" aria-label="关闭" onClick={closeDetail}>
|
||||
×
|
||||
</button>
|
||||
</header>
|
||||
<div className="probe-detail-body">
|
||||
<dl className="probe-detail-dl">
|
||||
<dt>显示名称</dt>
|
||||
<dd>{m.display_name}</dd>
|
||||
<dt>协议</dt>
|
||||
<dd>{protocolLabel(m.protocol)}</dd>
|
||||
<dt>模型</dt>
|
||||
<dd>{m.model}</dd>
|
||||
<dt>API 根地址</dt>
|
||||
<dd>
|
||||
<code className="probe-detail-code">{m.api_base_url}</code>
|
||||
<div className="probe-detail-link-wrap">
|
||||
<a href={m.api_base_url} target="_blank" rel="noreferrer">
|
||||
在浏览器中打开
|
||||
</a>
|
||||
</div>
|
||||
</dd>
|
||||
<dt>探测时间</dt>
|
||||
<dd>
|
||||
{probe
|
||||
? new Date(probe.ts * 1000).toLocaleString(undefined, {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "medium",
|
||||
})
|
||||
: "—"}
|
||||
</dd>
|
||||
<dt>结果</dt>
|
||||
<dd>{probe ? (probe.ok === 1 ? "成功" : "失败") : "尚无记录"}</dd>
|
||||
<dt>HTTP 状态</dt>
|
||||
<dd>{probe?.http_status != null ? probe.http_status : "—"}</dd>
|
||||
<dt>首字延迟</dt>
|
||||
<dd>{probe?.first_token_ms != null ? `${probe.first_token_ms} ms` : "—"}</dd>
|
||||
</dl>
|
||||
{probe?.error_message ? (
|
||||
<div className="probe-detail-error">
|
||||
<strong>错误信息</strong>
|
||||
<pre className="probe-detail-pre">{probe.error_message}</pre>
|
||||
</div>
|
||||
) : null}
|
||||
{probe ? (
|
||||
<div className="probe-detail-io">
|
||||
<strong>输入(本次请求发送的用户消息)</strong>
|
||||
<pre className="probe-detail-io-pre">{probe.probe_input ?? "—"}</pre>
|
||||
<strong>输出(模型流式正文摘要,最长约数千字)</strong>
|
||||
<pre className="probe-detail-io-pre probe-detail-io-out">
|
||||
{probe.probe_output ?? "—"}
|
||||
</pre>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
34
frontend/src/components/PwaUpdatePrompt.tsx
Normal file
34
frontend/src/components/PwaUpdatePrompt.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useRegisterSW } from "virtual:pwa-register/react";
|
||||
|
||||
export function PwaUpdatePrompt() {
|
||||
const {
|
||||
needRefresh: [needRefresh, setNeedRefresh],
|
||||
updateServiceWorker,
|
||||
} = useRegisterSW({
|
||||
onRegisteredSW(_swUrl, registration) {
|
||||
if (registration) {
|
||||
window.setInterval(() => void registration.update(), 60 * 60 * 1000);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (!needRefresh) return null;
|
||||
|
||||
return (
|
||||
<div className="pwa-update-banner" role="alert">
|
||||
<p className="pwa-update-text">发现新版本,更新后即可使用最新功能。</p>
|
||||
<div className="pwa-update-actions">
|
||||
<button type="button" className="btn ghost small" onClick={() => setNeedRefresh(false)}>
|
||||
稍后
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn primary small"
|
||||
onClick={() => void updateServiceWorker(true)}
|
||||
>
|
||||
立即更新
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
42
frontend/src/components/SplashScreen.tsx
Normal file
42
frontend/src/components/SplashScreen.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import "../splash.css";
|
||||
|
||||
const APP_NAME = "ModelPing";
|
||||
|
||||
export function SplashScreen() {
|
||||
return (
|
||||
<div className="splash-screen" role="status" aria-live="polite" aria-busy="true">
|
||||
<div className="splash-bg-glow splash-bg-glow--a" aria-hidden />
|
||||
<div className="splash-bg-glow splash-bg-glow--b" aria-hidden />
|
||||
|
||||
<div className="splash-content">
|
||||
<div className="splash-logo-wrap">
|
||||
<div className="splash-rings" aria-hidden>
|
||||
<span className="splash-ring" />
|
||||
<span className="splash-ring" />
|
||||
<span className="splash-ring" />
|
||||
</div>
|
||||
<img
|
||||
className="splash-logo"
|
||||
src="/logo192.png"
|
||||
alt=""
|
||||
width={96}
|
||||
height={96}
|
||||
decoding="async"
|
||||
fetchPriority="high"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<h1 className="splash-title">{APP_NAME}</h1>
|
||||
<p className="splash-subtitle">加载中</p>
|
||||
|
||||
<div className="splash-dots" aria-hidden>
|
||||
<span />
|
||||
<span />
|
||||
<span />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span className="sr-only">{APP_NAME} 正在加载</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
57
frontend/src/context/AppBootContext.tsx
Normal file
57
frontend/src/context/AppBootContext.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { SplashScreen } from "../components/SplashScreen";
|
||||
|
||||
const MIN_SPLASH_MS = 900;
|
||||
|
||||
type AppBootContextValue = {
|
||||
signalBootReady: () => void;
|
||||
};
|
||||
|
||||
const AppBootContext = createContext<AppBootContextValue | null>(null);
|
||||
|
||||
export function AppBootProvider({ children }: { children: ReactNode }) {
|
||||
const [showSplash, setShowSplash] = useState(true);
|
||||
const bootReady = useRef(false);
|
||||
const startedAt = useRef(Date.now());
|
||||
const hideTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const signalBootReady = useCallback(() => {
|
||||
if (bootReady.current) return;
|
||||
bootReady.current = true;
|
||||
const delay = Math.max(0, MIN_SPLASH_MS - (Date.now() - startedAt.current));
|
||||
hideTimer.current = setTimeout(() => setShowSplash(false), delay);
|
||||
}, []);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (hideTimer.current) clearTimeout(hideTimer.current);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const value = useMemo(() => ({ signalBootReady }), [signalBootReady]);
|
||||
|
||||
return (
|
||||
<AppBootContext.Provider value={value}>
|
||||
{children}
|
||||
{showSplash ? <SplashScreen /> : null}
|
||||
</AppBootContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useAppBoot(): AppBootContextValue {
|
||||
const ctx = useContext(AppBootContext);
|
||||
if (!ctx) {
|
||||
throw new Error("useAppBoot must be used within AppBootProvider");
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
983
frontend/src/index.css
Normal file
983
frontend/src/index.css
Normal file
@@ -0,0 +1,983 @@
|
||||
:root {
|
||||
/* 主字体:LXGW WenKai Mono(等宽,由 Vite 打包子集 woff2);无则回退系统字体 */
|
||||
--font-app: "LXGW WenKai Mono", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
|
||||
--font-mono: "LXGW WenKai Mono", ui-monospace, "Cascadia Code", monospace;
|
||||
/* 随机背景高斯模糊(CSS blur 无百分比,按「10%」诉求取 10px,可按需改) */
|
||||
--rand-bg-blur: 10px;
|
||||
--rand-bg-scale: 1.08;
|
||||
font-family: var(--font-app);
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
color: #222;
|
||||
background-color: #f4f6f8;
|
||||
--green: #2ecc71;
|
||||
--green-dark: #27ae60;
|
||||
--red: #e74c3c;
|
||||
--card: #fff;
|
||||
--muted: #6b7280;
|
||||
--shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
background-color: #dfe6eb;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--green-dark);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.app-shell {
|
||||
position: relative;
|
||||
isolation: isolate;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* https://randbg.smyhub.com — 全站随机底图,轻微缩放避免模糊露边 */
|
||||
.app-rand-bg {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: -1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
filter: blur(var(--rand-bg-blur));
|
||||
transform: scale(var(--rand-bg-scale));
|
||||
transform-origin: center center;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.app-rand-bg {
|
||||
filter: none;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
backdrop-filter: blur(8px);
|
||||
border-bottom: 1px solid rgba(15, 23, 42, 0.06);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
a.brand {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
padding: 0.35rem 0.5rem;
|
||||
margin: 0;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
touch-action: manipulation;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
a.brand:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.brand:focus-visible {
|
||||
outline: 2px solid var(--green);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.admin-code-sample {
|
||||
display: inline-block;
|
||||
padding: 0.25rem 0.45rem;
|
||||
background: #f1f5f9;
|
||||
border-radius: 6px;
|
||||
font-size: 0.9rem;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.brand-logo {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
flex-shrink: 0;
|
||||
touch-action: manipulation;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.brand-text {
|
||||
font-weight: 700;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.top-nav {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.top-nav a {
|
||||
font-weight: 500;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.main-area {
|
||||
flex: 1;
|
||||
padding: 1.25rem;
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.panel-intro {
|
||||
background: var(--card);
|
||||
border-radius: 14px;
|
||||
padding: 1rem 1.15rem;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.status-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dot.ok {
|
||||
background: var(--green);
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.pills {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.pill {
|
||||
border: 1px solid rgba(15, 23, 42, 0.12);
|
||||
border-radius: 999px;
|
||||
padding: 0.35rem 0.85rem;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.pill.active {
|
||||
border-color: var(--green);
|
||||
background: rgba(46, 204, 113, 0.12);
|
||||
color: var(--green-dark);
|
||||
}
|
||||
|
||||
.search input {
|
||||
min-width: 220px;
|
||||
width: min(420px, 100%);
|
||||
padding: 0.45rem 0.65rem;
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(15, 23, 42, 0.14);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card);
|
||||
border-radius: 16px;
|
||||
padding: 1rem;
|
||||
box-shadow: var(--shadow);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.65rem;
|
||||
}
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
|
||||
.card-title-row {
|
||||
display: flex;
|
||||
gap: 0.55rem;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.card-name {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.card-sub {
|
||||
margin: 0.15rem 0 0;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.card-sub-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.card-sub-row-model {
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.card-sub-col-protocol {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.08rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.card-sub-protocol-path {
|
||||
color: #0f766e;
|
||||
font-weight: 500;
|
||||
font-size: 0.76rem;
|
||||
line-height: 1.35;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.card-sub-meta-after,
|
||||
.card-sub-paused-after {
|
||||
margin-top: 0.2rem;
|
||||
font-size: 0.76rem;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.card-sub-model {
|
||||
color: #1e3a5f;
|
||||
font-weight: 600;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.card-sub-protocol {
|
||||
color: #0f766e;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.card-sub-meta {
|
||||
color: #64748b;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.card-sub-paused {
|
||||
color: #c2410c;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.card-sub-sep {
|
||||
color: #cbd5e1;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.card-head-right {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 0.35rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 0.78rem;
|
||||
padding: 0.15rem 0.5rem;
|
||||
border-radius: 999px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.badge-ok {
|
||||
background: rgba(46, 204, 113, 0.16);
|
||||
color: var(--green-dark);
|
||||
}
|
||||
|
||||
.badge-bad {
|
||||
background: rgba(231, 76, 60, 0.12);
|
||||
color: #c0392b;
|
||||
}
|
||||
|
||||
.btn-detail {
|
||||
display: inline-block;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 0.78rem;
|
||||
padding: 0.3rem 0.65rem;
|
||||
border-radius: 8px;
|
||||
background: linear-gradient(145deg, var(--green), #58d68d);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.btn-detail:hover {
|
||||
filter: brightness(1.03);
|
||||
}
|
||||
|
||||
.btn-detail:focus-visible {
|
||||
outline: 2px solid var(--green-dark);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.probe-detail-dialog {
|
||||
max-width: min(520px, 94vw);
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
border: none;
|
||||
border-radius: 16px;
|
||||
padding: 0;
|
||||
box-shadow: 0 20px 50px rgba(15, 23, 42, 0.22);
|
||||
}
|
||||
|
||||
.probe-detail-dialog::backdrop {
|
||||
background: rgba(15, 23, 42, 0.4);
|
||||
}
|
||||
|
||||
.probe-detail-inner {
|
||||
padding: 1rem 1.15rem 1.15rem;
|
||||
}
|
||||
|
||||
.probe-detail-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.probe-detail-title {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.probe-detail-close {
|
||||
border: none;
|
||||
background: #f1f5f9;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: 8px;
|
||||
font-size: 1.35rem;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
color: #64748b;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.probe-detail-close:hover {
|
||||
background: #e2e8f0;
|
||||
}
|
||||
|
||||
.probe-detail-dl {
|
||||
margin: 0;
|
||||
display: grid;
|
||||
grid-template-columns: 7.5rem 1fr;
|
||||
gap: 0.35rem 0.75rem;
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.probe-detail-dl dt {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.probe-detail-dl dd {
|
||||
margin: 0;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.probe-detail-code {
|
||||
display: block;
|
||||
font-size: 0.78rem;
|
||||
background: #f8fafc;
|
||||
padding: 0.35rem 0.5rem;
|
||||
border-radius: 8px;
|
||||
word-break: break-all;
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
|
||||
.probe-detail-link-wrap {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.probe-detail-error {
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
|
||||
.probe-detail-error strong {
|
||||
display: block;
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 0.4rem;
|
||||
color: #c0392b;
|
||||
}
|
||||
|
||||
.probe-detail-pre {
|
||||
margin: 0;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.78rem;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
background: #fef2f2;
|
||||
border: 1px solid rgba(231, 76, 60, 0.2);
|
||||
border-radius: 8px;
|
||||
padding: 0.55rem 0.65rem;
|
||||
max-height: 220px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.probe-detail-io {
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
|
||||
.probe-detail-io strong {
|
||||
display: block;
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 0.35rem;
|
||||
margin-top: 0.65rem;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.probe-detail-io strong:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.probe-detail-io-pre {
|
||||
margin: 0;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.78rem;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
background: #f8fafc;
|
||||
border: 1px solid rgba(15, 23, 42, 0.08);
|
||||
border-radius: 8px;
|
||||
padding: 0.55rem 0.65rem;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.probe-detail-io-out {
|
||||
background: #f0fdf4;
|
||||
border-color: rgba(46, 204, 113, 0.25);
|
||||
}
|
||||
|
||||
.timeline {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 1px;
|
||||
height: 42px;
|
||||
padding: 4px 2px;
|
||||
border-radius: 10px;
|
||||
background: #f8fafc;
|
||||
border: 1px solid rgba(15, 23, 42, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.timeline-empty {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
padding: 0.25rem 0.35rem;
|
||||
}
|
||||
|
||||
.tl-seg {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
border-radius: 1px;
|
||||
align-self: stretch;
|
||||
background: #cbd5e1;
|
||||
}
|
||||
|
||||
.tl-seg.tl-none {
|
||||
background: #e2e8f0;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.tl-seg.tl-up {
|
||||
background: var(--green);
|
||||
}
|
||||
|
||||
.tl-seg.tl-warn {
|
||||
background: linear-gradient(180deg, #facc15, #eab308);
|
||||
box-shadow: inset 0 0 0 1px rgba(180, 83, 9, 0.22);
|
||||
}
|
||||
|
||||
.tl-seg.tl-down {
|
||||
background: var(--red);
|
||||
}
|
||||
|
||||
.card-mid {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.card-mid-edge {
|
||||
color: #94a3b8;
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
|
||||
.card-mid-pct {
|
||||
font-size: 1.02rem;
|
||||
font-weight: 750;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.card-foot {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.55rem 0.75rem;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.card-foot-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.card-foot-label {
|
||||
font-size: 0.68rem;
|
||||
font-weight: 600;
|
||||
color: #94a3b8;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.card-metric-value {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 650;
|
||||
line-height: 1.25;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.card-metric-value-muted {
|
||||
color: #94a3b8 !important;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.card-accent-http-ok {
|
||||
color: #15803d;
|
||||
}
|
||||
|
||||
.card-accent-http-info {
|
||||
color: #0369a1;
|
||||
}
|
||||
|
||||
.card-accent-http-client {
|
||||
color: #c2410c;
|
||||
}
|
||||
|
||||
.card-accent-http-server {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.card-accent-latency-good {
|
||||
color: #15803d;
|
||||
}
|
||||
|
||||
.card-accent-latency-mid {
|
||||
color: #b45309;
|
||||
}
|
||||
|
||||
.card-accent-latency-slow {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.card-accent-pct-high {
|
||||
color: #15803d;
|
||||
}
|
||||
|
||||
.card-accent-pct-mid {
|
||||
color: #3f6212;
|
||||
}
|
||||
|
||||
.card-accent-pct-low {
|
||||
color: #b45309;
|
||||
}
|
||||
|
||||
.card-accent-pct-critical {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.card-foot-probe-time {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.card-foot-probe-value {
|
||||
font-size: 0.78rem;
|
||||
font-weight: 650;
|
||||
line-height: 1.35;
|
||||
word-break: break-word;
|
||||
color: #3730a3;
|
||||
}
|
||||
|
||||
.card-foot-wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.card-foot-count-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
padding-top: 0.35rem;
|
||||
margin-top: 0.1rem;
|
||||
border-top: 1px solid rgba(15, 23, 42, 0.06);
|
||||
}
|
||||
|
||||
.card-foot-count-value {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 750;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: #6d28d9;
|
||||
}
|
||||
|
||||
.banner {
|
||||
background: rgba(46, 204, 113, 0.1);
|
||||
border: 1px solid rgba(46, 204, 113, 0.35);
|
||||
padding: 0.55rem 0.75rem;
|
||||
border-radius: 10px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.banner.error {
|
||||
background: rgba(231, 76, 60, 0.08);
|
||||
border-color: rgba(231, 76, 60, 0.35);
|
||||
color: #922b21;
|
||||
}
|
||||
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(15, 23, 42, 0.45);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
z-index: 9999;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
padding: 1rem 1.1rem;
|
||||
width: min(360px, 100%);
|
||||
box-shadow: 0 22px 48px rgba(15, 23, 42, 0.28);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
margin: 0 0 0.65rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.admin-token-backdrop {
|
||||
z-index: 10002;
|
||||
}
|
||||
|
||||
.admin-token-modal {
|
||||
width: min(300px, 100%);
|
||||
padding: 0.85rem 0.95rem;
|
||||
}
|
||||
|
||||
.admin-token-title {
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.92rem;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.admin-token-input {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.admin-token-modal .modal-actions {
|
||||
margin-top: 0.55rem;
|
||||
}
|
||||
|
||||
.modal-input {
|
||||
width: 100%;
|
||||
padding: 0.5rem 0.55rem;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(15, 23, 42, 0.15);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.modal-err {
|
||||
color: #c0392b;
|
||||
font-size: 0.85rem;
|
||||
margin: 0.35rem 0 0;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.btn {
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(15, 23, 42, 0.12);
|
||||
padding: 0.4rem 0.75rem;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.btn.primary {
|
||||
background: linear-gradient(145deg, var(--green), #58d68d);
|
||||
color: #fff;
|
||||
border: none;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn.primary:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn.ghost {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.btn.small {
|
||||
font-size: 0.78rem;
|
||||
padding: 0.3rem 0.55rem;
|
||||
}
|
||||
|
||||
.btn.danger {
|
||||
border-color: rgba(192, 57, 43, 0.45);
|
||||
color: #c0392b;
|
||||
}
|
||||
|
||||
.admin-form-section {
|
||||
background: var(--card);
|
||||
border-radius: 14px;
|
||||
padding: 1rem;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.admin-form {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
|
||||
gap: 0.65rem 1rem;
|
||||
}
|
||||
|
||||
.admin-form label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.85rem;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.admin-form input,
|
||||
.admin-form select,
|
||||
.admin-form textarea {
|
||||
padding: 0.45rem 0.5rem;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(15, 23, 42, 0.14);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.admin-form textarea {
|
||||
grid-column: 1 / -1;
|
||||
min-height: 5.5rem;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.checkbox-row {
|
||||
flex-direction: row !important;
|
||||
align-items: center;
|
||||
gap: 0.4rem !important;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.admin-monitor-grid {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.admin-monitors-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.admin-monitors-head h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-monitor-dialog {
|
||||
max-width: min(720px, 96vw);
|
||||
}
|
||||
|
||||
.admin-monitor-dialog-inner {
|
||||
max-height: min(88vh, 900px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
.admin-form--modal {
|
||||
overflow-y: auto;
|
||||
padding-right: 0.15rem;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.card-admin-footer {
|
||||
margin-top: 0.15rem;
|
||||
padding-top: 0.65rem;
|
||||
border-top: 1px solid rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
|
||||
.card-admin-footer-inner {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.card-admin-fallback-msg {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-actions-bar {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.pwa-update-banner {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
bottom: 1rem;
|
||||
transform: translateX(-50%);
|
||||
z-index: 10001;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.65rem 0.85rem;
|
||||
max-width: min(520px, calc(100vw - 2rem));
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
border: 1px solid rgba(46, 204, 113, 0.35);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
|
||||
}
|
||||
|
||||
.pwa-update-text {
|
||||
margin: 0;
|
||||
font-size: 0.88rem;
|
||||
color: #374151;
|
||||
flex: 1 1 12rem;
|
||||
}
|
||||
|
||||
.pwa-update-actions {
|
||||
display: flex;
|
||||
gap: 0.45rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.topbar {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.card-foot {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
11
frontend/src/main.tsx
Normal file
11
frontend/src/main.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "lxgw-wenkai-webfont/lxgwwenkaimono-regular.css";
|
||||
import "./index.css";
|
||||
import App from "./App.tsx";
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
462
frontend/src/pages/Admin.tsx
Normal file
462
frontend/src/pages/Admin.tsx
Normal file
@@ -0,0 +1,462 @@
|
||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||
import { Navigate, useNavigate, useSearchParams } from "react-router-dom";
|
||||
import {
|
||||
adminCreateMonitor,
|
||||
adminDeleteMonitor,
|
||||
adminGetProbeSettings,
|
||||
adminListMonitors,
|
||||
adminPing,
|
||||
adminRunMonitor,
|
||||
adminSaveProbeSettings,
|
||||
adminUpdateMonitor,
|
||||
} from "../api";
|
||||
import { MonitorCard } from "../components/MonitorCard";
|
||||
import { useAppBoot } from "../context/AppBootContext";
|
||||
import {
|
||||
clearAdminToken,
|
||||
getAdminToken,
|
||||
setAdminToken,
|
||||
type AdminMonitorRow,
|
||||
type MonitorProtocol,
|
||||
} from "../types";
|
||||
|
||||
const INTERVALS = [1, 5, 10, 30, 60, 360] as const;
|
||||
/** 管理页与首页一致:拉取最新监控与统计数据 */
|
||||
const ADMIN_REFRESH_MS = 60_000;
|
||||
|
||||
const EMPTY_FORM = {
|
||||
display_name: "",
|
||||
api_base_url: "",
|
||||
api_key: "",
|
||||
model: "",
|
||||
protocol: "openai" as MonitorProtocol,
|
||||
category: "",
|
||||
enabled: true,
|
||||
probe_stream: true,
|
||||
show_on_dashboard: true,
|
||||
};
|
||||
|
||||
type Row = AdminMonitorRow;
|
||||
|
||||
export function Admin() {
|
||||
const { signalBootReady } = useAppBoot();
|
||||
const [searchParams] = useSearchParams();
|
||||
const navigate = useNavigate();
|
||||
const [hasToken, setHasToken] = useState(() => !!getAdminToken());
|
||||
|
||||
useEffect(() => {
|
||||
const sync = () => setHasToken(!!getAdminToken());
|
||||
window.addEventListener("modelping:admin-auth", sync);
|
||||
return () => window.removeEventListener("modelping:admin-auth", sync);
|
||||
}, []);
|
||||
const [urlVerifying, setUrlVerifying] = useState(false);
|
||||
const authAttempt = useRef(0);
|
||||
|
||||
const [rows, setRows] = useState<Row[] | null>(null);
|
||||
const [globalForm, setGlobalForm] = useState({
|
||||
probe_interval_minutes: 5 as (typeof INTERVALS)[number],
|
||||
probe_prompts: "",
|
||||
});
|
||||
const [msg, setMsg] = useState<string | null>(null);
|
||||
const [editing, setEditing] = useState<Row | null>(null);
|
||||
const monitorFormDlgRef = useRef<HTMLDialogElement>(null);
|
||||
|
||||
const [form, setForm] = useState({ ...EMPTY_FORM });
|
||||
|
||||
const refreshAll = () => {
|
||||
if (!getAdminToken()) {
|
||||
setRows([]);
|
||||
return;
|
||||
}
|
||||
void Promise.all([adminListMonitors(), adminGetProbeSettings()])
|
||||
.then(([list, g]) => {
|
||||
setRows(list);
|
||||
setGlobalForm({
|
||||
probe_interval_minutes: g.probe_interval_minutes as (typeof INTERVALS)[number],
|
||||
probe_prompts: g.probe_prompts,
|
||||
});
|
||||
setMsg(null);
|
||||
})
|
||||
.catch(() => setMsg("加载失败,请重新使用带 token 的链接登录"));
|
||||
};
|
||||
|
||||
const refreshAllRef = useRef(refreshAll);
|
||||
refreshAllRef.current = refreshAll;
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasToken) return;
|
||||
const tick = () => {
|
||||
refreshAllRef.current();
|
||||
};
|
||||
const t = setInterval(tick, ADMIN_REFRESH_MS);
|
||||
const onVis = () => {
|
||||
if (document.visibilityState === "visible") tick();
|
||||
};
|
||||
document.addEventListener("visibilitychange", onVis);
|
||||
return () => {
|
||||
clearInterval(t);
|
||||
document.removeEventListener("visibilitychange", onVis);
|
||||
};
|
||||
}, [hasToken]);
|
||||
|
||||
/** 从 /admin?token=xxx 登录:校验后写入 sessionStorage 并去掉地址栏参数 */
|
||||
useEffect(() => {
|
||||
const raw = searchParams.get("token");
|
||||
const tokenFromUrl = typeof raw === "string" ? raw.trim() : "";
|
||||
if (!tokenFromUrl) return;
|
||||
|
||||
const id = ++authAttempt.current;
|
||||
queueMicrotask(() => {
|
||||
if (authAttempt.current !== id) return;
|
||||
setUrlVerifying(true);
|
||||
setMsg(null);
|
||||
});
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
const result = await adminPing(tokenFromUrl);
|
||||
if (authAttempt.current !== id) return;
|
||||
if (result.ok === true) {
|
||||
setAdminToken(tokenFromUrl);
|
||||
setHasToken(true);
|
||||
} else if (result.ok === false) {
|
||||
setMsg(null);
|
||||
}
|
||||
} catch {
|
||||
if (authAttempt.current === id) setMsg(null);
|
||||
} finally {
|
||||
if (authAttempt.current === id) {
|
||||
setUrlVerifying(false);
|
||||
if (getAdminToken()) {
|
||||
navigate("/admin", { replace: true });
|
||||
} else {
|
||||
navigate("/", { replace: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
}, [searchParams, navigate]);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const run = async () => {
|
||||
if (!getAdminToken()) {
|
||||
if (!cancelled) {
|
||||
setRows([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const [list, g] = await Promise.all([adminListMonitors(), adminGetProbeSettings()]);
|
||||
if (!cancelled) {
|
||||
setRows(list);
|
||||
setGlobalForm({
|
||||
probe_interval_minutes: g.probe_interval_minutes as (typeof INTERVALS)[number],
|
||||
probe_prompts: g.probe_prompts,
|
||||
});
|
||||
setMsg(null);
|
||||
}
|
||||
} catch {
|
||||
if (!cancelled) {
|
||||
setRows([]);
|
||||
setMsg("加载失败,请重新使用带 token 的链接登录");
|
||||
}
|
||||
}
|
||||
};
|
||||
void run();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [hasToken]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!urlVerifying && rows !== null) signalBootReady();
|
||||
}, [urlVerifying, rows, signalBootReady]);
|
||||
|
||||
if (urlVerifying || !hasToken) {
|
||||
if (urlVerifying) return null;
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
const saveGlobal = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
setMsg(null);
|
||||
try {
|
||||
await adminSaveProbeSettings({
|
||||
probe_interval_minutes: globalForm.probe_interval_minutes,
|
||||
probe_prompts: globalForm.probe_prompts,
|
||||
});
|
||||
refreshAll();
|
||||
setMsg("全局设置已保存(对所有监控生效)");
|
||||
} catch (err) {
|
||||
setMsg(err instanceof Error && err.message ? err.message : "全局设置保存失败");
|
||||
}
|
||||
};
|
||||
|
||||
const submitNew = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
setMsg(null);
|
||||
try {
|
||||
await adminCreateMonitor({
|
||||
display_name: form.display_name,
|
||||
api_base_url: form.api_base_url,
|
||||
api_key: form.api_key,
|
||||
model: form.model,
|
||||
protocol: form.protocol,
|
||||
category: form.category || undefined,
|
||||
enabled: form.enabled,
|
||||
probe_stream: form.probe_stream,
|
||||
show_on_dashboard: form.show_on_dashboard,
|
||||
});
|
||||
setForm({ ...EMPTY_FORM });
|
||||
monitorFormDlgRef.current?.close();
|
||||
refreshAll();
|
||||
setMsg("已创建");
|
||||
} catch {
|
||||
setMsg("创建失败");
|
||||
}
|
||||
};
|
||||
|
||||
const openNewMonitorModal = () => {
|
||||
setEditing(null);
|
||||
setForm({ ...EMPTY_FORM });
|
||||
monitorFormDlgRef.current?.showModal();
|
||||
};
|
||||
|
||||
const openEditMonitor = (r: Row) => {
|
||||
setEditing(r);
|
||||
setForm({
|
||||
display_name: r.display_name,
|
||||
api_base_url: r.api_base_url,
|
||||
api_key: "",
|
||||
model: r.model,
|
||||
protocol: r.protocol,
|
||||
category: r.category,
|
||||
enabled: r.enabled !== 0,
|
||||
probe_stream: r.probe_stream !== 0,
|
||||
show_on_dashboard: r.show_on_dashboard !== 0,
|
||||
});
|
||||
monitorFormDlgRef.current?.showModal();
|
||||
};
|
||||
|
||||
const onMonitorFormDialogClose = () => {
|
||||
setEditing(null);
|
||||
setForm({ ...EMPTY_FORM });
|
||||
};
|
||||
|
||||
const saveEdit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!editing) return;
|
||||
setMsg(null);
|
||||
try {
|
||||
const patch: Parameters<typeof adminUpdateMonitor>[1] = {
|
||||
display_name: form.display_name,
|
||||
api_base_url: form.api_base_url,
|
||||
model: form.model,
|
||||
protocol: form.protocol,
|
||||
category: form.category,
|
||||
enabled: form.enabled,
|
||||
probe_stream: form.probe_stream,
|
||||
show_on_dashboard: form.show_on_dashboard,
|
||||
};
|
||||
if (form.api_key.trim()) patch.api_key = form.api_key.trim();
|
||||
await adminUpdateMonitor(editing.id, patch);
|
||||
monitorFormDlgRef.current?.close();
|
||||
refreshAll();
|
||||
setMsg("已保存");
|
||||
} catch (e) {
|
||||
setMsg(e instanceof Error && e.message ? e.message : "保存失败");
|
||||
}
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
clearAdminToken();
|
||||
setHasToken(false);
|
||||
setRows([]);
|
||||
navigate("/admin", { replace: true });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="page admin">
|
||||
<div className="admin-actions-bar">
|
||||
<button type="button" className="btn ghost" onClick={logout}>
|
||||
退出管理
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{msg ? <p className="banner">{msg}</p> : null}
|
||||
|
||||
<section className="admin-form-section">
|
||||
<h2>全局设置</h2>
|
||||
<form className="admin-form" onSubmit={saveGlobal}>
|
||||
<label>
|
||||
探测间隔
|
||||
<select
|
||||
value={globalForm.probe_interval_minutes}
|
||||
onChange={(e) =>
|
||||
setGlobalForm((f) => ({
|
||||
...f,
|
||||
probe_interval_minutes: Number(e.target.value) as (typeof INTERVALS)[number],
|
||||
}))
|
||||
}
|
||||
>
|
||||
{INTERVALS.map((n) => (
|
||||
<option key={n} value={n}>
|
||||
{n === 60 ? "1小时" : n === 360 ? "6小时" : `${n}分钟`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
探测用语
|
||||
<textarea
|
||||
rows={4}
|
||||
placeholder={"你好\nhello\nping"}
|
||||
value={globalForm.probe_prompts}
|
||||
onChange={(e) => setGlobalForm((f) => ({ ...f, probe_prompts: e.target.value }))}
|
||||
/>
|
||||
</label>
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn primary">
|
||||
保存全局设置
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="admin-monitors-section">
|
||||
<div className="admin-monitors-head">
|
||||
<h2>监控列表</h2>
|
||||
<button type="button" className="btn primary" onClick={openNewMonitorModal}>
|
||||
新增监控
|
||||
</button>
|
||||
</div>
|
||||
<div className="card-grid admin-monitor-grid">
|
||||
{(rows ?? []).map((r) => {
|
||||
const bar = (
|
||||
<div className="card-admin-footer-inner">
|
||||
<button type="button" className="btn small" onClick={() => void adminRunMonitor(r.id).then(refreshAll)}>
|
||||
立即探测
|
||||
</button>
|
||||
<button type="button" className="btn small" onClick={() => openEditMonitor(r)}>
|
||||
编辑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn small danger"
|
||||
onClick={() => {
|
||||
if (confirm("确定删除?")) void adminDeleteMonitor(r.id).then(refreshAll);
|
||||
}}
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
return <MonitorCard key={r.id} m={r} footerExtra={bar} />;
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<dialog
|
||||
ref={monitorFormDlgRef}
|
||||
className="probe-detail-dialog admin-monitor-dialog"
|
||||
onClose={onMonitorFormDialogClose}
|
||||
>
|
||||
<div className="probe-detail-inner admin-monitor-dialog-inner">
|
||||
<header className="probe-detail-head">
|
||||
<h3 className="probe-detail-title">{editing ? "编辑监控" : "新建监控"}</h3>
|
||||
<button
|
||||
type="button"
|
||||
className="probe-detail-close"
|
||||
aria-label="关闭"
|
||||
onClick={() => monitorFormDlgRef.current?.close()}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</header>
|
||||
<form className="admin-form admin-form--modal" onSubmit={editing ? saveEdit : submitNew}>
|
||||
<label>
|
||||
显示名称
|
||||
<input
|
||||
required
|
||||
value={form.display_name}
|
||||
onChange={(e) => setForm((f) => ({ ...f, display_name: e.target.value }))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
API 根地址(如 https://api.openai.com/v1)
|
||||
<input
|
||||
required
|
||||
value={form.api_base_url}
|
||||
onChange={(e) => setForm((f) => ({ ...f, api_base_url: e.target.value }))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
API Key {editing ? "(留空则不变)" : null}
|
||||
<input
|
||||
required={!editing}
|
||||
type="password"
|
||||
autoComplete="off"
|
||||
value={form.api_key}
|
||||
onChange={(e) => setForm((f) => ({ ...f, api_key: e.target.value }))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
模型名
|
||||
<input required value={form.model} onChange={(e) => setForm((f) => ({ ...f, model: e.target.value }))} />
|
||||
</label>
|
||||
<label>
|
||||
协议
|
||||
<select
|
||||
value={form.protocol}
|
||||
onChange={(e) =>
|
||||
setForm((f) => ({ ...f, protocol: e.target.value as MonitorProtocol }))
|
||||
}
|
||||
>
|
||||
<option value="openai">OpenAI Chat Completions(/v1/chat/completions)</option>
|
||||
<option value="openai_responses">OpenAI Responses(/v1/responses)</option>
|
||||
<option value="claude">Anthropic(/messages)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
分类(可选)
|
||||
<input value={form.category} onChange={(e) => setForm((f) => ({ ...f, category: e.target.value }))} />
|
||||
</label>
|
||||
<label className="checkbox-row">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.show_on_dashboard}
|
||||
onChange={(e) => setForm((f) => ({ ...f, show_on_dashboard: e.target.checked }))}
|
||||
/>
|
||||
在首页展示该监控卡片(关闭则仅后台可见,仍参与定时探测)
|
||||
</label>
|
||||
<label className="checkbox-row">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.probe_stream}
|
||||
onChange={(e) => setForm((f) => ({ ...f, probe_stream: e.target.checked }))}
|
||||
/>
|
||||
使用流式调用(SSE);关闭则为非流式 JSON,首包耗时为整段响应完成时间
|
||||
</label>
|
||||
<label className="checkbox-row">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.enabled}
|
||||
onChange={(e) => setForm((f) => ({ ...f, enabled: e.target.checked }))}
|
||||
/>
|
||||
启用
|
||||
</label>
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn ghost" onClick={() => monitorFormDlgRef.current?.close()}>
|
||||
取消
|
||||
</button>
|
||||
<button type="submit" className="btn primary">
|
||||
{editing ? "保存" : "创建"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
111
frontend/src/pages/Dashboard.tsx
Normal file
111
frontend/src/pages/Dashboard.tsx
Normal file
@@ -0,0 +1,111 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { fetchMonitors } from "../api";
|
||||
import { MonitorCard } from "../components/MonitorCard";
|
||||
import { useAppBoot } from "../context/AppBootContext";
|
||||
import type { MonitorDto } from "../types";
|
||||
|
||||
const REFRESH_MS = 60_000;
|
||||
|
||||
export function Dashboard() {
|
||||
const { signalBootReady } = useAppBoot();
|
||||
const [rows, setRows] = useState<MonitorDto[] | null>(null);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [filterCat, setFilterCat] = useState<string>("__all__");
|
||||
const [q, setQ] = useState("");
|
||||
|
||||
const load = useCallback(() => {
|
||||
fetchMonitors()
|
||||
.then((data) => {
|
||||
setRows(data);
|
||||
setErr(null);
|
||||
})
|
||||
.catch(() => {
|
||||
setRows([]);
|
||||
setErr("加载失败");
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
const t = setInterval(load, REFRESH_MS);
|
||||
const onVis = () => {
|
||||
if (document.visibilityState === "visible") load();
|
||||
};
|
||||
document.addEventListener("visibilitychange", onVis);
|
||||
return () => {
|
||||
clearInterval(t);
|
||||
document.removeEventListener("visibilitychange", onVis);
|
||||
};
|
||||
}, [load]);
|
||||
|
||||
useEffect(() => {
|
||||
if (rows !== null) signalBootReady();
|
||||
}, [rows, signalBootReady]);
|
||||
|
||||
const categories = useMemo(() => {
|
||||
const s = new Set<string>();
|
||||
for (const m of rows ?? []) {
|
||||
if (m.category?.trim()) s.add(m.category.trim());
|
||||
}
|
||||
return ["__all__", ...[...s].sort()];
|
||||
}, [rows]);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
let list = rows ?? [];
|
||||
if (filterCat !== "__all__") list = list.filter((m) => (m.category || "").trim() === filterCat);
|
||||
const qq = q.trim().toLowerCase();
|
||||
if (qq) {
|
||||
list = list.filter(
|
||||
(m) =>
|
||||
m.display_name.toLowerCase().includes(qq) ||
|
||||
m.model.toLowerCase().includes(qq) ||
|
||||
m.api_base_url.toLowerCase().includes(qq)
|
||||
);
|
||||
}
|
||||
return list;
|
||||
}, [rows, filterCat, q]);
|
||||
|
||||
const online = (rows ?? []).filter((m) => m.lastProbe?.ok === 1).length;
|
||||
const offline = (rows ?? []).filter((m) => m.lastProbe && m.lastProbe.ok !== 1).length;
|
||||
|
||||
return (
|
||||
<div className="page dashboard">
|
||||
<section className="panel-intro">
|
||||
<div className="status-line">
|
||||
<span className="dot ok" />
|
||||
<span>
|
||||
{online} 在线 | <span className="muted">{offline} 离线</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="toolbar">
|
||||
<div className="pills">
|
||||
{categories.map((c) => (
|
||||
<button
|
||||
key={c}
|
||||
type="button"
|
||||
className={`pill ${filterCat === c ? "active" : ""}`}
|
||||
onClick={() => setFilterCat(c)}
|
||||
>
|
||||
{c === "__all__" ? "全部" : c}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label className="search">
|
||||
<span className="sr-only">搜索</span>
|
||||
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder="搜索名称、模型或地址…" />
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{err ? <p className="banner error">{err}</p> : null}
|
||||
|
||||
{rows?.length === 0 ? <p className="muted">暂无监控项。请从管理入口添加。</p> : null}
|
||||
|
||||
<div className="card-grid">
|
||||
{filtered.map((m) => (
|
||||
<MonitorCard key={m.id} m={m} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
225
frontend/src/splash.css
Normal file
225
frontend/src/splash.css
Normal file
@@ -0,0 +1,225 @@
|
||||
.splash-screen {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 10000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
background: linear-gradient(
|
||||
145deg,
|
||||
#dfe6eb 0%,
|
||||
#e8f4ec 28%,
|
||||
#d8efe3 55%,
|
||||
#cfe8d8 78%,
|
||||
#c5e2d2 100%
|
||||
);
|
||||
animation: splash-bg-pulse 5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.splash-bg-glow {
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
pointer-events: none;
|
||||
filter: blur(48px);
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.splash-bg-glow--a {
|
||||
width: min(72vw, 420px);
|
||||
height: min(72vw, 420px);
|
||||
top: 12%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: radial-gradient(circle, rgba(46, 204, 113, 0.45) 0%, transparent 70%);
|
||||
animation: splash-glow-drift 6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.splash-bg-glow--b {
|
||||
width: min(55vw, 320px);
|
||||
height: min(55vw, 320px);
|
||||
bottom: 8%;
|
||||
right: 8%;
|
||||
background: radial-gradient(circle, rgba(39, 174, 96, 0.35) 0%, transparent 72%);
|
||||
animation: splash-glow-drift 7s ease-in-out infinite reverse;
|
||||
}
|
||||
|
||||
.splash-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.65rem;
|
||||
padding: 1.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.splash-logo-wrap {
|
||||
position: relative;
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
|
||||
.splash-rings {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.splash-ring {
|
||||
position: absolute;
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
border: 2px solid rgba(46, 204, 113, 0.55);
|
||||
border-radius: 50%;
|
||||
animation: splash-ring-expand 2.4s ease-out infinite;
|
||||
}
|
||||
|
||||
.splash-ring:nth-child(2) {
|
||||
animation-delay: 0.8s;
|
||||
}
|
||||
|
||||
.splash-ring:nth-child(3) {
|
||||
animation-delay: 1.6s;
|
||||
}
|
||||
|
||||
.splash-logo {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
object-fit: contain;
|
||||
border-radius: 22px;
|
||||
box-shadow:
|
||||
0 12px 32px rgba(15, 23, 42, 0.18),
|
||||
0 0 0 1px rgba(255, 255, 255, 0.65) inset;
|
||||
animation: splash-logo-float 2.8s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.splash-title {
|
||||
margin: 0;
|
||||
font-size: clamp(1.65rem, 5vw, 2rem);
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.02em;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.splash-subtitle {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 500;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.splash-dots {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.45rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.splash-dots span {
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 50%;
|
||||
background: var(--green, #2ecc71);
|
||||
animation: splash-dot-pulse 1.1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.splash-dots span:nth-child(2) {
|
||||
animation-delay: 0.18s;
|
||||
}
|
||||
|
||||
.splash-dots span:nth-child(3) {
|
||||
animation-delay: 0.36s;
|
||||
}
|
||||
|
||||
@keyframes splash-bg-pulse {
|
||||
0%,
|
||||
100% {
|
||||
filter: brightness(1);
|
||||
}
|
||||
50% {
|
||||
filter: brightness(1.04);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes splash-glow-drift {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateX(-50%) scale(1);
|
||||
opacity: 0.5;
|
||||
}
|
||||
50% {
|
||||
transform: translateX(-48%) scale(1.08);
|
||||
opacity: 0.72;
|
||||
}
|
||||
}
|
||||
|
||||
.splash-bg-glow--b {
|
||||
animation-name: splash-glow-drift-b;
|
||||
}
|
||||
|
||||
@keyframes splash-glow-drift-b {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
opacity: 0.4;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.1);
|
||||
opacity: 0.65;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes splash-logo-float {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-7px);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes splash-ring-expand {
|
||||
0% {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
100% {
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes splash-dot-pulse {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(0.65);
|
||||
opacity: 0.55;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.splash-screen,
|
||||
.splash-bg-glow,
|
||||
.splash-logo,
|
||||
.splash-ring,
|
||||
.splash-dots span {
|
||||
animation: none !important;
|
||||
}
|
||||
}
|
||||
55
frontend/src/types.ts
Normal file
55
frontend/src/types.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
export type MonitorProtocol = "openai" | "openai_responses" | "claude";
|
||||
|
||||
export type MonitorDto = {
|
||||
id: string;
|
||||
display_name: string;
|
||||
api_base_url: string;
|
||||
model: string;
|
||||
protocol: MonitorProtocol;
|
||||
interval_minutes: number;
|
||||
/** 1=流式,0=非流式 */
|
||||
probe_stream: number;
|
||||
/** 1=首页展示卡片,0=仅后台可见 */
|
||||
show_on_dashboard: number;
|
||||
enabled: number;
|
||||
category: string;
|
||||
created_at: number;
|
||||
last_run_at: number | null;
|
||||
next_run_at: number;
|
||||
availability24h: number | null;
|
||||
availability30d: number | null;
|
||||
probe_count: number;
|
||||
lastProbe: {
|
||||
ts: number;
|
||||
ok: number;
|
||||
first_token_ms: number | null;
|
||||
http_status: number | null;
|
||||
error_message: string | null;
|
||||
probe_input: string | null;
|
||||
probe_output: string | null;
|
||||
} | null;
|
||||
timelineDaily: Array<{ t: number; up: boolean; ratio: number; hasData: boolean }>;
|
||||
};
|
||||
|
||||
/** 管理后台列表与公开面板共用数据结构(后台接口含统计字段) */
|
||||
export type AdminMonitorRow = MonitorDto;
|
||||
|
||||
/** /api/admin/probe-settings 与后台表单 */
|
||||
export type GlobalProbeSettings = {
|
||||
probe_interval_minutes: number;
|
||||
probe_prompts: string;
|
||||
};
|
||||
|
||||
export const ADMIN_TOKEN_KEY = "modelping_admin_token";
|
||||
|
||||
export function getAdminToken(): string | null {
|
||||
return sessionStorage.getItem(ADMIN_TOKEN_KEY);
|
||||
}
|
||||
|
||||
export function setAdminToken(token: string): void {
|
||||
sessionStorage.setItem(ADMIN_TOKEN_KEY, token);
|
||||
}
|
||||
|
||||
export function clearAdminToken(): void {
|
||||
sessionStorage.removeItem(ADMIN_TOKEN_KEY);
|
||||
}
|
||||
2
frontend/src/vite-env.d.ts
vendored
Normal file
2
frontend/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference types="vite-plugin-pwa/client" />
|
||||
Reference in New Issue
Block a user