Files
sundynix-pets/pets-be/web/admin/src/pages/Login.tsx
T
Blizzard 609f7d06cf init: 毛孩子计划 小程序 + Go 后端 + 内嵌后台
- pets-fe: 微信原生小程序(首页/计划/记录/报告/社区/引导),
  服务端驱动、无假数据;弹层改用 scroll-view,打开时隐藏自定义 tabBar
- pets-be: Gin + GORM(MySQL, sundynix_ 前缀) + MinIO,统一响应/分页,
  微信 code2session 登录,provider-neutral AI(DeepSeek),go:embed React 后台
- 修复:分段选择类型不匹配(字符串 vs 数字)导致选不中

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 15:36:55 +08:00

58 lines
2.0 KiB
TypeScript

import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { api, setToken } from '@/lib/api'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
export default function Login() {
const [username, setUsername] = useState('sundynix')
const [password, setPassword] = useState('sundynix')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
const navigate = useNavigate()
async function submit(e: React.FormEvent) {
e.preventDefault()
setLoading(true)
setError('')
try {
const res = await api.login(username, password)
setToken(res.token)
navigate('/')
} catch (err: any) {
setError(err.message || '登录失败')
} finally {
setLoading(false)
}
}
return (
<div className="flex min-h-screen items-center justify-center p-4">
<Card className="w-full max-w-sm">
<CardHeader>
<div className="text-3xl text-center mb-2">🐾</div>
<CardTitle className="text-center text-xl"> · </CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={submit} className="space-y-4">
<div className="space-y-1.5">
<Label></Label>
<Input value={username} onChange={(e) => setUsername(e.target.value)} />
</div>
<div className="space-y-1.5">
<Label></Label>
<Input type="password" value={password} onChange={(e) => setPassword(e.target.value)} />
</div>
{error && <p className="text-sm text-destructive">{error}</p>}
<Button type="submit" className="w-full" disabled={loading}>
{loading ? '登录中...' : '登录'}
</Button>
</form>
</CardContent>
</Card>
</div>
)
}