wood chen 33d6a51416 refactor(web): Migrate to modern web frontend and simplify admin routes
- Remove legacy static files, templates, and JavaScript
- Update main.go to serve SPA-style web application
- Modify admin route handling to support client-side routing
- Simplify configuration and metrics API endpoints
- Remove server-side template rendering in favor of static file serving
- Update Dockerfile and GitHub Actions to build web frontend
2025-02-15 11:44:09 +08:00

59 lines
1.5 KiB
TypeScript

"use client"
import Link from "next/link"
import { usePathname, useRouter } from "next/navigation"
import { Button } from "@/components/ui/button"
import { useToast } from "@/components/ui/use-toast"
export function Nav() {
const pathname = usePathname()
const router = useRouter()
const { toast } = useToast()
const handleLogout = async () => {
try {
const response = await fetch("/api/logout", {
method: "POST",
})
if (response.ok) {
localStorage.removeItem("token")
toast({
title: "已退出登录",
})
router.push("/")
}
} catch {
toast({
title: "退出失败",
description: "请稍后重试",
variant: "destructive",
})
}
}
return (
<nav className="border-b bg-white">
<div className="container mx-auto flex h-14 items-center px-4">
<div className="mr-4 font-bold"></div>
<div className="flex flex-1 items-center space-x-4 md:space-x-6">
<Link
href="/dashboard"
className={pathname === "/dashboard" ? "text-primary" : "text-muted-foreground"}
>
</Link>
<Link
href="/dashboard/config"
className={pathname === "/dashboard/config" ? "text-primary" : "text-muted-foreground"}
>
</Link>
</div>
<Button variant="ghost" onClick={handleLogout}>
退
</Button>
</div>
</nav>
)
}