超管登录

This commit is contained in:
柳清爽
2025-04-09 14:07:54 +08:00
parent 899bac425b
commit c8893e4473
9 changed files with 228 additions and 6 deletions

View File

@@ -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 (
<div className="space-y-6">
<h1 className="text-3xl font-bold">使</h1>
<p className="text-muted-foreground"></p>
<p className="text-muted-foreground">
{greeting}{userName}
</p>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
<Card>

View File

@@ -8,22 +8,55 @@ import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
import { Label } from "@/components/ui/label"
import { md5 } from "@/lib/utils"
export default function LoginPage() {
const [username, setUsername] = useState("")
const [password, setPassword] = useState("")
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState("")
const router = useRouter()
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault()
setIsLoading(true)
setError("")
// Simulate login API call
setTimeout(() => {
try {
// 对密码进行MD5加密
const encryptedPassword = md5(password)
// 调用登录接口
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/auth/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
account: username,
password: encryptedPassword
}),
credentials: "include"
})
const result = await response.json()
if (result.code === 200) {
// 保存用户信息到本地存储
localStorage.setItem("admin_info", JSON.stringify(result.data))
localStorage.setItem("admin_token", result.data.token)
// 跳转到仪表盘
router.push("/dashboard")
} else {
setError(result.msg || "登录失败")
}
} catch (err) {
console.error("登录失败:", err)
setError("网络错误,请稍后再试")
} finally {
setIsLoading(false)
router.push("/dashboard")
}, 1500)
}
}
return (
@@ -32,6 +65,7 @@ export default function LoginPage() {
<CardHeader className="space-y-1">
<CardTitle className="text-2xl text-center"></CardTitle>
<CardDescription className="text-center"></CardDescription>
{error && <p className="text-sm text-red-500 text-center">{error}</p>}
</CardHeader>
<form onSubmit={handleLogin}>
<CardContent className="space-y-4">