UNPKG

xph-form

Version:

This is a configurable form component that supports React

32 lines (31 loc) 1.29 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from "react"; import { AutoComplete } from "antd"; import { useApiComonentCache } from "../../hooks"; const ApiAutoComplete = (apiAutoCompleteProps) => { console.log("render ApiAutoComplete"); const { api, params, immediate = true, isusewatch, onDropdownVisibleChange: onDropdownVisibleChangeProp, } = apiAutoCompleteProps; const isUseWatch = isusewatch === "true"; const [options, setOptions] = React.useState([]); const { getApiData: getApiOptions } = useApiComonentCache({ api, immediate, params, apiCallback: setOptions, isUseWatch, }); const onDropdownVisibleChange = (visible) => { if (visible) { /** 目前每次展开都会请求 */ !immediate && getApiOptions(); } onDropdownVisibleChangeProp && onDropdownVisibleChangeProp(visible); }; /** 把扩展的属性排除掉 */ const getAutoCompleteProps = () => { const { api, params, immediate, isusewatch, ...rest } = apiAutoCompleteProps; return rest; }; return (_jsx(AutoComplete, { ...getAutoCompleteProps(), options: options, onDropdownVisibleChange: onDropdownVisibleChange })); }; export default ApiAutoComplete;