fix: 修改自动补全筛选失效问题

This commit is contained in:
wjh 2024-03-15 20:15:46 +08:00
parent c544ae80f1
commit 7f856cffb0
2 changed files with 3 additions and 5 deletions

View File

@ -8,7 +8,6 @@ export const AutoComplete = (props) => {
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const { fieldNames } = fieldSchema['x-component-props']; const { fieldNames } = fieldSchema['x-component-props'];
const fieldFilter = fieldSchema['x-component-props']['params']; const fieldFilter = fieldSchema['x-component-props']['params'];
const filter = fieldFilter ? JSON.stringify(fieldFilter.filter) : {};
const [defultValue, setDefultValue] = useState([]); const [defultValue, setDefultValue] = useState([]);
const api = useAPIClient(); const api = useAPIClient();
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
@ -24,7 +23,7 @@ export const AutoComplete = (props) => {
}, },
}); });
changLable(defultOptions?.data?.data); changLable(defultOptions?.data?.data);
}, [filter]); }, [fieldFilter?.filter]);
useEffect(() => { useEffect(() => {
changLable(defultValue); changLable(defultValue);
@ -45,7 +44,7 @@ export const AutoComplete = (props) => {
} }
const onSearch = (data) => { const onSearch = (data) => {
if (data) { if (data) {
const searchValue = defultValue.filter((item) => item[fieldNames.label].includes(data)); const searchValue = defultValue.filter((item) => item.label.includes(data));
if (searchValue.length) { if (searchValue.length) {
setOptions(searchValue); setOptions(searchValue);
} else { } else {

View File

@ -26,7 +26,6 @@ const ObjectSelect = (props: Props) => {
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 api = useAPIClient(); const api = useAPIClient();
useAsyncEffect(async () => { useAsyncEffect(async () => {
if (collectionName) { if (collectionName) {
@ -39,7 +38,7 @@ const ObjectSelect = (props: Props) => {
}); });
setDefOptions(defValue?.data?.data); setDefOptions(defValue?.data?.data);
} }
}, [filter]); }, [filterField?.filter]);
const toValue = (v: any) => { const toValue = (v: any) => {
if (isEmptyObject(v)) { if (isEmptyObject(v)) {
return; return;