fix: 修改多选下拉框数据问题
This commit is contained in:
parent
3920cb20c3
commit
c544ae80f1
@ -21,25 +21,13 @@ type Props = SelectProps<any, any> & {
|
|||||||
const isEmptyObject = (val: any) => !isValid(val) || (typeof val === 'object' && Object.keys(val).length === 0);
|
const isEmptyObject = (val: any) => !isValid(val) || (typeof val === 'object' && Object.keys(val).length === 0);
|
||||||
|
|
||||||
const ObjectSelect = (props: Props) => {
|
const ObjectSelect = (props: Props) => {
|
||||||
const {
|
const { value, options, onChange, fieldNames, mode, loading, rawOptions, defaultValue, ...others } = props;
|
||||||
value,
|
const [defoptions, setDefOptions] = useState();
|
||||||
options: defultValue,
|
|
||||||
onChange,
|
|
||||||
fieldNames,
|
|
||||||
mode,
|
|
||||||
loading,
|
|
||||||
rawOptions,
|
|
||||||
defaultValue,
|
|
||||||
...others
|
|
||||||
} = props;
|
|
||||||
const [options, setOptions] = useState([]);
|
|
||||||
const [defult, setDefult] = useState(false);
|
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const collectionName = fieldSchema['collectionName'];
|
const collectionName = fieldSchema['collectionName'];
|
||||||
const filterField = fieldSchema['x-component-props']['params'];
|
const filterField = fieldSchema['x-component-props']['params'];
|
||||||
const filter = filterField ? JSON.stringify(filterField.filter) : {};
|
const filter = filterField ? JSON.stringify(filterField.filter) : {};
|
||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
|
|
||||||
useAsyncEffect(async () => {
|
useAsyncEffect(async () => {
|
||||||
if (collectionName) {
|
if (collectionName) {
|
||||||
const defValue = await api.request({
|
const defValue = await api.request({
|
||||||
@ -49,10 +37,9 @@ const ObjectSelect = (props: Props) => {
|
|||||||
filter: filterField ? { ...filterField.filter } : {},
|
filter: filterField ? { ...filterField.filter } : {},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setOptions(defValue?.data?.data);
|
setDefOptions(defValue?.data?.data);
|
||||||
}
|
}
|
||||||
}, [filter]);
|
}, [filter]);
|
||||||
|
|
||||||
const toValue = (v: any) => {
|
const toValue = (v: any) => {
|
||||||
if (isEmptyObject(v)) {
|
if (isEmptyObject(v)) {
|
||||||
return;
|
return;
|
||||||
@ -89,7 +76,7 @@ const ObjectSelect = (props: Props) => {
|
|||||||
}}
|
}}
|
||||||
labelInValue
|
labelInValue
|
||||||
notFoundContent={loading ? <Spin /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />}
|
notFoundContent={loading ? <Spin /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />}
|
||||||
options={options}
|
options={defoptions || options}
|
||||||
fieldNames={fieldNames}
|
fieldNames={fieldNames}
|
||||||
showSearch
|
showSearch
|
||||||
popupMatchSelectWidth={false}
|
popupMatchSelectWidth={false}
|
||||||
|
Loading…
Reference in New Issue
Block a user