Skip to content

Commit 0f935d7

Browse files
archerarcher
authored andcommitted
fix: 修复移动端菜单样式问题
- 修复语言选择器下拉框在移动端溢出问题(改为左对齐) - 移动端 Logo 旁边显示 FastGPT 文字 - 菜单打开时锁定背景滚动(仅移动端) - 点击蒙层外部可关闭菜单 - 菜单 header 高度与原 header 对齐(56px) - 菜单内容区域可滚动
1 parent df9df5f commit 0f935d7

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

src/components/header/Header.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { siteConfig } from '@/config/site';
66
import { MenuIcon } from 'lucide-react';
77
import Image from 'next/image';
88
import Link from 'next/link';
9-
import { useState } from 'react';
9+
import { useState, useEffect } from 'react';
1010
import { CgClose } from 'react-icons/cg';
1111
import { useParams } from 'next/navigation';
1212
import { defaultLocale } from '@/lib/i18n';
@@ -24,6 +24,20 @@ const Header = ({ dict, CTALocale }: { dict: Dict; CTALocale: any }) => {
2424
const params = useParams<{ lang: string }>();
2525
const lang = params?.lang || defaultLocale;
2626

27+
useEffect(() => {
28+
if (isMenuOpen) {
29+
// 只在移动端锁定滚动
30+
if (window.innerWidth < 768) {
31+
document.body.style.overflow = 'hidden';
32+
}
33+
} else {
34+
document.body.style.overflow = '';
35+
}
36+
return () => {
37+
document.body.style.overflow = '';
38+
};
39+
}, [isMenuOpen]);
40+
2741
return (
2842
<header className="relative py-2 mx-auto max-w-8xl px-4 sm:px-6 lg:px-8 flex justify-between">
2943
<nav className="z-50 flex justify-between w-full fix-header">
@@ -49,24 +63,27 @@ const Header = ({ dict, CTALocale }: { dict: Dict; CTALocale: any }) => {
4963
</button>
5064

5165
{isMenuOpen && (
52-
<div className="absolute top-0 left-0 z-50 w-screen h-screen bg-overlay/50">
53-
<div className="p-5 bg-background rounded shadow-sm">
54-
<div className="flex items-center justify-between mb-4">
66+
<div
67+
className="absolute top-0 left-0 z-50 w-screen h-screen bg-overlay/50"
68+
onClick={() => setIsMenuOpen(false)}
69+
>
70+
<div className="bg-background h-screen overflow-y-auto" onClick={(e) => e.stopPropagation()}>
71+
<div className="px-4 sm:px-6 lg:px-8 flex items-center justify-between h-[56px]">
5572
<LogoFC dict={dict} lang={lang} />
5673

5774
<div>
5875
<button
5976
aria-label="Close Menu"
6077
title="Close Menu"
61-
className="tracking-wide transition-colors duration-200 font-norma"
78+
className="p-2 -mr-1 transition duration-200 rounded focus:outline-none focus:shadow-outline"
6279
onClick={() => setIsMenuOpen(false)}
6380
>
6481
<CgClose />
6582
</button>
6683
</div>
6784
</div>
6885

69-
<nav>
86+
<nav className="px-4 sm:px-6 lg:px-8">
7087
<ul className="space-y-4">
7188
{dict?.links.map((link) => (
7289
<Link
@@ -83,7 +100,7 @@ const Header = ({ dict, CTALocale }: { dict: Dict; CTALocale: any }) => {
83100
</ul>
84101
</nav>
85102

86-
<div className="mt-4 border-t-1 flex flex-col gap-6 pt-4 border-white/10">
103+
<div className="mt-4 border-t pt-4 border-white/10 px-4 sm:px-6 lg:px-8">
87104
<LangSwitcher />
88105
</div>
89106
</div>
@@ -111,7 +128,7 @@ const LogoFC = ({ dict, lang }: { dict: Dict; lang: string }) => (
111128
width={32}
112129
height={32}
113130
/>
114-
<span className="text-white hidden md:block">FastGPT</span>
131+
<span className="text-white">FastGPT</span>
115132
</Link>
116133

117134
<ul className="hidden items-center gap-5 md:flex">

src/components/header/LangSwitcher.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const LangSwitcher = () => {
8484
{open && (
8585
<div
8686
role="listbox"
87-
className="absolute right-0 top-full mt-1 z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95"
87+
className="absolute left-0 top-full mt-1 z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95"
8888
>
8989
<div className="p-1">
9090
{Object.keys(localeNames).map((key: string) => (

0 commit comments

Comments
 (0)