Skip to content

Let's use AI to Earn!

header show in moble

bulaienaofutuojsonzhang8749e9406aa2
diff --git a/src/app/layout/HomeHeader.tsx b/src/app/layout/HomeHeader.tsx
index 0c64d58a..1299a23a 100644
--- a/src/app/layout/HomeHeader.tsx
+++ b/src/app/layout/HomeHeader.tsx
@@ -1,4 +1,4 @@
-import { ForwardedRef, forwardRef, memo } from "react";
+import { ForwardedRef, forwardRef, memo, useState } from "react";
import { useTransClient } from "@/app/i18n/client";
import { usePathname, useRouter } from "next/navigation";
import { useUserStore } from "@/store/user";
@@ -7,7 +7,7 @@ import Image from "next/image";
import logo from "@/assets/images/logo.png";
import Link from "next/link";
import { Button } from "antd";
-import { GlobalOutlined } from "@ant-design/icons";
+import { GlobalOutlined, MenuOutlined, CloseOutlined } from "@ant-design/icons";
import { removeLocalePrefix } from "@/app/layout/layout.utils";
import { homeHeaderRouterData } from "@/app/layout/routerData";
@@ -22,7 +22,11 @@ const HomeHeader = memo(
const router = useRouter();
const userStore = useUserStore();
const currentPath = removeLocalePrefix(pathname).replace(/\/+$/, "") || "/";
+ const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
+ /**
+ * 切换语言
+ */
const toggleLanguage = () => {
const newLng = userStore.lang === "zh-CN" ? "en" : "zh-CN";
userStore.setLang(newLng);
@@ -31,6 +35,23 @@ const HomeHeader = memo(
);
};
+ /**
+ * 切换移动端菜单显示状态
+ */
+ const toggleMobileMenu = () => {
+ setIsMobileMenuOpen(!isMobileMenuOpen);
+ };
+
+ /**
+ * 关闭移动端菜单
+ */
+ const closeMobileMenu = () => {
+ setIsMobileMenuOpen(false);
+ };
+
+ /**
+ * 判断链接是否为当前激活状态
+ */
const isActive = (href: string) => {
if (!href.startsWith("/")) return false;
const normalizedHref = href.replace(/\/+$/, "") || "/";
@@ -40,26 +61,96 @@ const HomeHeader = memo(
};
return (
- <header className={styles.header}>
- <div className={styles.headerContainer}>
- <div
- className={styles.logo}
- style={{ cursor: "pointer" }}
- onClick={() => router.push("/")}
- >
- <Image src={logo} alt="logo" width={50} />
- <span className={styles.logoText}>{t("header.logo")}</span>
+ <>
+ <header className={styles.header}>
+ <div className={styles.headerContainer}>
+ <div
+ className={styles.logo}
+ style={{ cursor: "pointer" }}
+ onClick={() => router.push("/")}
+ >
+ <Image src={logo} alt="logo" width={50} />
+ <span className={styles.logoText}>{t("header.logo")}</span>
+ </div>
+
+ {/* 桌面端导航 */}
+ <nav className={styles.nav}>
+ {homeHeaderRouterData.value.map((v) => {
+ return (
+ <Link
+ key={v.title}
+ className={`${styles.navLink} ${isActive(v.href) ? styles.active : ""}`}
+ href={v.href}
+ target="_blank"
+ rel="noopener noreferrer"
+ style={{ paddingTop: "3px" }}
+ >
+ {v.title}
+ </Link>
+ );
+ })}
+ </nav>
+
+ <div className={styles.headerRight}>
+ <Button
+ type="text"
+ icon={<GlobalOutlined />}
+ onClick={toggleLanguage}
+ className={styles.languageButton}
+ >
+ {userStore.lang === "zh-CN" ? "EN" : "中文"}
+ </Button>
+
+ {/* 移动端菜单按钮 */}
+ <button
+ className={styles.mobileMenuButton}
+ onClick={toggleMobileMenu}
+ aria-label="Toggle mobile menu"
+ >
+ {isMobileMenuOpen ? <CloseOutlined /> : <MenuOutlined />}
+ </button>
+
+ <button
+ onClick={() => {
+ router.push("/accounts");
+ }}
+ className={styles.getStartedBtn}
+ >
+ {t("header.getStarted")}
+ </button>
+ </div>
+ </div>
+ </header>
+
+ {/* 移动端菜单遮罩层 */}
+ {isMobileMenuOpen && (
+ <div className={styles.mobileMenuOverlay} onClick={closeMobileMenu} />
+ )}
+
+ {/* 移动端侧边菜单 */}
+ <div className={`${styles.mobileMenu} ${isMobileMenuOpen ? styles.mobileMenuOpen : ""}`}>
+ <div className={styles.mobileMenuHeader}>
+ <Image src={logo} alt="logo" width={40} />
+ <span className={styles.mobileMenuTitle}>{t("header.logo")}</span>
+ <button
+ className={styles.mobileMenuClose}
+ onClick={closeMobileMenu}
+ aria-label="Close mobile menu"
+ >
+ <CloseOutlined />
+ </button>
</div>
- <nav className={styles.nav}>
+
+ <nav className={styles.mobileMenuNav}>
{homeHeaderRouterData.value.map((v) => {
return (
<Link
key={v.title}
- className={`${styles.navLink} ${isActive(v.href) ? styles.active : ""}`}
+ className={`${styles.mobileNavLink} ${isActive(v.href) ? styles.active : ""}`}
href={v.href}
target="_blank"
rel="noopener noreferrer"
- style={{ paddingTop: "3px" }}
+ onClick={closeMobileMenu}
>
{v.title}
</Link>
@@ -67,27 +158,18 @@ const HomeHeader = memo(
})}
</nav>
- <div className={styles.headerRight}>
+ <div className={styles.mobileMenuFooter}>
<Button
type="text"
icon={<GlobalOutlined />}
onClick={toggleLanguage}
- className={styles.languageButton}
+ className={styles.mobileLanguageButton}
>
{userStore.lang === "zh-CN" ? "EN" : "中文"}
</Button>
-
- <button
- onClick={() => {
- router.push("/accounts");
- }}
- className={styles.getStartedBtn}
- >
- {t("header.getStarted")}
- </button>
</div>
</div>
- </header>
+ </>
);
}),
);