| | |
| | | |
| | | function SiteSearchPage() { |
| | | const [searchValue, setSearchValue] = useState('') //搜索值 |
| | | const [searchCursor, setSearchCursor] = useState(0) |
| | | const [shouldFocusSearchInput, setShouldFocusSearchInput] = useState(true) |
| | | const [showAllHistory, setShowAllHistory] = useState(false) // 是否展示全部历史记录 |
| | | const [showAllRecommend, setShowAllRecommend] = useState(false) // 是否展示全部推荐站点 |
| | | const [distanceConfig, setDistanceConfig] = useState<any>({}) |
| | |
| | | }); |
| | | |
| | | const changeSearchValue = (e: any) => { |
| | | const val = e.detail.value; |
| | | const val = String(e?.detail?.value || ''); |
| | | const nextCursor = typeof e?.detail?.cursor === 'number' |
| | | ? e.detail.cursor |
| | | : val.length; |
| | | setSearchValue(val); |
| | | setSearchCursor(nextCursor); |
| | | setShouldFocusSearchInput(true); |
| | | debouncedSearch(val); |
| | | return val; |
| | | } |
| | |
| | | |
| | | const clearSearchValue = () => { |
| | | setSearchValue(''); |
| | | setSearchCursor(0); |
| | | setShouldFocusSearchInput(true); |
| | | clearSearchResults(); |
| | | } |
| | | const handleCloseTipPopup = () => { |
| | |
| | | <View className={`search-icon ${pageType == 'end' ? 'end-icon' : ''}`}></View> |
| | | <View className='search-input-box'> |
| | | <Input className='search-input' placeholder={pageType == 'start' ? '请输入上车点' : '请输入目的地'} value={searchValue} |
| | | cursor={searchCursor} |
| | | focus={shouldFocusSearchInput} |
| | | onInput={(e) => changeSearchValue(e)} |
| | | onBlur={flushDebouncedSearch} |
| | | onFocus={(e) => { |
| | | const nextCursor = typeof e?.detail?.cursor === 'number' |
| | | ? e.detail.cursor |
| | | : searchValue.length; |
| | | setSearchCursor(nextCursor); |
| | | setShouldFocusSearchInput(true); |
| | | }} |
| | | onBlur={() => { |
| | | setShouldFocusSearchInput(false); |
| | | flushDebouncedSearch(); |
| | | }} |
| | | onConfirm={(e) => { |
| | | const keyword = e?.detail?.value || searchValue; // 确认搜索关键字,优先取输入框事件值 |
| | | confirmSearch(keyword); |