diff --git a/Server/application/superadmin/config/route.php b/Server/application/superadmin/config/route.php new file mode 100644 index 00000000..5413a593 --- /dev/null +++ b/Server/application/superadmin/config/route.php @@ -0,0 +1,5 @@ +request->isPost()) { + return json(['code' => 405, 'msg' => '请求方法不允许']); + } + + $account = $this->request->post('account'); + $password = $this->request->post('password'); + + if (empty($account) || empty($password)) { + return json(['code' => 400, 'msg' => '账号和密码不能为空']); + } + + $admin = Administrator::login($account, $password); + + if (!$admin) { + return json(['code' => 401, 'msg' => '账号或密码错误']); + } + + // 更新登录信息 + $admin->lastLoginTime = time(); + $admin->lastLoginIp = $this->request->ip(); + $admin->save(); + + // 设置登录Cookie,有效期24小时 + cookie('admin_id', $admin->id, 86400); + cookie('admin_token', $this->createToken($admin), 86400); + + return json([ + 'code' => 200, + 'msg' => '登录成功', + 'data' => [ + 'id' => $admin->id, + 'name' => $admin->name, + 'account' => $admin->account, + 'token' => cookie('admin_token') + ] + ]); + } + + /** + * 创建登录令牌 + * @param Administrator $admin + * @return string + */ + private function createToken($admin) + { + $data = $admin->id . '|' . $admin->account . '|' . time(); + return md5($data . 'cunkebao_admin_secret'); + } +} \ No newline at end of file diff --git a/Server/application/superadmin/data/administrator.sql b/Server/application/superadmin/data/administrator.sql new file mode 100644 index 00000000..02073d56 --- /dev/null +++ b/Server/application/superadmin/data/administrator.sql @@ -0,0 +1,2 @@ +INSERT INTO `tk_administrators` (`name`, `account`, `password`, `status`, `createTime`, `updateTime`) +VALUES ('超级管理员', 'admin', MD5('123456'), 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()); \ No newline at end of file diff --git a/Server/application/superadmin/model/Administrator.php b/Server/application/superadmin/model/Administrator.php new file mode 100644 index 00000000..be2ce650 --- /dev/null +++ b/Server/application/superadmin/model/Administrator.php @@ -0,0 +1,48 @@ +find(); + } +} \ No newline at end of file diff --git a/Server/route/route.php b/Server/route/route.php index 7dfa30d5..cd50328c 100644 --- a/Server/route/route.php +++ b/Server/route/route.php @@ -24,12 +24,14 @@ include __DIR__ . '/../application/api/config/route.php'; // 加载Common模块路由配置 include __DIR__ . '/../application/common/config/route.php'; -// 加载Devices模块路由配置 +// 加载Cunkebao模块路由配置 include __DIR__ . '/../application/cunkebao/config/route.php'; // 加载Store模块路由配置 include __DIR__ . '/../application/store/config/route.php'; +// 加载Superadmin模块路由配置 +include __DIR__ . '/../application/superadmin/config/route.php'; // 加载CozeAI模块路由配置 include __DIR__ . '/../application/cozeai/config/route.php'; diff --git a/SuperAdmin/app/dashboard/page.tsx b/SuperAdmin/app/dashboard/page.tsx index dfe14b45..2daa9ee4 100644 --- a/SuperAdmin/app/dashboard/page.tsx +++ b/SuperAdmin/app/dashboard/page.tsx @@ -1,11 +1,52 @@ +"use client" + +import { useEffect, useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Users, FolderKanban, UserCog } from "lucide-react" +import useAuthCheck from "@/hooks/useAuthCheck" export default function DashboardPage() { + const [greeting, setGreeting] = useState("") + const [userName, setUserName] = useState("") + + // 验证用户是否已登录 + useAuthCheck() + + useEffect(() => { + // 获取用户信息 + const adminInfo = localStorage.getItem("admin_info") + if (adminInfo) { + try { + const { name } = JSON.parse(adminInfo) + setUserName(name || "管理员") + } catch (err) { + console.error("解析用户信息失败:", err) + } + } + + // 获取当前时间 + const hour = new Date().getHours() + let timeGreeting = "" + + if (hour >= 5 && hour < 12) { + timeGreeting = "上午好" + } else if (hour >= 12 && hour < 14) { + timeGreeting = "中午好" + } else if (hour >= 14 && hour < 18) { + timeGreeting = "下午好" + } else { + timeGreeting = "晚上好" + } + + setGreeting(timeGreeting) + }, []) + return (
通过此平台,您可以管理项目、客户和管理员权限。
++ {greeting},{userName}!通过此平台,您可以管理项目、客户和管理员权限。 +
{error}
}