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 (