This commit is contained in:
sijinhui 2024-03-24 18:50:36 +08:00
parent d534c4422d
commit 79aa8c1065
5 changed files with 61 additions and 35 deletions

View File

@ -1,17 +1,17 @@
import UsageByModel from "./usage-by-model-chart"; import UsageByModel from "./usage-by-model-chart";
import UserByMap from "./user-by-map"; import UserByMap from "./user-by-map";
import { getSession } from "@/lib/auth"; // import { getSession } from "@/lib/auth";
import { isName, ADMIN_LIST } from "@/lib/auth_list"; // import { isName, ADMIN_LIST } from "@/lib/auth_list";
import { redirect } from "next/navigation"; // import { redirect } from "next/navigation";
import { Flex } from "antd"; import { Flex } from "antd";
export default async function AdminPage() { export default async function AdminPage() {
const session = await getSession(); // const session = await getSession();
const name = session?.user?.email || session?.user?.name; // const name = session?.user?.email || session?.user?.name;
if (!(name && ADMIN_LIST.includes(name))) { // if (!(name && ADMIN_LIST.includes(name))) {
// Replace '/dashboard' with the desired redirect path // // Replace '/dashboard' with the desired redirect path
redirect("/"); // redirect("/");
} // }
return ( return (
<> <>

View File

@ -1,6 +1,9 @@
"use client"; "use client";
import React, { ReactNode, useState } from "react"; import { useSession } from "next-auth/react";
import { redirect } from "next/navigation";
import { ADMIN_LIST } from "@/lib/auth_list";
import React, { ReactNode, useEffect, useState } from "react";
import { import {
MenuFoldOutlined, MenuFoldOutlined,
MenuUnfoldOutlined, MenuUnfoldOutlined,
@ -15,12 +18,23 @@ const { Header, Sider, Content } = Layout;
function MainLayout({ children }: { children: ReactNode }) { function MainLayout({ children }: { children: ReactNode }) {
// const [theme, setTheme] = useState<ThemeConfig>('dark'); // const [theme, setTheme] = useState<ThemeConfig>('dark');
const { data, status } = useSession();
const name = data?.user?.email || data?.user?.name;
// console.log('name', name, data, status)
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);
const { const {
token: { colorBgContainer, borderRadiusLG, colorBgLayout }, token: { colorBgContainer, borderRadiusLG, colorBgLayout },
} = theme.useToken(); } = theme.useToken();
// 客户端才执行
useEffect(() => {
// 用户已登录,且没设置密码
// if (status === "loading") return;
if (status === "authenticated" && !(name && ADMIN_LIST.includes(name))) {
redirect("/");
}
// 状态变化时,重新判断
}, [name, status]);
return ( return (
<ConfigProvider <ConfigProvider
theme={{ theme={{

View File

@ -0,0 +1,29 @@
"use client";
import { Flex } from "antd";
import prisma from "@/lib/prisma";
import { Space, Table, Tag } from "antd";
const { Column, ColumnGroup } = Table;
async function getData() {
const users = await prisma.user.findMany();
return users;
}
export default async function UsersPage() {
const data = await getData();
console.log("data", data);
return (
<>
<Flex gap="middle" vertical>
<Table dataSource={data}>
{/*<Column title="ID" dataIndex="id" key="id" hidden={true}/>*/}
<Column title="Name" key="name" dataIndex="name" />
<Column title="UserName" key="username" dataIndex="username" />
<Column title="email" key="email" dataIndex="email" />
</Table>
</Flex>
</>
);
}

View File

@ -68,33 +68,15 @@ const SideBar: React.FC = () => {
setCurrent(e.key); setCurrent(e.key);
router.push(e.key); router.push(e.key);
}; };
useEffect(() => {
// 如果按钮和路径不相等,那其实应该跳转到按钮的网址
if (current != pathname) {
router.push(current);
}
}, [current, pathname, router]);
// useEffect(() => { // useEffect(() => {
// const handleStart = () => setLoading(true) // // 如果按钮和路径不相等,那其实应该跳转到按钮的网址
// const handleComplete = () => setLoading(false); // if (current != pathname) {
// router.events.on('routeChangeStart', handleStart); // router.push(current);
// router.events.on('routeChangeComplete', handleStop);
// router.events.on('routeChangeError', handleStop);
//
// return () => {
// router.
// } // }
// // }, [current, pathname, router]);
// }, [router]);
return ( return (
<> <>
{/*<Switch*/}
{/* // checked={theme === 'dark'}*/}
{/* // onChange={changeTheme}*/}
{/* checkedChildren="Dark"*/}
{/* unCheckedChildren="Light"*/}
{/*/>*/}
<br /> <br />
<br /> <br />
<Menu <Menu

View File

@ -27,6 +27,7 @@
"@vercel/speed-insights": "^1.0.9", "@vercel/speed-insights": "^1.0.9",
"antd": "^5.15.1", "antd": "^5.15.1",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"cron": "^3.1.6",
"echarts": "^5.4.3", "echarts": "^5.4.3",
"emoji-picker-react": "^4.7.10", "emoji-picker-react": "^4.7.10",
"fuse.js": "^7.0.0", "fuse.js": "^7.0.0",
@ -74,7 +75,7 @@
"postcss": "^8.4.33", "postcss": "^8.4.33",
"prettier": "^3.2.4", "prettier": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.11", "prettier-plugin-tailwindcss": "^0.5.11",
"prisma": "^5.9.0", "prisma": "^5.11.0",
"tailwindcss": "^3.4.1", "tailwindcss": "^3.4.1",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"typescript": "^5.3.3", "typescript": "^5.3.3",