zhou zhou
3 小时以前 6103a8e5d2316af7fcf6b246e9e866e5216476f0
rsf-admin/src/page/components/DictSelect.jsx
@@ -3,7 +3,7 @@
    useTranslate, useNotify, required
} from 'react-admin';
import request from '@/utils/request';
import { Select, MenuItem, FormControl, InputLabel } from '@mui/material';
import { Autocomplete, TextField, FormControl } from '@mui/material';
const DictSelect = (props) => {
    const { dictTypeCode, label, group, value, onChange, ...params } = props;
@@ -29,33 +29,35 @@
        }
    };
    const handleChange = (event) => {
        const selectedValue = event.target.value;
    const validValueObj = list.find(item => item.value === value) || null;
    const handleChange = (event, newValue) => {
        if (onChange) {
            onChange(event);
            onChange({ target: { value: newValue ? newValue.value : '' } });
        }
    };
    const validValue = list.some(item => item.value === value) ? value : '';
    return (
        <FormControl fullWidth>
            <InputLabel id="demo-select-small-label">{label}</InputLabel>
            <Select
                labelId="demo-select-small-label"
                value={validValue}
                variant="filled"
        <FormControl fullWidth size="small">
            <Autocomplete
                value={validValueObj}
                onChange={handleChange}
                size='small'
            >
                {list.map((item) => (
                    <MenuItem key={item.value} value={item.value}>
                        {item.label}
                    </MenuItem>
                ))}
            </Select>
                options={list}
                getOptionLabel={(option) => option.label || ''}
                isOptionEqualToValue={(option, val) => option.value === val.value}
                size="small"
                ListboxProps={{ style: { maxHeight: '200px' } }}
                renderInput={(p) => (
                    <TextField
                        {...p}
                        label={label}
                        variant="filled"
                    />
                )}
                {...params}
            />
        </FormControl>
    );
};
export default DictSelect;
export default DictSelect;