diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx new file mode 100644 index 0000000..c6366c0 --- /dev/null +++ b/src/app/(auth)/login/page.tsx @@ -0,0 +1,131 @@ +'use client' +import { useState } from 'react' +import { useRouter } from 'next/navigation' +import { zodResolver } from '@hookform/resolvers/zod' +import { useForm } from 'react-hook-form' +import * as z from 'zod' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form' +import { Lock, User } from 'lucide-react' +import { useAuthStore } from '@/store/auth' +import { toast, Toaster } from 'sonner' +import { login } from '@/actions/auth' + +const formSchema = z.object({ + account: z.string().min(3, '账号至少需要3个字符'), + password: z.string().min(6, '密码至少需要6个字符'), +}) + +export default function LoginPage() { + const router = useRouter() + const [loading, setLoading] = useState(false) + const setAuth = useAuthStore(state => state.setAuth) + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + account: '', + password: '', + }, + }) + + async function onSubmit(values: z.infer) { + setLoading(true) + try { + const data = await login(values) + + if (data.success) { + toast.success('登录成功', { + description: '正在跳转到仪表盘...', + }) + setAuth(true) + await new Promise(resolve => setTimeout(resolve, 1000)) + router.push('/dashboard') + router.refresh() + } + else { + toast.error('账号或密码错误,请重新输入') + } + } + catch (error) { + toast.error('登录失败', { + description: error instanceof Error ? error.message : '账号或密码错误,请稍后重试', + }) + } + finally { + setLoading(false) + } + } + return ( + <> +
+ + + 登录 + + +
+ + ( + + 账号 + +
+ + +
+
+ +
+ )} + /> + ( + + 密码 + +
+ + +
+
+ +
+ )} + /> + + + +
+
+
+ + + ) +} diff --git a/src/app/dashboard/components/allocationStatus.tsx b/src/app/dashboard/components/allocationStatus.tsx index f90eaf3..9a23252 100644 --- a/src/app/dashboard/components/allocationStatus.tsx +++ b/src/app/dashboard/components/allocationStatus.tsx @@ -83,24 +83,8 @@ export default function AllocationStatus({ detailed = false }: { detailed?: bool - - {timeFilter === 'custom' && ( -
- setCustomHours(e.target.value)} - placeholder="输入小时数" - className="border rounded p-2 w-24" - /> - 小时 (1-720) -
- )} -