import { useEffect, useState, type FC, type Key } from 'react'; import { Select } from 'antd'; import type { SelectProps, DefaultOptionType } from 'antd/es/select'; import { useTranslation } from 'react-i18next'; import { request } from '@/utils/request'; interface OptionType { [key: string]: Key | string | number; } interface ApiResponse { items?: T[]; } interface CustomSelectProps extends Omit { url: string; params?: Record; valueKey?: string | string[]; labelKey?: string; placeholder?: string; hasAll?: boolean; allTitle?: string; format?: (items: OptionType[]) => OptionType[]; showSearch?: boolean; optionFilterProp?: string; filterOption?: (inputValue: string, option?: DefaultOptionType) => boolean; } const defaultFilterOption = (inputValue: string, option?: DefaultOptionType): boolean => { if (!option || !inputValue) return true; const label = String(option.children || option.label || ''); return label.toLowerCase().includes(inputValue.toLowerCase()); }; const CustomSelect: FC = ({ url, params, valueKey = 'value', labelKey = 'label', placeholder, hasAll = true, allTitle, format, showSearch = false, filterOption, ...props }) => { const { t } = useTranslation(); const [options, setOptions] = useState([]); useEffect(() => { request.get>(url, params).then((res) => { const data = Array.isArray(res) ? res : res?.items || []; setOptions(data); }); }, [url, params]); const displayOptions = format ? format(options) : options; return ( ); }; export default CustomSelect;