import React from 'react'; import cx from 'classnames'; import { OptionsControl, OptionsControlProps, Option, FormOptionsControl } from './Options'; import Select from '../../components/Select'; import find from 'lodash/find'; import debouce from 'lodash/debounce'; import {Api} from '../../types'; import {isEffectiveApi} from '../../utils/api'; import {isEmpty, createObject, autobind} from '../../utils/helper'; import {dataMapping} from '../../utils/tpl-builtin'; import {SchemaApi} from '../../Schema'; /** * Select 下拉选择框。 * 文档:https://baidu.gitee.io/amis/docs/components/form/select */ export interface SelectControlSchema extends FormOptionsControl { type: 'select' | 'multi-select'; /** * 自动完成 API,当输入部分文字的时候,会将这些文字通过 ${term} 可以取到,发送给接口。 * 接口可以返回匹配到的选项,帮助用户输入。 */ autoComplete?: SchemaApi; /** * 是否可以搜索值 */ searchable?: boolean; /** * 可以自定义菜单展示。 */ menuTpl?: string; } export interface SelectProps extends OptionsControlProps { autoComplete?: Api; searchable?: boolean; defaultOpen?: boolean; } export default class SelectControl extends React.Component { static defaultProps: Partial = { clearable: false, searchable: false, multiple: false }; input: any; unHook: Function; lazyloadRemote: Function; constructor(props: SelectProps) { super(props); this.changeValue = this.changeValue.bind(this); this.lazyloadRemote = debouce(this.loadRemote.bind(this), 250, { trailing: true, leading: false }); this.inputRef = this.inputRef.bind(this); } componentWillUnmount() { this.unHook && this.unHook(); } inputRef(ref: any) { this.input = ref; } foucs() { this.input && this.input.focus(); } changeValue(value: Option | Array