|
|
@ -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,53 +167,76 @@ 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' |
|
|
|
}}> |
|
|
|
{/* 只在非吸顶状态下显示搜索框 */} |
|
|
|
{!props.stickyStatus && <MySearch statusBarHeight={statusBarHeight} />} |
|
|
|
</View> |
|
|
|
<NavBar |
|
|
|
<Sticky |
|
|
|
threshold={0} |
|
|
|
onChange={onStickyChange} |
|
|
|
style={{ |
|
|
|
marginTop: `${statusBarHeight}px`, |
|
|
|
marginBottom: '0px', |
|
|
|
backgroundColor: 'transparent' |
|
|
|
}} |
|
|
|
onBackClick={() => { |
|
|
|
zIndex: 1000, |
|
|
|
backgroundColor: stickyStatus ? '#03605c' : 'transparent', |
|
|
|
transition: 'background-color 0.3s ease', |
|
|
|
}} |
|
|
|
left={ |
|
|
|
!IsLogin ? ( |
|
|
|
<View style={{display: 'flex', alignItems: 'center'}}> |
|
|
|
<Button style={{color: '#ffffff'}} open-type="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}> |
|
|
|
<Space> |
|
|
|
<Avatar |
|
|
|
size="22" |
|
|
|
src={getWebsiteLogo()} |
|
|
|
/> |
|
|
|
<Text style={{color: '#ffffff'}}>{getWebsiteName()}</Text> |
|
|
|
<TriangleDown size={9} className={'text-white'}/> |
|
|
|
</Space> |
|
|
|
</Button> |
|
|
|
</View> |
|
|
|
) : ( |
|
|
|
<View style={{display: 'flex', alignItems: 'center', gap: '8px'}}> |
|
|
|
<Avatar |
|
|
|
size="22" |
|
|
|
src={getWebsiteLogo()} |
|
|
|
/> |
|
|
|
<Text className={'text-white'}>{getWebsiteName()}</Text> |
|
|
|
<TriangleDown className={'text-white'} size={9}/> |
|
|
|
</View> |
|
|
|
)}> |
|
|
|
{/*<QRLoginButton />*/} |
|
|
|
</NavBar> |
|
|
|
> |
|
|
|
<View className={'header-bg'} style={{ |
|
|
|
height: !stickyStatus ? '180px' : `${(statusBarHeight || 0) + 44}px`, |
|
|
|
paddingBottom: !stickyStatus ? '12px' : '0px' |
|
|
|
}}> |
|
|
|
{/* 只在非吸顶状态下显示搜索框 */} |
|
|
|
{!stickyStatus && <MySearch statusBarHeight={statusBarHeight} />} |
|
|
|
</View> |
|
|
|
<NavBar |
|
|
|
style={{ |
|
|
|
marginTop: `${statusBarHeight}px`, |
|
|
|
marginBottom: '0px', |
|
|
|
backgroundColor: 'transparent' |
|
|
|
}} |
|
|
|
onBackClick={() => { |
|
|
|
}} |
|
|
|
left={ |
|
|
|
!IsLogin ? ( |
|
|
|
<View style={{display: 'flex', alignItems: 'center'}}> |
|
|
|
<Button style={{color: '#ffffff'}} open-type="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}> |
|
|
|
<Space> |
|
|
|
<Avatar |
|
|
|
size="22" |
|
|
|
src={getWebsiteLogo()} |
|
|
|
/> |
|
|
|
<Text style={{color: '#ffffff'}}>{getWebsiteName()}</Text> |
|
|
|
<TriangleDown size={9} className={'text-white'}/> |
|
|
|
</Space> |
|
|
|
</Button> |
|
|
|
</View> |
|
|
|
) : ( |
|
|
|
<View style={{display: 'flex', alignItems: 'center', gap: '8px'}}> |
|
|
|
<Avatar |
|
|
|
size="22" |
|
|
|
src={getWebsiteLogo()} |
|
|
|
/> |
|
|
|
<Text className={'text-white'}>{getWebsiteName()}</Text> |
|
|
|
<TriangleDown className={'text-white'} size={9}/> |
|
|
|
</View> |
|
|
|
)}> |
|
|
|
{/*<QRLoginButton />*/} |
|
|
|
</NavBar> |
|
|
|
</Sticky> |
|
|
|
</> |
|
|
|
) |
|
|
|
} |
|
|
|