"use client"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import React, { useState } from "react"; import Image from "next/image"; import { FaPlus, FaBars } from "react-icons/fa6"; import { MdOutlineHome, MdLogout } from "react-icons/md"; import { PiSquaresFourBold } from "react-icons/pi"; import { BsLightningChargeFill } from "react-icons/bs"; import { useTranslations, useLocale } from "next-intl"; import classNames from "classnames"; import useUserStore from "@/store/userStore"; import useFetch from "@/hooks/useFetch"; import { useToast } from "@/contexts/ToastContext"; import useLoadingStore from "@/store/loadingStore"; type MenuItem = { name: string; href: string; icon?: React.ComponentType; }; export default function SideBar() { const pathname = usePathname(); const router = useRouter(); const user = useUserStore((state) => state.user); const t = useTranslations("sideBar"); const locale = useLocale(); const { addToast, addToastSuccess, addToastError } = useToast(); const [sidebarOpen, setSidebarOpen] = useState(false); // 控制侧边栏的开关状态 const hideLoading = useLoadingStore((state) => state.hideLoading); const toggleSidebar = () => { setSidebarOpen(!sidebarOpen); }; const menu: { title: string; items: MenuItem[] }[] = [ { title: t("creation"), items: [ { name: t("videos"), href: "/projects", icon: PiSquaresFourBold, }, ], }, ]; const { fetchData: logoutFetch, loading: logoutLoading, data: logoutResult, } = useFetch({ url: "/api/logout/", // 假设你的退出接口路径为 /api/logout/ method: "POST", }); const logout = () => { logoutFetch() // 不需要传递参数 .then((res) => { addToastSuccess(t("logoutSuccess")); router.push("/login"); // 退出成功后跳转到登录页面 }) .finally(() => { hideLoading(); }); }; return (