Merge pull request 'fix: 修改多选下拉框数据问题' (#392) from fix_multipleSelect into @hera/dev

Reviewed-on: daoyoucloud/tachycode#392
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
This commit is contained in:
sealday 2024-03-15 19:13:40 +08:00
commit 759f51dae8

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 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}