"use client"; import { useState, type FormEvent } from "react"; import { useRouter } from "next/navigation"; import { API_BASE_URL } from "@/lib/config"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; export default function AgentLoginPage() { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const router = useRouter(); // 客服登录 async function handleLogin(e: FormEvent) { e.preventDefault(); // 阻止默认行为 if (!username || !password) { setError("用户名和密码不能为空"); return; } setLoading(true); setError(""); try { const res = await fetch(`${API_BASE_URL}/login`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }); const data = await res.json(); if (res.ok) { // 登录成功,保存用户信息到 localStorage localStorage.setItem("agent_user_id", String(data.user_id)); localStorage.setItem("agent_username", data.username); localStorage.setItem("agent_role", data.role); // 跳转到客服工作台(三栏布局) router.push("/agent/dashboard"); } else { // 登录失败,显示错误信息 setError(data.error || data.message || "登录失败"); } } catch (error) { console.error("登录失败:", error); setError("登录失败,请检查网络连接"); } finally { setLoading(false); } } return (

客服登录

管理员和客服请在此登录

setUsername(e.target.value)} className="w-full mb-4" disabled={loading} /> setPassword(e.target.value)} className="w-full mb-4" disabled={loading} /> {error && (
{error}
)}

默认管理员账号:admin / admin123

); }