Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | /* eslint-disable */ import React from "react"; import { PureInput } from "./PureInput"; import { SingleValueSelect } from "./SingleValueSelect"; import { MultipleValueSelect } from "./MultipleValueSelect"; import { Loading } from "./Loading"; import { Empty } from "./Empty"; export interface ValueSelectProps { /** * 值选择组件类型,用于选择不同组件 */ type: string | [string, { [key: string]: any }]; /** * 值选择组件可选值的集合 */ values?: any[] | Function; /** * 当前输入值 */ inputValue?: string; onChange?: (value: any) => void; onSelect?: (value: any) => void; onCancel?: () => void; offset: number; maxHeight: number; } export class ValueSelect extends React.Component<ValueSelectProps, any> { mount = false; state = { values: this.props.values, }; componentDidMount() { this.mount = true; const propsValues = this.props.values; if (typeof propsValues === "function") { const res = propsValues(); // Promise if (res && res.then) { res.then(values => { this.mount && this.setState({ values }); }); } else { this.mount && this.setState({ values: res }); } } } componentWillUnmount() { this.mount = false; } handleKeyDown = (keyCode: number): boolean => { if (this["select"] && this["select"].handleKeyDown) { return this["select"].handleKeyDown(keyCode); } return true; }; // handleKeyUp = (keyCode: number): boolean => { // if (this['select'] && this['select'].handleKeyUp) { // return this['select'].handleKeyUp(keyCode); // } // return true; // } render() { const { values } = this.state; const { type, inputValue, onChange, onSelect, onCancel, offset, maxHeight, } = this.props; const props = { values, inputValue, onChange, onSelect, onCancel, offset, maxHeight, }; let componentName = type; let componentOptions = {}; if (Array.isArray(type)) { [componentName, componentOptions = {}] = type; } switch (componentName) { case "input": return ( <PureInput ref={select => (this["select"] = select)} {...props} /> ); case "single": if (!Array.isArray(values)) { return <Loading offset={offset} />; } if (!values.length) { return ( <Empty {...componentOptions} offset={offset} onCancel={onCancel} /> ); } return ( <SingleValueSelect {...props} ref={select => (this["select"] = select)} values={values} /> ); case "multiple": if (!Array.isArray(values)) { return <Loading offset={offset} />; } if (!values.length) { return ( <Empty {...componentOptions} offset={offset} onCancel={onCancel} /> ); } return ( <MultipleValueSelect {...props} {...componentOptions} ref={select => (this["select"] = select)} values={values} /> ); } return null; } } |