import { FlaskConical, ListChecks, LogOut, Plus, Radar, Server, Settings } from 'lucide-react' import { useState, type FormEvent } from 'react' import { NavLink, Navigate, Route, Routes } from 'react-router-dom' import { activateSource, getBase, listSources } from '@shared/api/source' import { describeError, Field, SourceButton, Spinner, ThemeToggle } from '@shared/ui' import { useAuth } from './auth' import { AgentDetail } from './pages/AgentDetail' import { Agents } from './pages/Agents' import { Probes } from './pages/Probes' import { System } from './pages/System' import { Tasks } from './pages/Tasks' import { Tests } from './pages/Tests' /** 登录页:左边选后端(这个页面自己所在的,或保存过的,或添加一个),右边都是用户名 + 密码。 */ function Login() { const { login } = useAuth() const active = getBase() const saved = listSources() const [adding, setAdding] = useState(false) const [url, setUrl] = useState('') const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [busy, setBusy] = useState(false) const choose = (base: string) => { setAdding(false) setError('') setPassword('') if (base !== active) { activateSource(base) location.reload() } } const submit = async (e: FormEvent) => { e.preventDefault() setBusy(true) setError('') try { await login(username, password, adding ? url : undefined) } catch (err) { setError(describeError(err)) } finally { setBusy(false) } } const rows = [{ base: '', label: location.host }, ...saved.map((x) => ({ base: x.base, label: x.base.replace(/^https?:\/\//i, '') }))] const title = adding ? '添加后端' : active ? active.replace(/^https?:\/\//i, '') : location.origin return (

{title}

{adding ? ( setUrl(e.target.value)} placeholder="例如 https://你的域名" autoComplete="off" autoFocus required /> ) : null} setUsername(e.target.value)} autoComplete="username" autoFocus={!adding} required /> setPassword(e.target.value)} autoComplete="current-password" required /> {error ?
{error}
: null}
) } const NAV = [ { section: '运维', items: [{ to: '/agents', label: 'Agent', icon: Server }, { to: '/probes', label: 'Probe', icon: Radar }] }, { section: '测试', items: [{ to: '/tasks', label: '任务', icon: ListChecks }, { to: '/tests', label: '按需测试', icon: FlaskConical }] }, { section: '系统', items: [{ to: '/system', label: '系统', icon: Settings }] }, ] export function App() { const { me, ready, logout } = useAuth() if (!ready) { return (
) } if (!me) return return (
} /> } /> } /> } /> } /> } /> } /> } />
) }