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'; function callElectron(method: string) { try { (window as any).electronAPI?.[method](); } catch {} } 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 (
{/* 关闭按钮 */}

码枪堂 2.0

用户认证系统

{(['login', 'register', 'vip'] as const).map(t => ( ))}
{tab === 'vip' ? ( <> setCardKey(e.target.value)} style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }} /> ) : ( <> setUsername(e.target.value)} style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }} /> setPassword(e.target.value)} style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }} /> {tab === 'register' && ( setEmail(e.target.value)} style={{ borderRadius: 0, borderColor: '#333', background: '#111', color: '#e0e0e0', fontSize: 10 }} /> )} )} {error && (

✕ {error}

)}

SYS-AUTH v1.0

); }