fix: 修改多选下拉框数据问题

This commit is contained in:
wjh 2024-03-15 19:06:15 +08:00
parent 3920cb20c3
commit c544ae80f1

View File

@ -21,25 +21,13 @@ type Props = SelectProps<any, any> & {
const isEmptyObject = (val: any) => !isValid(val) || (typeof val === 'object' && Object.keys(val).length === 0);
const ObjectSelect = (props: Props) => {
const {
value,
options: defultValue,
onChange,
fieldNames,
mode,
loading,
rawOptions,
defaultValue,
...others
} = props;
const [options, setOptions] = useState([]);
const [defult, setDefult] = useState(false);
const { value, options, onChange, fieldNames, mode, loading, rawOptions, defaultValue, ...others } = props;
const [defoptions, setDefOptions] = useState();
const fieldSchema = useFieldSchema();
const collectionName = fieldSchema['collectionName'];
const filterField = fieldSchema['x-component-props']['params'];
const filter = filterField ? JSON.stringify(filterField.filter) : {};
const api = useAPIClient();
useAsyncEffect(async () => {
if (collectionName) {
const defValue = await api.request({
@ -49,10 +37,9 @@ const ObjectSelect = (props: Props) => {
filter: filterField ? { ...filterField.filter } : {},
},
});
setOptions(defValue?.data?.data);
setDefOptions(defValue?.data?.data);
}
}, [filter]);
const toValue = (v: any) => {
if (isEmptyObject(v)) {
return;
@ -89,7 +76,7 @@ const ObjectSelect = (props: Props) => {
}}
labelInValue
notFoundContent={loading ? <Spin /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />}
options={options}
options={defoptions || options}
fieldNames={fieldNames}
showSearch
popupMatchSelectWidth={false}