diff --git a/frontend/src/apis/apis.ts b/frontend/src/apis/apis.ts index 4bd5c55..946094e 100644 --- a/frontend/src/apis/apis.ts +++ b/frontend/src/apis/apis.ts @@ -1,4 +1,4 @@ -import type { tokenData, ApiUser, ApiServerInfo, YggProfile, ApiConfig } from '@/apis/model' +import type { tokenData, ApiUser, ApiServerInfo, YggProfile, ApiConfig, List, UserInfo } from '@/apis/model' import { apiGet } from '@/apis/utils' export async function login(username: string, password: string) { @@ -102,4 +102,14 @@ export async function changeName(name: string, token: string) { } }) return await apiGet(r) +} + +export async function ListUser(page: number, token: string) { + const r = await fetch(import.meta.env.VITE_APIADDR + "/api/v1/admin/users?page=" + String(page), { + method: "GET", + headers: { + "Authorization": "Bearer " + token + } + }) + return await apiGet>(r) } \ No newline at end of file diff --git a/frontend/src/apis/model.ts b/frontend/src/apis/model.ts index 998fc5d..18b8dca 100644 --- a/frontend/src/apis/model.ts +++ b/frontend/src/apis/model.ts @@ -12,6 +12,11 @@ export interface Api { data: T } +export interface List { + total: number + list: T[] +} + interface captcha { type: string @@ -42,4 +47,13 @@ export interface YggProfile { export interface ApiConfig { captcha: captcha AllowChangeName: boolean +} + +export interface UserInfo { + uid: number + uuid: number + is_admin: boolean + email: string + reg_ip: string + name: string } \ No newline at end of file diff --git a/frontend/src/views/admin/UserAdmin.tsx b/frontend/src/views/admin/UserAdmin.tsx index 4265e82..8c3a530 100644 --- a/frontend/src/views/admin/UserAdmin.tsx +++ b/frontend/src/views/admin/UserAdmin.tsx @@ -6,58 +6,73 @@ import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; import Paper from '@mui/material/Paper'; import useTitle from '@/hooks/useTitle'; +import { useRequest } from 'ahooks'; +import { ListUser } from '@/apis/apis'; +import { useEffect, useState } from 'react'; +import { useAtomValue } from 'jotai'; +import { token } from '@/store/store'; +import TablePagination from '@mui/material/TablePagination'; +import Alert from '@mui/material/Alert'; +import Snackbar from '@mui/material/Snackbar'; +import Button from '@mui/material/Button'; -function createData( - name: string, - calories: number, - fat: number, - carbs: number, - protein: number, -) { - return { name, calories, fat, carbs, protein }; -} - -const rows = [ - createData('Frozen yoghurt', 159, 6.0, 24, 4.0), - createData('Ice cream sandwich', 237, 9.0, 37, 4.3), - createData('Eclair', 262, 16.0, 24, 6.0), - createData('Cupcake', 305, 3.7, 67, 4.3), - createData('Gingerbread', 356, 16.0, 49, 3.9), -]; export default function UserAdmin() { useTitle("用户管理") + const [page, setPage] = useState(1) + const nowtoken = useAtomValue(token) + const [err, setErr] = useState("") + + const { data, run } = useRequest(ListUser, { + cacheKey: "/api/v1/admin/users?page=" + String(page), + onError: e => { + setErr(String(e)) + } + }) + + useEffect(() => { + run(page, nowtoken) + }, [page, nowtoken, run]) - return ( - - - - - Dessert (100g serving) - Calories - Fat (g) - Carbs (g) - Protein (g) - - - - {rows.map((row) => ( - - - {row.name} - - {row.calories} - {row.fat} - {row.carbs} - {row.protein} + return (<> + + +
+ + + 邮箱 + 用户名 + 注册 ip + uuid + - ))} - -
-
- ); + + + {data?.list.map((row) => ( + + {row.email} + {row.name} + {row.reg_ip} + {row.uuid} + + + ))} + + + + setPage(page + 1)} + /> + + + setErr("")} severity="error">{err} + + + ); } \ No newline at end of file