列表联调
This commit is contained in:
@@ -1,65 +1,134 @@
|
||||
import { View, Text, Image } from "@tarojs/components";
|
||||
import img from "@/config/images";
|
||||
import { getCurrentLocation } from "@/utils/locationUtils";
|
||||
import styles from "./index.module.scss";
|
||||
import { useEffect } from "react";
|
||||
import { useGlobalState } from "@/store/global";
|
||||
import { useListState } from "@/store/listStore";
|
||||
import CustomNavbar from '@/components/CustomNavbar'
|
||||
import CustomNavbar from "@/components/CustomNavbar";
|
||||
import { Input } from "@nutui/nutui-react-taro";
|
||||
import Taro from "@tarojs/taro";
|
||||
import "./index.scss";
|
||||
|
||||
const ListHeader = () => {
|
||||
interface IProps {
|
||||
config?: {
|
||||
showInput: boolean;
|
||||
inputLeftIcon: string;
|
||||
iconPath?: string;
|
||||
leftIconClick: () => void;
|
||||
};
|
||||
}
|
||||
|
||||
const ListHeader = (props: IProps) => {
|
||||
const { config } = props;
|
||||
const {
|
||||
showInput = false,
|
||||
inputLeftIcon,
|
||||
leftIconClick,
|
||||
} = config || {};
|
||||
const {
|
||||
updateState,
|
||||
location,
|
||||
getLocationText,
|
||||
getLocationLoading,
|
||||
statusNavbarHeightInfo,
|
||||
} = useGlobalState();
|
||||
const { gamesNum } = useListState();
|
||||
const { gamesNum, searchValue, isShowInputCustomerNavBar } = useListState();
|
||||
const { statusBarHeight, navbarHeight } = statusNavbarHeightInfo;
|
||||
|
||||
// 获取位置信息
|
||||
const getCurrentLocal = () => {
|
||||
updateState({
|
||||
getLocationLoading: true,
|
||||
});
|
||||
getCurrentLocation().then((res) => {
|
||||
updateState({
|
||||
getLocationLoading: false,
|
||||
location: res || {},
|
||||
});
|
||||
});
|
||||
};
|
||||
useEffect(() => {
|
||||
getCurrentLocal();
|
||||
}, []);
|
||||
|
||||
const currentAddress = getLocationLoading
|
||||
? getLocationText
|
||||
: location?.address;
|
||||
|
||||
const handleInputClick = () => {
|
||||
const pages = Taro.getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const currentPagePath = currentPage.route;
|
||||
if (currentPagePath === "pages/searchResult/index") {
|
||||
Taro.navigateBack();
|
||||
} else {
|
||||
Taro.navigateTo({
|
||||
url: "/pages/search/index",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 点击logo
|
||||
const handleLogoClick = () => {
|
||||
Taro.redirectTo({
|
||||
url: "pages/list/index", // 列表页
|
||||
});
|
||||
};
|
||||
|
||||
const handleInputLeftIconClick = () => {
|
||||
if (leftIconClick) {
|
||||
leftIconClick();
|
||||
} else {
|
||||
handleLogoClick();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<CustomNavbar>
|
||||
<View
|
||||
className={styles.container}
|
||||
style={{
|
||||
height: `${navbarHeight}px`,
|
||||
paddingTop: `${statusBarHeight}px`,
|
||||
}}
|
||||
>
|
||||
{/* logo */}
|
||||
<Image src={img.ICON_LOGO} className={styles.logo} />
|
||||
<View className={styles.line} />
|
||||
<View className={styles.content}>
|
||||
<View className={styles.cityWrapper}>
|
||||
{/* 位置 */}
|
||||
<Text className={styles.city}>{currentAddress}</Text>
|
||||
{!getLocationLoading && (
|
||||
<Image src={img.ICON_CHANGE} className={styles.change} />
|
||||
)}
|
||||
<View className="listNavWrapper">
|
||||
{/* 首页logo 导航*/}
|
||||
<View
|
||||
className={`listNavContainer toggleElement firstElement hidden ${
|
||||
(!isShowInputCustomerNavBar && !showInput) && "visible"
|
||||
}`}
|
||||
style={{
|
||||
height: `${navbarHeight}px`,
|
||||
paddingTop: `${statusBarHeight}px`,
|
||||
}}
|
||||
>
|
||||
<View className="listNavContentWrapper">
|
||||
{/* logo */}
|
||||
<Image
|
||||
src={img.ICON_LOGO}
|
||||
className="listNavLogo"
|
||||
onClick={handleLogoClick}
|
||||
/>
|
||||
<View className="listNavLine" />
|
||||
<View className="listNavContent">
|
||||
<View className="listNavCityWrapper">
|
||||
{/* 位置 */}
|
||||
<Text className="listNavCity">{currentAddress}</Text>
|
||||
{!getLocationLoading && currentAddress && (
|
||||
<Image src={img.ICON_CHANGE} className="listNavChange" />
|
||||
)}
|
||||
</View>
|
||||
<View className="listNavInfoWrapper">
|
||||
<Text className="listNavInfo">附近${gamesNum}场球局</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.infoWrapper}>
|
||||
<Text className={styles.info}>附近${gamesNum}场球局</Text>
|
||||
</View>
|
||||
{/* 搜索导航 */}
|
||||
<View
|
||||
className={`inputCustomerNavbarContainer toggleElement secondElement hidden ${
|
||||
(isShowInputCustomerNavBar || showInput) && "visible"
|
||||
} ${showInput && "inputCustomerNavbarShowInput"}`}
|
||||
style={{
|
||||
height: `${navbarHeight}px`,
|
||||
paddingTop: `${statusBarHeight}px`,
|
||||
}}
|
||||
>
|
||||
<View className="navContent">
|
||||
{/* logo */}
|
||||
<Image
|
||||
src={inputLeftIcon || img.ICON_LIST_INPUT_LOGO}
|
||||
className="logo"
|
||||
onClick={handleInputLeftIconClick}
|
||||
/>
|
||||
{/* 搜索框 */}
|
||||
<View className="searchContainer">
|
||||
<Image
|
||||
className="searchIcon icon16"
|
||||
src={img.ICON_LIST_SEARCH_SEARCH}
|
||||
/>
|
||||
<Input
|
||||
placeholder="搜索上海的球局和场地"
|
||||
clearable={false}
|
||||
value={searchValue}
|
||||
onClick={handleInputClick}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user