mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-02 16:16:39 +08:00
opt user table
This commit is contained in:
parent
8a39cd2a87
commit
2843e3fab1
@ -12,11 +12,15 @@ async function handle(
|
|||||||
// const url = req.url;
|
// const url = req.url;
|
||||||
const { pathname, searchParams } = new URL(req.url);
|
const { pathname, searchParams } = new URL(req.url);
|
||||||
const searchText = searchParams.get("search");
|
const searchText = searchParams.get("search");
|
||||||
|
|
||||||
// console.log(req, '2', params.path)
|
// console.log(req, '2', params.path)
|
||||||
|
|
||||||
if (method === "GET") {
|
if (method === "GET") {
|
||||||
// 是否有查询
|
// 是否有查询
|
||||||
try {
|
try {
|
||||||
|
const skip = Number(searchParams.get("skip"));
|
||||||
|
const take = Number(searchParams.get("take"));
|
||||||
|
console.log("-----", skip, take);
|
||||||
const result = searchText
|
const result = searchText
|
||||||
? await prisma.user.findMany({
|
? await prisma.user.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
@ -85,6 +85,17 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
const [editUserModal, editUserModalContextHolder] = Modal.useModal();
|
const [editUserModal, editUserModalContextHolder] = Modal.useModal();
|
||||||
const [editUserForm] = Form.useForm();
|
const [editUserForm] = Form.useForm();
|
||||||
|
|
||||||
|
const [tableScroll, setTableScroll] = useState({ y: 240 });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleResize = () => {
|
||||||
|
setTableScroll({ y: window.innerHeight - 240 });
|
||||||
|
};
|
||||||
|
window.addEventListener("resize", handleResize);
|
||||||
|
handleResize();
|
||||||
|
return () => window.removeEventListener("resize", handleResize);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleUserEdit = (method: "POST" | "PUT", record: User | undefined) => {
|
const handleUserEdit = (method: "POST" | "PUT", record: User | undefined) => {
|
||||||
editUserModal.confirm({
|
editUserModal.confirm({
|
||||||
title: "编辑用户",
|
title: "编辑用户",
|
||||||
@ -217,15 +228,17 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const columns: TableColumnsType<User> = [
|
const columns: TableColumnsType<User> = [
|
||||||
{ title: "Name", dataIndex: "name" },
|
{ title: "姓名", dataIndex: "name", width: 80 },
|
||||||
{
|
{
|
||||||
title: "UserName",
|
title: "用户名",
|
||||||
dataIndex: "username",
|
dataIndex: "username",
|
||||||
|
width: 80,
|
||||||
},
|
},
|
||||||
{ title: "Email", dataIndex: "email" },
|
{ title: "邮箱", dataIndex: "email", width: 180 },
|
||||||
{
|
{
|
||||||
title: "createdAt",
|
title: "createdAt",
|
||||||
dataIndex: "createdAt",
|
dataIndex: "createdAt",
|
||||||
|
width: 120,
|
||||||
render: (value) => getCurrentTime(new Date(value)),
|
render: (value) => getCurrentTime(new Date(value)),
|
||||||
sorter: (a, b) => {
|
sorter: (a, b) => {
|
||||||
if (a.createdAt < b.createdAt) return 1;
|
if (a.createdAt < b.createdAt) return 1;
|
||||||
@ -235,12 +248,13 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
{
|
{
|
||||||
title: "updatedAt",
|
title: "updatedAt",
|
||||||
dataIndex: "updatedAt",
|
dataIndex: "updatedAt",
|
||||||
|
width: 120,
|
||||||
render: (value) => getCurrentTime(new Date(value)),
|
render: (value) => getCurrentTime(new Date(value)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "管理员",
|
title: "管理员",
|
||||||
dataIndex: "isAdmin",
|
dataIndex: "isAdmin",
|
||||||
width: 80,
|
width: 50,
|
||||||
render: (value) => {
|
render: (value) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -252,7 +266,7 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
{
|
{
|
||||||
title: "允许登录",
|
title: "允许登录",
|
||||||
dataIndex: "allowToLogin",
|
dataIndex: "allowToLogin",
|
||||||
width: 80,
|
width: 50,
|
||||||
render: (value) => {
|
render: (value) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -265,6 +279,7 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
title: "Action",
|
title: "Action",
|
||||||
dataIndex: "",
|
dataIndex: "",
|
||||||
key: "id",
|
key: "id",
|
||||||
|
width: 120,
|
||||||
render: (_, record) => (
|
render: (_, record) => (
|
||||||
<Space size="small">
|
<Space size="small">
|
||||||
<Button type="link" onClick={() => handleUserEdit("PUT", record)}>
|
<Button type="link" onClick={() => handleUserEdit("PUT", record)}>
|
||||||
@ -286,11 +301,12 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
<Table
|
<Table
|
||||||
dataSource={users}
|
dataSource={users}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
|
size="middle"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
loading={loading as boolean}
|
loading={loading as boolean}
|
||||||
scroll={{
|
scroll={{
|
||||||
scrollToFirstRowOnChange: true,
|
scrollToFirstRowOnChange: true,
|
||||||
y: 1080,
|
...tableScroll,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user