| | |
| | | const [pageType, setPageType] = useState('') //出发地 start 目的地 end |
| | | const [showAllHistory, setShowAllHistory] = useState(false) // 是否展示全部历史记录 |
| | | const [showAllRecommend, setShowAllRecommend] = useState(false) // 是否展示全部推荐站点 |
| | | const [historyContentHeight, setHistoryContentHeight] = useState(0) |
| | | const [historyCollapsedHeight, setHistoryCollapsedHeight] = useState(0) |
| | | const [recommendContentHeight, setRecommendContentHeight] = useState(0) |
| | | const [recommendCollapsedHeight, setRecommendCollapsedHeight] = useState(0) |
| | | |
| | | const MAX_SHOW_COUNT = 5 // 默认最多显示5条 |
| | | |
| | |
| | | |
| | | |
| | | const recommendList = siteList.length > 0 ? siteList : nearbySiteList; |
| | | const historyMaxHeight = showAllHistory ? historyContentHeight : historyCollapsedHeight; |
| | | const recommendMaxHeight = showAllRecommend ? recommendContentHeight : recommendCollapsedHeight; |
| | | |
| | | useEffect(() => { |
| | | if (historySite.length === 0) { |
| | | setHistoryContentHeight(0); |
| | | setHistoryCollapsedHeight(0); |
| | | return; |
| | | } |
| | | setTimeout(() => { |
| | | const query = Taro.createSelectorQuery(); |
| | | query.select('#history-card-content').boundingClientRect(); |
| | | query.selectAll('#history-card-content .history-item').boundingClientRect(); |
| | | query.exec((res) => { |
| | | const container = res?.[0]; |
| | | const items = res?.[1] || []; |
| | | if (!container || items.length === 0) return; |
| | | const top = container.top; |
| | | const last = items[items.length - 1]; |
| | | const fullHeight = Math.max(0, last.bottom - top); |
| | | const collapsedIndex = Math.min(MAX_SHOW_COUNT, items.length) - 1; |
| | | const collapsed = Math.max(0, items[collapsedIndex].bottom - top); |
| | | setHistoryContentHeight(fullHeight); |
| | | setHistoryCollapsedHeight(collapsed); |
| | | }); |
| | | }, 0); |
| | | }, [historySite.length]); |
| | | |
| | | useEffect(() => { |
| | | if (recommendList.length === 0) { |
| | | setRecommendContentHeight(0); |
| | | setRecommendCollapsedHeight(0); |
| | | return; |
| | | } |
| | | setTimeout(() => { |
| | | const query = Taro.createSelectorQuery(); |
| | | query.select('#recommend-card-content').boundingClientRect(); |
| | | query.selectAll('#recommend-card-content .history-item').boundingClientRect(); |
| | | query.exec((res) => { |
| | | const container = res?.[0]; |
| | | const items = res?.[1] || []; |
| | | if (!container || items.length === 0) return; |
| | | const top = container.top; |
| | | const last = items[items.length - 1]; |
| | | const fullHeight = Math.max(0, last.bottom - top); |
| | | const collapsedIndex = Math.min(MAX_SHOW_COUNT, items.length) - 1; |
| | | const collapsed = Math.max(0, items[collapsedIndex].bottom - top); |
| | | setRecommendContentHeight(fullHeight); |
| | | setRecommendCollapsedHeight(collapsed); |
| | | }); |
| | | }, 0); |
| | | }, [recommendList.length]); |
| | | |
| | | return ( |
| | | <View className='search-page'> |
| | |
| | | historySite.length > 0 && |
| | | <View className='history-card'> |
| | | <View className='card-header'>历史记录</View> |
| | | <View className='card-content'> |
| | | <View |
| | | className='card-content list-content' |
| | | id='history-card-content' |
| | | style={historyMaxHeight ? { maxHeight: `${historyMaxHeight}px` } : undefined} |
| | | > |
| | | { |
| | | historySite.map((item, index) => { |
| | | return <View onClick={() => onChangeSelectSite(item)} className='history-item' key={item.id || index}> |
| | |
| | | recommendList.length > 0 && |
| | | <View className='recommend-card'> |
| | | <View className='card-header'>{siteList.length > 0 ? '推荐站点' : '附近站点'}</View> |
| | | <View className='card-content'> |
| | | <View |
| | | className='card-content list-content' |
| | | id='recommend-card-content' |
| | | style={recommendMaxHeight ? { maxHeight: `${recommendMaxHeight}px` } : undefined} |
| | | > |
| | | { |
| | | recommendList.map((item, index) => { |
| | | return <View onClick={() => onChangeSelectSite(item)} className='history-item' key={item.id || index}> |