import EditIcon from '@mui/icons-material/Edit'; 
 | 
import { useState, useEffect } from 'react'; 
 | 
import { 
 | 
    Button, useListContext, SelectInput, 
 | 
    required, SelectArrayInput, 
 | 
    useTranslate, useNotify, 
 | 
    SelectArrayInputClasses 
 | 
} from 'react-admin'; 
 | 
import request from '@/utils/request'; 
 | 
  
 | 
const StaSelect = (props) => { 
 | 
    const {  
 | 
        type , 
 | 
        name,  
 | 
        multiple = false,  
 | 
        perPage = 100,  // 默认每页显示100条数据 
 | 
        page = 1,       // 默认第一页 
 | 
        ...parmas  
 | 
    } = props; 
 | 
    const translate = useTranslate(); 
 | 
    const notify = useNotify(); 
 | 
    const [list, setList] = useState([]); 
 | 
    const [loading, setLoading] = useState(false); 
 | 
  
 | 
    useEffect(() => { 
 | 
        http(); 
 | 
    }, [type, page, perPage]); 
 | 
  
 | 
    const http = async () => { 
 | 
        setLoading(true); 
 | 
        try { 
 | 
            const res = await request.post('/selectStaList/list', {  
 | 
                type: type                 
 | 
            }); 
 | 
             
 | 
            if (res?.data?.code === 200) { 
 | 
                // 使用Set来过滤重复的site值 
 | 
                const uniqueSites = new Set(); 
 | 
                setList(res.data.data 
 | 
                    .filter(item => {                         
 | 
                        if (uniqueSites.has(item.site)) { 
 | 
                            return false; 
 | 
                        } 
 | 
                        uniqueSites.add(item.site); 
 | 
                        return true; 
 | 
                    }) 
 | 
                    .map((item) => { 
 | 
                        return { 
 | 
                            id: item.site, 
 | 
                            name: item.site 
 | 
                        } 
 | 
                    })); 
 | 
            } else { 
 | 
                notify(res.data.msg); 
 | 
            } 
 | 
        } catch (error) { 
 | 
            notify('加载站点失败', 'error'); 
 | 
            console.error('加载站点失败:', error); 
 | 
        } finally { 
 | 
            setLoading(false); 
 | 
        } 
 | 
    }; 
 | 
  
 | 
    const InputComponent = multiple ? SelectArrayInput : SelectInput; 
 | 
  
 | 
    return ( 
 | 
        <SelectInput 
 | 
            source={name} 
 | 
            choices={list} 
 | 
            isLoading={loading} 
 | 
            optionValue='id' 
 | 
            optionText='name' 
 | 
            {...parmas} 
 | 
        /> 
 | 
    ); 
 | 
}; 
 | 
  
 | 
export default StaSelect; 
 |