首页菜单栏下拉页面调整高度1024适配

This commit is contained in:
Eamon-meng
2025-06-12 18:51:54 +08:00
parent 831daeb46e
commit 8bbc0fc5f5
6 changed files with 152 additions and 42 deletions

View File

@@ -9,6 +9,7 @@ import prod from '@/assets/header/product/prod.svg'
import custom from '@/assets/header/product/custom.svg'
import {HeaderContext} from '@/app/(home)/@header/_client/provider'
import {useSearchParams} from 'next/navigation'
import {useRouter} from 'next/navigation'
type TabType = 'domestic' | 'oversea'
@@ -100,9 +101,20 @@ export default function ProductMenu() {
const urlType = searchParams?.get('type')
console.log('URL参数:', urlType)
}, [searchParams])
// 响应式布局
const [isMobile, setIsMobile] = useState(false)
useEffect(() => {
const checkMobile = () => {
setIsMobile(window.innerWidth <= 1024)
}
checkMobile()
window.addEventListener('resize', checkMobile)
return () => window.removeEventListener('resize', checkMobile)
}, [])
return (
<Wrap className="flex">
<Wrap className="flex h-75">
<ul role="tablist" className="w-48">
<Tab selected={type === 'domestic'} onSelect={() => setType('domestic')}></Tab>
<Tab selected={type === 'oversea'} onSelect={() => setType('oversea')}></Tab>
@@ -145,12 +157,21 @@ export function DomesticLink(props: {
active?: boolean
}) {
const ctx = useContext(HeaderContext)
const router = useRouter()
if (!ctx) {
throw new Error(`HeaderContext not found`)
}
const onClick = () => {
// const onClick = () => {
// ctx.setMenu(false)
// }
const onClick = (e: React.MouseEvent) => {
e.preventDefault()
e.stopPropagation()
ctx.setMenu(false)
setTimeout(() => {
router.push(props.href)
}, ctx.isMobile ? 100 : 0)
}
return (