'use client' // shared/ui/login-page.tsx — 统一登录页组件(与 issue-ai 登录页风格一致) import { useState } from 'react' interface LoginPageProps { siteName: string // 站点名称,如 "IT 工单跟踪系统"、"告警监控中心" title?: string // 副标题(可选),如 "monitor-ai" } export default function LoginPage({ siteName, title }: LoginPageProps) { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const [showLdapForm, setShowLdapForm] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true) try { const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }) }) const data = await res.json() if (!res.ok) { setError(data.error || '登录失败'); return } const params = new URLSearchParams(window.location.search) const redirect = params.get('redirect') const dest = (redirect && redirect.startsWith('/')) ? redirect : '/' window.location.href = dest } catch { setError('网络错误') } finally { setLoading(false) } } function handleSsoLogin() { window.location.href = '/api/auth/login/oidc' } return (
{title}
} {!title && } {error && (通过 SSO 统一身份认证
> ) : ( <>
> )}