列表
This commit is contained in:
parent
aca0dc21b0
commit
a64ab9e838
@ -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'
|
import { apiGet } from '@/apis/utils'
|
||||||
|
|
||||||
export async function login(username: string, password: string) {
|
export async function login(username: string, password: string) {
|
||||||
@ -103,3 +103,13 @@ export async function changeName(name: string, token: string) {
|
|||||||
})
|
})
|
||||||
return await apiGet<unknown>(r)
|
return await apiGet<unknown>(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<List<UserInfo>>(r)
|
||||||
|
}
|
@ -12,6 +12,11 @@ export interface Api<T> {
|
|||||||
data: T
|
data: T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface List<T> {
|
||||||
|
total: number
|
||||||
|
list: T[]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
interface captcha {
|
interface captcha {
|
||||||
type: string
|
type: string
|
||||||
@ -43,3 +48,12 @@ export interface ApiConfig {
|
|||||||
captcha: captcha
|
captcha: captcha
|
||||||
AllowChangeName: boolean
|
AllowChangeName: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UserInfo {
|
||||||
|
uid: number
|
||||||
|
uuid: number
|
||||||
|
is_admin: boolean
|
||||||
|
email: string
|
||||||
|
reg_ip: string
|
||||||
|
name: string
|
||||||
|
}
|
@ -6,58 +6,73 @@ import TableHead from '@mui/material/TableHead';
|
|||||||
import TableRow from '@mui/material/TableRow';
|
import TableRow from '@mui/material/TableRow';
|
||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import useTitle from '@/hooks/useTitle';
|
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() {
|
export default function UserAdmin() {
|
||||||
useTitle("用户管理")
|
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 (
|
return (<>
|
||||||
<TableContainer component={Paper}>
|
<Paper>
|
||||||
<Table sx={{ minWidth: 650 }} aria-label="simple table">
|
<TableContainer >
|
||||||
<TableHead>
|
<Table>
|
||||||
<TableRow>
|
<TableHead>
|
||||||
<TableCell>Dessert (100g serving)</TableCell>
|
<TableRow>
|
||||||
<TableCell align="right">Calories</TableCell>
|
<TableCell>邮箱</TableCell>
|
||||||
<TableCell align="right">Fat (g)</TableCell>
|
<TableCell>用户名</TableCell>
|
||||||
<TableCell align="right">Carbs (g)</TableCell>
|
<TableCell>注册 ip</TableCell>
|
||||||
<TableCell align="right">Protein (g)</TableCell>
|
<TableCell>uuid</TableCell>
|
||||||
</TableRow>
|
<TableCell></TableCell>
|
||||||
</TableHead>
|
|
||||||
<TableBody>
|
|
||||||
{rows.map((row) => (
|
|
||||||
<TableRow
|
|
||||||
key={row.name}
|
|
||||||
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
|
|
||||||
>
|
|
||||||
<TableCell component="th" scope="row">
|
|
||||||
{row.name}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell align="right">{row.calories}</TableCell>
|
|
||||||
<TableCell align="right">{row.fat}</TableCell>
|
|
||||||
<TableCell align="right">{row.carbs}</TableCell>
|
|
||||||
<TableCell align="right">{row.protein}</TableCell>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
</TableHead>
|
||||||
</TableBody>
|
<TableBody>
|
||||||
</Table>
|
{data?.list.map((row) => (
|
||||||
</TableContainer>
|
<TableRow key={row.uid}>
|
||||||
);
|
<TableCell sx={{ maxWidth: 'min-content' }}>{row.email}</TableCell>
|
||||||
|
<TableCell>{row.name}</TableCell>
|
||||||
|
<TableCell>{row.reg_ip}</TableCell>
|
||||||
|
<TableCell>{row.uuid}</TableCell>
|
||||||
|
<TableCell><Button>编辑</Button></TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</TableContainer>
|
||||||
|
<TablePagination
|
||||||
|
rowsPerPageOptions={[20]}
|
||||||
|
component="div"
|
||||||
|
count={data?.total ?? 0}
|
||||||
|
rowsPerPage={20}
|
||||||
|
page={page - 1}
|
||||||
|
onPageChange={(_, page) => setPage(page + 1)}
|
||||||
|
/>
|
||||||
|
</Paper >
|
||||||
|
<Snackbar anchorOrigin={{ vertical: 'top', horizontal: 'center' }} open={err != ""} >
|
||||||
|
<Alert onClose={() => setErr("")} severity="error">{err}</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
|
||||||
|
</>);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user