diff --git a/frontend/app/(main)/admin/page.tsx b/frontend/app/(main)/admin/page.tsx deleted file mode 100644 index 5d23713..0000000 --- a/frontend/app/(main)/admin/page.tsx +++ /dev/null @@ -1,186 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table"; -import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; - -interface User { - id: number; - username: string; - email: string; - role: string; - createdAt: string; -} - -export default function AdminPage() { - const [users, setUsers] = useState([]); - const [loading, setLoading] = useState(true); - const [open, setOpen] = useState(false); - const [form, setForm] = useState({ - username: "", - email: "", - password: "", - role: "user", - }); - - async function fetchUsers() { - const res = await fetch("/api/proxy/admin/users"); - if (res.ok) { - const data = await res.json(); - setUsers(data.users || []); - } - setLoading(false); - } - - useEffect(() => { - fetchUsers(); - }, []); - - async function handleCreate(e: React.FormEvent) { - e.preventDefault(); - const res = await fetch("/api/proxy/admin/users", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(form), - }); - - if (res.ok) { - setOpen(false); - setForm({ username: "", email: "", password: "", role: "user" }); - fetchUsers(); - } - } - - async function handleDelete(id: number) { - if (!confirm("确定删除该用户?")) return; - const res = await fetch(`/api/proxy/admin/users/${id}`, { - method: "DELETE", - }); - if (res.ok) { - fetchUsers(); - } - } - - return ( -
-
-

用户管理

- - 创建用户} /> - - - 新建用户 - -
-
- - - setForm({ ...form, username: e.target.value }) - } - required - /> -
-
- - - setForm({ ...form, email: e.target.value }) - } - required - /> -
-
- - - setForm({ ...form, password: e.target.value }) - } - required - /> -
-
- - -
- -
-
-
-
- - - - 用户列表 - - - {loading ? ( -

加载中...

- ) : ( - - - - ID - 用户名 - 邮箱 - 角色 - 操作 - - - - {users.map((user) => ( - - {user.id} - {user.username} - {user.email} - {user.role} - - - - - ))} - -
- )} -
-
-
- ); -} diff --git a/frontend/app/(main)/layout.tsx b/frontend/app/(main)/layout.tsx index 1e3ac30..6bee1a2 100644 --- a/frontend/app/(main)/layout.tsx +++ b/frontend/app/(main)/layout.tsx @@ -22,11 +22,6 @@ export default async function MainLayout({ 仪表盘 - {user?.role === "admin" && ( - - 管理后台 - - )}
{ "use server";