超管登录
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user