|
|
@ -1,6 +1,6 @@ |
|
|
|
import {useEffect, useState} from "react"; |
|
|
|
import Taro from '@tarojs/taro'; |
|
|
|
import {Button, Space} from '@nutui/nutui-react-taro' |
|
|
|
import {Button, Space, Sticky} from '@nutui/nutui-react-taro' |
|
|
|
import {TriangleDown} from '@nutui/icons-react-taro' |
|
|
|
import {Avatar, NavBar} from '@nutui/nutui-react-taro' |
|
|
|
import {getUserInfo, getWxOpenId} from "@/api/layout"; |
|
|
@ -22,6 +22,7 @@ const Header = (props: any) => { |
|
|
|
|
|
|
|
const [IsLogin, setIsLogin] = useState<boolean>(true) |
|
|
|
const [statusBarHeight, setStatusBarHeight] = useState<number>() |
|
|
|
const [stickyStatus, setStickyStatus] = useState<boolean>(false) |
|
|
|
|
|
|
|
const reload = async () => { |
|
|
|
Taro.getSystemInfo({ |
|
|
@ -166,18 +167,40 @@ const Header = (props: any) => { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// 处理粘性布局状态变化
|
|
|
|
const onStickyChange = (isSticky: boolean) => { |
|
|
|
setStickyStatus(isSticky) |
|
|
|
console.log('Header 粘性状态:', isSticky ? '已固定' : '取消固定') |
|
|
|
} |
|
|
|
|
|
|
|
// 获取小程序系统信息
|
|
|
|
const getSystemInfo = () => { |
|
|
|
const systemInfo = Taro.getSystemInfoSync() |
|
|
|
// 状态栏高度 + 导航栏高度 (一般为44px)
|
|
|
|
return (systemInfo.statusBarHeight || 0) + 44 |
|
|
|
} |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
reload().then() |
|
|
|
}, []) |
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<View className={'fixed top-0 header-bg'} style={{ |
|
|
|
height: !props.stickyStatus ? '180px' : `${(statusBarHeight || 0) + 44}px`, |
|
|
|
paddingBottom: !props.stickyStatus ? '12px' : '0px' |
|
|
|
<Sticky |
|
|
|
threshold={0} |
|
|
|
onChange={onStickyChange} |
|
|
|
style={{ |
|
|
|
zIndex: 1000, |
|
|
|
backgroundColor: stickyStatus ? '#03605c' : 'transparent', |
|
|
|
transition: 'background-color 0.3s ease', |
|
|
|
}} |
|
|
|
> |
|
|
|
<View className={'header-bg'} style={{ |
|
|
|
height: !stickyStatus ? '180px' : `${(statusBarHeight || 0) + 44}px`, |
|
|
|
paddingBottom: !stickyStatus ? '12px' : '0px' |
|
|
|
}}> |
|
|
|
{/* 只在非吸顶状态下显示搜索框 */} |
|
|
|
{!props.stickyStatus && <MySearch statusBarHeight={statusBarHeight} />} |
|
|
|
{!stickyStatus && <MySearch statusBarHeight={statusBarHeight} />} |
|
|
|
</View> |
|
|
|
<NavBar |
|
|
|
style={{ |
|
|
@ -213,6 +236,7 @@ const Header = (props: any) => { |
|
|
|
)}> |
|
|
|
{/*<QRLoginButton />*/} |
|
|
|
</NavBar> |
|
|
|
</Sticky> |
|
|
|
</> |
|
|
|
) |
|
|
|
} |
|
|
|