From 86da43b635e12671cc6b031791313ada17c1308a Mon Sep 17 00:00:00 2001 From: que01 Date: Sat, 19 Sep 2026 18:29:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=80=81=E4=B8=8E=E9=80=80=E5=87=BA=E4=BD=93?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/src/main.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/admin/src/main.tsx b/apps/admin/src/main.tsx index 0154965..7dbc36e 100644 --- a/apps/admin/src/main.tsx +++ b/apps/admin/src/main.tsx @@ -8,7 +8,15 @@ import "antd/dist/reset.css"; const apiBaseUrl = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:3001"; const queryClient = new QueryClient(); -const api = () => new ApiClient({ baseUrl: apiBaseUrl, token: localStorage.getItem("adminToken") ?? undefined, fetcher: (input, init) => fetch(input, init) }); +async function authenticatedFetch(input: RequestInfo | URL, init?: RequestInit): Promise { + const response = await fetch(input, init); + if (response.status === 401) { + localStorage.removeItem("adminToken"); + window.dispatchEvent(new Event("admin-auth-expired")); + } + return response; +} +const api = () => new ApiClient({ baseUrl: apiBaseUrl, token: localStorage.getItem("adminToken") ?? undefined, fetcher: authenticatedFetch }); function Login({ onLogin }: { onLogin: () => void }) { const [form] = Form.useForm(); @@ -56,7 +64,7 @@ function InquiriesPage() { return update.mutate({ id: item.id, nextStatus: nextStatus as never })} options={bookingStatusOptions.map((value) => ({ value, label: bookingStatusLabels[value] }))} /> }]} />; } -function Dashboard() { const [page, setPage] = useState("brand"); return 个人品牌 setPage(key)} items={[{ key: "brand", label: "品牌信任" }, { key: "trust", label: "信任内容" }, { key: "services", label: "服务与合作" }, { key: "inquiries", label: "咨询记录" }]} />品牌管理后台{page === "brand" ? : page === "trust" ? : page === "services" ? : }; } +function Dashboard({ onLogout }: { onLogout: () => void }) { const [page, setPage] = useState("brand"); return 个人品牌 setPage(key)} items={[{ key: "brand", label: "品牌信任" }, { key: "trust", label: "信任内容" }, { key: "services", label: "服务与合作" }, { key: "inquiries", label: "咨询记录" }]} />品牌管理后台{page === "brand" ? : page === "trust" ? : page === "services" ? : }; } -function Root() { const [loggedIn, setLoggedIn] = useState(Boolean(localStorage.getItem("adminToken"))); return loggedIn ? : setLoggedIn(true)} />; } +function Root() { const [loggedIn, setLoggedIn] = useState(Boolean(localStorage.getItem("adminToken"))); React.useEffect(() => { const expire = () => { message.warning("登录状态已失效,请重新登录"); setLoggedIn(false); }; window.addEventListener("admin-auth-expired", expire); return () => window.removeEventListener("admin-auth-expired", expire); }, []); const logout = () => { localStorage.removeItem("adminToken"); setLoggedIn(false); }; return loggedIn ? : setLoggedIn(true)} />; } createRoot(document.getElementById("app")!).render();