From 984a53f2ae28d1762a01c3fb92381c6bc2d3bd22 Mon Sep 17 00:00:00 2001 From: Rogee Date: Tue, 22 Sep 2026 13:35:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E8=A1=A5=E5=9B=9E=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E7=9A=84=E7=99=BB=E5=BD=95=E9=A1=B5=EF=BC=88task-3=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=B7=AF=E7=94=B1=E6=97=B6=E8=AF=AF=E5=88=A0?= =?UTF-8?q?=EF=BC=8C=E5=AE=A1=E8=AE=A1=E5=8F=91=E7=8E=B0=E8=87=B4=E5=91=BD?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/login/index.tsx | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 web/src/pages/login/index.tsx diff --git a/web/src/pages/login/index.tsx b/web/src/pages/login/index.tsx new file mode 100644 index 0000000..c94eff5 --- /dev/null +++ b/web/src/pages/login/index.tsx @@ -0,0 +1,63 @@ +// 登录页:语义对齐 web.archived/src/app/LoginPage.jsx(提交 d97cade)。 +// 提交 GET /api/gateways 校验 Basic 凭证,成功后写入 localStorage('creatorhub.auth') 并跳转首页。 +// 仅用 antd 默认组件:Card/Form/Input/Button/Alert。 +import { history } from '@umijs/max'; +import { Alert, Button, Card, Form, Input, Typography } from 'antd'; +import { useState } from 'react'; + +interface FormValues { + username: string; + password: string; +} + +export default function Page() { + const [form] = Form.useForm(); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(''); + + async function onFinish({ username, password }: FormValues) { + setBusy(true); + setError(''); + const controller = new AbortController(); + const timer = window.setTimeout(() => controller.abort(), 15000); + try { + const response = await fetch('/api/gateways', { + headers: { Authorization: `Basic ${btoa(`${username}:${password}`)}` }, + signal: controller.signal, + }); + if (response.status === 401) throw new Error('用户名或密码不正确'); + if (!response.ok) throw new Error(`认证服务不可用(${response.status})`); + localStorage.setItem('creatorhub.auth', `${username}:${password}`); + history.replace('/accounts'); + } catch (reason: any) { + setError( + reason.name === 'AbortError' ? '认证请求超时,请检查控制面连接' : reason.message || '登录失败', + ); + } finally { + window.clearTimeout(timer); + setBusy(false); + } + } + + return ( +
+ + + CreatorHub + + {error ? : null} +
+ + + + + + + +
+
+
+ ); +}