import React, { useEffect, useState } from 'react'; import styles from './index.less'; import { Select } from 'antd'; import useMapList from '@/hooks/useMapList'; import { SearchOutlined } from '@ant-design/icons'; type mapResType = { text: string; value: string; }; const { Option } = Select; type SearchInputProps = { onSearch: (s: string) => void; }; const SearchInput: React.FC = ({ onSearch }) => { const mapList = useMapList(); const [resData, setResData] = useState([]); const [value, setValue] = useState(); const handleSearch = (value: string) => { //debugger; if (value) { let data: mapResType[] = []; mapList.map((item, index) => { if (item.localName.indexOf(value) > -1) { data.push({ text: item.localName, value: item.localName, }); } setResData(data); }); } else { setResData([]); } }; const handleChange = (sel: string) => { setValue(null); //清空输入的值 setResData([]); //清空搜索匹配列表 onSearch(sel); }; return (
); }; export default SearchInput;