Ship brand favicons and install-to-home manifests for nomadro.cn and admin, improve admin mobile drawer UX, and keep the game module forced off. Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { FormEvent, useState } from 'react'
|
||
import { useNavigate } from 'react-router-dom'
|
||
import { api, setToken } from '../api'
|
||
|
||
export default function Login() {
|
||
const nav = useNavigate()
|
||
const [username, setUsername] = useState('admin')
|
||
const [password, setPassword] = useState('')
|
||
const [err, setErr] = useState('')
|
||
const [loading, setLoading] = useState(false)
|
||
|
||
async function onSubmit(e: FormEvent) {
|
||
e.preventDefault()
|
||
setLoading(true)
|
||
setErr('')
|
||
try {
|
||
const data = await api<{ token: string }>('/api/admin/login', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ username, password }),
|
||
})
|
||
setToken(data.token)
|
||
nav('/')
|
||
} catch (ex: any) {
|
||
setErr(ex.message || '登录失败')
|
||
} finally {
|
||
setLoading(false)
|
||
}
|
||
}
|
||
|
||
return (
|
||
<div className="login-page">
|
||
<div className="login-bg" />
|
||
<form className="login-card" onSubmit={onSubmit}>
|
||
<div className="login-brand">
|
||
<img src="/apple-touch-icon.png" width={56} height={56} alt="Nomadro" />
|
||
<div>
|
||
<h1>Nomadro Admin</h1>
|
||
<p>微信 / 抖音小程序后台 · 可添加到手机桌面</p>
|
||
</div>
|
||
</div>
|
||
<label>
|
||
用户名
|
||
<input value={username} onChange={(e) => setUsername(e.target.value)} autoComplete="username" />
|
||
</label>
|
||
<label>
|
||
密码
|
||
<input
|
||
type="password"
|
||
value={password}
|
||
onChange={(e) => setPassword(e.target.value)}
|
||
autoComplete="current-password"
|
||
enterKeyHint="go"
|
||
/>
|
||
</label>
|
||
{err && <div className="error">{err}</div>}
|
||
<button disabled={loading}>{loading ? '登录中…' : '进入控制台'}</button>
|
||
<p className="login-install-hint">
|
||
iPhone:Safari 分享 →「添加到主屏幕」· Android:浏览器菜单 →「安装应用 / 添加到主屏幕」
|
||
</p>
|
||
</form>
|
||
</div>
|
||
)
|
||
}
|