feat(ui): 重做登录页并替换默认站点图标

- 登录页改为左侧品牌区 + 右侧表单卡,补字段标签、三步流程与 DCAuth 等待面板
- 新增自定义站点图标(SVG / ICO / apple-touch-icon / 192 / 512)
- index.html 补齐图标、theme-color 与页面描述
- 修复 client.ts 中既有的 any 类型告警
This commit is contained in:
yml2213
2026-10-21 22:04:44 +08:00
parent 2f5a63ae27
commit 3761267015
9 changed files with 749 additions and 154 deletions
+268 -150
View File
@@ -1,11 +1,16 @@
import { useEffect, useRef, useState } from 'react';
import { Alert, Button, Card, Divider, Form, Input, Space, Typography } from 'antd';
import { Button, Form, Input, Space, Typography } from 'antd';
import type { InputRef } from 'antd';
import { message } from '../utils/antdMessage';
import {
ArrowLeftOutlined,
DesktopOutlined,
LoadingOutlined,
LockOutlined,
MobileOutlined,
ReloadOutlined,
SafetyCertificateOutlined,
SafetyOutlined,
UserOutlined,
} from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
@@ -16,11 +21,50 @@ import { getErrorMessage } from '../utils/error';
import { useTheme } from '../store/useTheme';
import { useAppInfo } from '../hooks/useAppInfo';
const { Title, Text } = Typography;
const { Text } = Typography;
type LoginMode = 'secure' | 'legacy';
type LoginValues = { username: string; password: string; smsCode?: string };
const FLOW_STEPS = [
{ title: '账号密码', icon: <LockOutlined /> },
{ title: '短信验证码', icon: <MobileOutlined /> },
{ title: '本机确认', icon: <SafetyCertificateOutlined /> },
];
const BRAND_FEATURES = [
{ icon: <LockOutlined />, title: '账号密码', desc: '第一重校验,拒绝弱口令' },
{ icon: <MobileOutlined />, title: '短信验证码', desc: '绑定手机接收一次性验证码' },
{ icon: <DesktopOutlined />, title: '本机 DCAuth', desc: 'Ed25519 设备签名,换机即失效' },
];
function LogoMark({ size = 40 }: { size?: number }) {
return (
<svg
className="login-logo"
width={size}
height={size}
viewBox="0 0 64 64"
role="img"
aria-label="直播运营后台"
>
<defs>
<linearGradient id="loginBrand" x1="4" y1="2" x2="60" y2="62" gradientUnits="userSpaceOnUse">
<stop offset="0" stopColor="#6366F1" />
<stop offset="0.55" stopColor="#3B82F6" />
<stop offset="1" stopColor="#06B6D4" />
</linearGradient>
</defs>
<rect width="64" height="64" rx="17" fill="url(#loginBrand)" />
<path
d="M25.6 20.4c0-1.15 1.26-1.86 2.24-1.26l18.2 11.6c.94.6.94 1.98 0 2.58l-18.2 11.6c-.98.6-2.24-.11-2.24-1.26V20.4Z"
fill="#fff"
/>
<circle cx="47.5" cy="16.5" r="6.2" fill="#F43F5E" stroke="#0B1020" strokeWidth="2.6" />
</svg>
);
}
function errorCodeOf(error: unknown): string {
return (error as { errorCode?: string } | null)?.errorCode || '';
}
@@ -228,161 +272,235 @@ export default function LoginPage({ onLogin }: { onLogin?: () => void }) {
}
return (
<div
style={{
minHeight: '100vh',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
background: isDark
? 'linear-gradient(135deg, #1a1a2e 0%, #16213e 100%)'
: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
}}
>
<Card
style={{
width: 420,
boxShadow: isDark ? '0 8px 24px rgba(0,0,0,0.4)' : '0 8px 24px rgba(0,0,0,0.15)',
}}
>
<Title level={3} style={{ textAlign: 'center', marginBottom: 32 }}>
直播运营后台
</Title>
<Text
type="secondary"
style={{
display: 'block',
textAlign: 'center',
marginTop: -20,
marginBottom: 24,
fontSize: 12,
}}
>
当前版本 {versionText}
</Text>
<div className={`login-page${isDark ? ' is-dark' : ''}`}>
<div className="login-backdrop" aria-hidden="true" />
<div className="login-shell">
<aside className="login-brand">
<div className="login-brand-head">
<LogoMark size={44} />
<div>
<strong>直播运营后台</strong>
<span>Live Operations Console</span>
</div>
</div>
{mode === 'secure' ? (
<>
<Alert
type="info"
showIcon
message="安全登录"
description="用户名密码验证后,还需短信验证码和本机 DCAuth 设备签名。"
style={{ marginBottom: 16 }}
/>
<div className="login-brand-body">
<h1>
安全登录,
<br />
从这台设备开始
</h1>
<p>账号密码、短信验证码与本机 DCAuth 签名三重校验,账号被盗也进不来。</p>
{waiting ? (
<Alert
type="warning"
showIcon
message="等待本机确认"
description={
<Space direction="vertical" size={4} style={{ width: '100%' }}>
<span>请在弹出的 DCAuth 窗口中点击确认。若未弹出,请先安装并运行一次 DCAuth。</span>
{launchUrl ? (
<Text code copyable={{ text: launchUrl }} style={{ wordBreak: 'break-all' }}>
{launchUrl}
<ul className="login-features">
{BRAND_FEATURES.map((item) => (
<li key={item.title}>
<span className="login-feature-icon">{item.icon}</span>
<span>
<strong>{item.title}</strong>
<em>{item.desc}</em>
</span>
</li>
))}
</ul>
</div>
<div className="login-brand-foot">
<span className="login-version">{versionText}</span>
<span>仅限内部运营人员使用</span>
</div>
</aside>
<section className="login-card">
<header className="login-card-head">
<LogoMark size={46} />
<div>
<h2>{mode === 'secure' ? '安全登录' : '密码登录'}</h2>
<p>
直播运营后台 · <span>{versionText}</span>
</p>
</div>
</header>
{mode === 'secure' ? (
<>
<ol className="login-steps">
{FLOW_STEPS.map((step, index) => (
<li
key={step.title}
className={waiting && index === 2 ? 'is-active' : undefined}
>
<span className="login-step-icon">{step.icon}</span>
<span>{step.title}</span>
</li>
))}
</ol>
{waiting ? (
<div className="login-waiting">
<span className="login-waiting-icon">
<LoadingOutlined />
</span>
<div className="login-waiting-body">
<strong>等待本机确认</strong>
<p>请在 DCAuth 弹窗中点击「允许登录」;没弹出就点下面按钮重新唤起。</p>
<Space size={8} wrap>
<Button
size="small"
icon={<ReloadOutlined />}
onClick={() => launchProtocol(launchUrl)}
>
重新唤起 DCAuth
</Button>
<Text code copyable={{ text: launchUrl }} className="login-copy">
复制协议链接
</Text>
) : null}
</Space>
}
style={{ marginBottom: 16 }}
/>
) : null}
</Space>
</div>
</div>
) : null}
<Form form={form} onFinish={handleSecureLogin} size="large" requiredMark={false}>
<Form.Item name="username" rules={[{ required: true, message: '请输入用户名' }]}>
<Input
prefix={<UserOutlined />}
placeholder="用户名(中文 / 英文 / 数字)"
autoComplete="username"
/>
</Form.Item>
<Form.Item name="password" rules={[{ required: true, message: '请输入密码' }]}>
<Input.Password
prefix={<LockOutlined />}
placeholder="密码"
autoComplete="current-password"
ref={passwordRef}
/>
</Form.Item>
<Form.Item
name="smsCode"
rules={[{ required: true, message: '请输入短信验证码' }]}
<Form
form={form}
layout="vertical"
className="login-form"
onFinish={handleSecureLogin}
size="large"
requiredMark={false}
>
<Input
prefix={<SafetyCertificateOutlined />}
placeholder={phoneMasked ? `6 位验证码(${phoneMasked})` : '6 位短信验证码'}
maxLength={6}
autoComplete="one-time-code"
addonAfter={
<Button
type="link"
size="small"
htmlType="button"
loading={sendingCode}
disabled={countdown > 0 || loading}
onClick={() => void sendCode()}
style={{ padding: 0, height: 'auto' }}
>
{countdown > 0 ? `${countdown}s 后重发` : '获取验证码'}
</Button>
}
/>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" loading={loading} block>
安全登录 · 拉起本机验证
</Button>
</Form.Item>
</Form>
<Form.Item
label="账号"
name="username"
rules={[{ required: true, message: '请输入用户名' }]}
>
<Input
prefix={<UserOutlined />}
placeholder="中文 / 英文 / 数字账号"
autoComplete="username"
disabled={waiting}
/>
</Form.Item>
<Form.Item
label="密码"
name="password"
rules={[{ required: true, message: '请输入密码' }]}
>
<Input.Password
prefix={<LockOutlined />}
placeholder="请输入登录密码"
autoComplete="current-password"
ref={passwordRef}
disabled={waiting}
/>
</Form.Item>
<Form.Item
label="短信验证码"
name="smsCode"
rules={[{ required: true, message: '请输入短信验证码' }]}
>
<Input
prefix={<SafetyOutlined />}
placeholder={phoneMasked ? `已发送至 ${phoneMasked}` : '6 位数字验证码'}
maxLength={6}
inputMode="numeric"
autoComplete="one-time-code"
disabled={waiting}
addonAfter={
<Button
type="link"
size="small"
htmlType="button"
loading={sendingCode}
disabled={countdown > 0 || loading || waiting}
onClick={() => void sendCode()}
className="login-code-btn"
>
{countdown > 0 ? `${countdown}s 后重发` : '获取验证码'}
</Button>
}
/>
</Form.Item>
<Form.Item className="login-submit-item">
<Button type="primary" htmlType="submit" loading={loading} block>
{waiting ? '等待本机确认…' : '安全登录 · 验证本机'}
</Button>
</Form.Item>
</Form>
<Divider plain style={{ margin: '4px 0 12px' }}>
<Text type="secondary" style={{ fontSize: 12 }}>
未绑定手机号的旧账号
</Text>
</Divider>
<Button type="link" block onClick={() => switchMode('legacy')} disabled={loading}>
旧账号仅密码登录
</Button>
</>
) : (
<>
<Alert
type="warning"
showIcon
message="旧账号仅密码登录"
description="仅未绑定手机号的账号可用;已绑定手机号的账号会被要求使用安全登录。"
style={{ marginBottom: 16 }}
/>
<Form form={form} onFinish={handleLegacyLogin} size="large" requiredMark={false}>
<Form.Item name="username" rules={[{ required: true, message: '请输入用户名' }]}>
<Input
prefix={<UserOutlined />}
placeholder="用户名"
autoComplete="username"
/>
</Form.Item>
<Form.Item name="password" rules={[{ required: true, message: '请输入密码' }]}>
<Input.Password
prefix={<LockOutlined />}
placeholder="密码"
autoComplete="current-password"
ref={passwordRef}
/>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" loading={loading} block>
密码登录
<div className="login-switch">
<span>未绑定手机号的旧账号</span>
<Button
type="link"
size="small"
onClick={() => switchMode('legacy')}
disabled={loading || waiting}
>
仅密码登录
</Button>
</Form.Item>
</Form>
<Button type="link" block onClick={() => switchMode('secure')} disabled={loading}>
<MobileOutlined /> 返回安全登录
</Button>
</>
)}
</Card>
</div>
</>
) : (
<>
<div className="login-notice">
<SafetyCertificateOutlined />
<span>
仅未绑定手机号的账号可用;已绑定手机号的账号会被要求使用安全登录。
</span>
</div>
<Form
form={form}
layout="vertical"
className="login-form"
onFinish={handleLegacyLogin}
size="large"
requiredMark={false}
>
<Form.Item
label="账号"
name="username"
rules={[{ required: true, message: '请输入用户名' }]}
>
<Input
prefix={<UserOutlined />}
placeholder="中文 / 英文 / 数字账号"
autoComplete="username"
/>
</Form.Item>
<Form.Item
label="密码"
name="password"
rules={[{ required: true, message: '请输入密码' }]}
>
<Input.Password
prefix={<LockOutlined />}
placeholder="请输入登录密码"
autoComplete="current-password"
ref={passwordRef}
/>
</Form.Item>
<Form.Item className="login-submit-item">
<Button type="primary" htmlType="submit" loading={loading} block>
密码登录
</Button>
</Form.Item>
</Form>
<div className="login-switch login-switch-center">
<Button
type="link"
size="small"
icon={<ArrowLeftOutlined />}
onClick={() => switchMode('secure')}
disabled={loading}
>
返回安全登录
</Button>
</div>
</>
)}
</section>
</div>
</div>
);
}