mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-18 06:53:41 +08:00
暂存-设置项管理
This commit is contained in:
25
app/api/admin/setting/[[...path]]/route.ts
Normal file
25
app/api/admin/setting/[[...path]]/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
async function handle(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { path: string[] } },
|
||||
) {
|
||||
// 判断网址和请求方法
|
||||
const method = req.method;
|
||||
// const url = req.url;
|
||||
const { pathname, searchParams } = new URL(req.url);
|
||||
// console.log('----', pathname, searchParams, params.path)
|
||||
if (method === "GET" && !params.path) {
|
||||
const all_setting = await prisma.setting.findMany();
|
||||
console.log("all_setting,", all_setting);
|
||||
return NextResponse.json({ result: all_setting });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "当前方法不支持" }, { status: 405 });
|
||||
}
|
||||
|
||||
export const GET = handle;
|
||||
export const POST = handle;
|
||||
export const PUT = handle;
|
||||
export const DELETE = handle;
|
||||
9
app/app/(admin)/admin/setting/page.tsx
Normal file
9
app/app/(admin)/admin/setting/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Flex } from "antd";
|
||||
import SettingForm from "../../components/admin-setting-table";
|
||||
export default async function SettingPage() {
|
||||
return (
|
||||
<Flex>
|
||||
<SettingForm />
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
50
app/app/(admin)/components/admin-setting-table.tsx
Normal file
50
app/app/(admin)/components/admin-setting-table.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
import type { FormProps } from "antd";
|
||||
import { Button, Checkbox, Form, Input, Table } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Setting } from "@prisma/client";
|
||||
|
||||
function SettingForm() {
|
||||
const [setting, setSetting] = useState<Setting[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/admin/setting", {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((result) => {
|
||||
setSetting(result["result"]);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: "key",
|
||||
dataIndex: "key",
|
||||
key: "key",
|
||||
},
|
||||
{
|
||||
title: "value",
|
||||
dataIndex: "value",
|
||||
},
|
||||
{
|
||||
title: "type",
|
||||
dataIndex: "type",
|
||||
},
|
||||
{
|
||||
title: "action",
|
||||
dataIndex: "",
|
||||
key: "key",
|
||||
render: (_, record) => (
|
||||
<>
|
||||
<Button>编辑</Button>
|
||||
</>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return <Table dataSource={setting} columns={columns} />;
|
||||
}
|
||||
|
||||
export default SettingForm;
|
||||
@@ -38,6 +38,7 @@ const items: MenuItem[] = [
|
||||
|
||||
getItem("管理", "manage", <AppstoreOutlined />, [
|
||||
getItem("用户管理", "/admin/users"),
|
||||
getItem("系统设置", "/admin/setting"),
|
||||
]),
|
||||
|
||||
// getItem("Navigation Three", "sub4", <SettingOutlined />, [
|
||||
|
||||
Reference in New Issue
Block a user