feat: #21 login-page.tsx 添加 localadmin hidden 入口 (?method=local)
This commit is contained in:
parent
d62dcd2f82
commit
bde6c77f11
|
|
@ -1,6 +1,7 @@
|
|||
'use client'
|
||||
// shared/ui/login-page.tsx — 统一登录页组件(与 issue-ai 登录页风格一致)
|
||||
import { useState } from 'react'
|
||||
// shared/ui/login-page.tsx — 统一登录页组件
|
||||
// 支持 SSO、LDAP 和 localadmin(通过 ?method=local URL 参数激活)三种登录方式
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
interface LoginPageProps {
|
||||
siteName: string // 站点名称,如 "IT 工单跟踪系统"、"告警监控中心"
|
||||
|
|
@ -14,6 +15,12 @@ export default function LoginPage({ siteName, title, redirectPath = '/' }: Login
|
|||
const [error, setError] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [showLdapForm, setShowLdapForm] = useState(false)
|
||||
const [showLocalAdmin, setShowLocalAdmin] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
if (params.get('method') === 'local') setShowLocalAdmin(true)
|
||||
}, [])
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault(); setError(''); setLoading(true)
|
||||
|
|
@ -47,7 +54,7 @@ export default function LoginPage({ siteName, title, redirectPath = '/' }: Login
|
|||
<div className="mb-4 p-3 rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-600 dark:text-red-400 text-sm">{error}</div>
|
||||
)}
|
||||
|
||||
{!showLdapForm ? (
|
||||
{!showLdapForm && !showLocalAdmin ? (
|
||||
<>
|
||||
<button
|
||||
onClick={handleSsoLogin}
|
||||
|
|
@ -73,6 +80,43 @@ export default function LoginPage({ siteName, title, redirectPath = '/' }: Login
|
|||
</button>
|
||||
</p>
|
||||
</>
|
||||
) : showLocalAdmin ? (
|
||||
<>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">用户名</label>
|
||||
<input
|
||||
type="text" value={username} onChange={(e) => setUsername(e.target.value)}
|
||||
placeholder="请输入用户名"
|
||||
className="w-full px-3 py-2 rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-900 dark:text-white placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">密码</label>
|
||||
<input
|
||||
type="password" value={password} onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="请输入密码"
|
||||
className="w-full px-3 py-2 rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-900 dark:text-white placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit" disabled={loading}
|
||||
className="w-full py-2 px-4 rounded-lg bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium transition-colors duration-200"
|
||||
>
|
||||
{loading ? '登录中...' : '本地管理员登录'}
|
||||
</button>
|
||||
</form>
|
||||
<p className="text-center mt-3">
|
||||
<button
|
||||
onClick={() => { window.location.href = '/login' }}
|
||||
className="text-xs text-slate-400 hover:text-slate-600 dark:hover:text-slate-300 underline"
|
||||
>
|
||||
返回普通登录
|
||||
</button>
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
|
|
|
|||
Loading…
Reference in New Issue