chore: initial commit - maqt-desktop v0.2
- Phase 1-5: UI framework, auth, weapon schemes, color filters, system optimization - Industrial/tech design style with Chinese localization - Points to gch3n.online/delta backend API - Hardware monitor, filter editor, and all module pages
This commit is contained in:
140
src/pages/Login.tsx
Normal file
140
src/pages/Login.tsx
Normal file
@@ -0,0 +1,140 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import Button from '../components/ui/Button';
|
||||
import Input from '../components/ui/Input';
|
||||
import Card from '../components/ui/Card';
|
||||
import { useAuth } from '../hooks/useAuth';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
import { getVipStatus, activateVip } from '../services/auth.api';
|
||||
|
||||
export default function Login() {
|
||||
const navigate = useNavigate();
|
||||
const { login } = useAuth();
|
||||
const isLoggedIn = useAuthStore(s => s.isLoggedIn);
|
||||
|
||||
const [tab, setTab] = useState<'login' | 'register' | 'vip'>('login');
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [cardKey, setCardKey] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const handleLogin = async () => {
|
||||
setLoading(true); setError('');
|
||||
try {
|
||||
await login({
|
||||
username, password,
|
||||
installId: 'maqt-desktop',
|
||||
deviceHash: 'maqt-desktop',
|
||||
platform: navigator.platform || 'win32',
|
||||
osVersion: navigator.userAgent || '',
|
||||
appVersion: '7.0.4',
|
||||
});
|
||||
navigate('/');
|
||||
} catch (e: any) {
|
||||
setError(e.message || '登录失败');
|
||||
} finally { setLoading(false); }
|
||||
};
|
||||
|
||||
const handleActivateVip = async () => {
|
||||
setLoading(true); setError('');
|
||||
try {
|
||||
await activateVip(cardKey);
|
||||
const status = await getVipStatus();
|
||||
if (status) navigate('/');
|
||||
} catch (e: any) {
|
||||
setError(e.message || '激活失败');
|
||||
} finally { setLoading(false); }
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-screen bg-[#1a1a1a] flex flex-col items-center justify-center p-6">
|
||||
{/* 品牌 */}
|
||||
<div className="text-center mb-6">
|
||||
<h1 className="text-[14px] font-bold tracking-[0.2em] uppercase text-[#e0e0e0]">码枪堂 2.0</h1>
|
||||
<p className="text-[8px] font-mono text-[#555] mt-1">用户认证系统</p>
|
||||
</div>
|
||||
|
||||
{/* 认证卡片 */}
|
||||
<Card className="w-full max-w-xs" serial="AUTH-01">
|
||||
{/* 标签页 */}
|
||||
<div className="flex border-b border-[#333]">
|
||||
{(['login', 'register', 'vip'] as const).map(t => (
|
||||
<button
|
||||
key={t}
|
||||
onClick={() => setTab(t)}
|
||||
className={`flex-1 py-2 text-[8px] font-semibold tracking-[0.12em] uppercase transition-colors duration-75
|
||||
border-r border-[#333] last:border-r-0
|
||||
${tab === t ? 'bg-[#ff4500]/10 text-[#ff4500]' : 'text-[#555] hover:text-[#888]'}`}
|
||||
>
|
||||
{t === 'login' ? '登录' : t === 'register' ? '注册' : 'VIP'}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 表单 */}
|
||||
<div className="p-3 space-y-2.5">
|
||||
{tab === 'vip' ? (
|
||||
<>
|
||||
<Input
|
||||
placeholder="VIP 卡密"
|
||||
value={cardKey}
|
||||
onChange={e => setCardKey(e.target.value)}
|
||||
style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }}
|
||||
/>
|
||||
<Button variant="primary" size="sm" className="w-full text-[9px]" onClick={handleActivateVip} loading={loading}>
|
||||
激活 VIP
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Input
|
||||
placeholder="用户名"
|
||||
value={username}
|
||||
onChange={e => setUsername(e.target.value)}
|
||||
style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }}
|
||||
/>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="密码"
|
||||
value={password}
|
||||
onChange={e => setPassword(e.target.value)}
|
||||
style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }}
|
||||
/>
|
||||
{tab === 'register' && (
|
||||
<Input
|
||||
placeholder="邮箱(可选)"
|
||||
value={email}
|
||||
onChange={e => setEmail(e.target.value)}
|
||||
style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }}
|
||||
/>
|
||||
)}
|
||||
<Button variant="primary" size="sm" className="w-full text-[9px]" onClick={handleLogin} loading={loading}>
|
||||
{tab === 'login' ? '登录' : '注册'}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<p className="text-[8px] font-mono text-[#cc3300] border border-[#cc3300]/30 p-1.5 bg-[#cc3300]/5">
|
||||
✕ {error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<p className="text-[7px] font-mono text-[#444] text-center">
|
||||
SYS-AUTH v1.0
|
||||
</p>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 返回 */}
|
||||
<button
|
||||
onClick={() => navigate('/')}
|
||||
className="mt-4 text-[8px] font-mono text-[#555] hover:text-[#888] transition-colors duration-75"
|
||||
>
|
||||
← 返回桌面
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user