优化Select
parent
c12cb39ac8
commit
8907dbd186
|
|
@ -1,10 +1,12 @@
|
||||||
import { Select } from "antd";
|
import { Select } from "antd";
|
||||||
|
import { getLabelName } from "../../../utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础下拉组件(不建议直接使用此组件,二次继承使用)
|
* 基础下拉组件(不建议直接使用此组件,二次继承使用)
|
||||||
*/
|
*/
|
||||||
function BasicSelect(props) {
|
function BasicSelect(props) {
|
||||||
const {
|
const {
|
||||||
|
onGetLabel,
|
||||||
placeholder = "",
|
placeholder = "",
|
||||||
data = [],
|
data = [],
|
||||||
nameKey = "name",
|
nameKey = "name",
|
||||||
|
|
@ -12,8 +14,24 @@ function BasicSelect(props) {
|
||||||
...restProps
|
...restProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
// const handleSelect = (event) => {
|
||||||
|
// onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// const handleClear = () => {
|
||||||
|
// onGetLabel?.(undefined);
|
||||||
|
// };
|
||||||
|
|
||||||
|
const handleChange = (event) => {
|
||||||
|
if (event)
|
||||||
|
onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
|
||||||
|
else
|
||||||
|
onGetLabel?.(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select placeholder={`请选择${placeholder}`} showSearch allowClear {...restProps}>
|
// <Select placeholder={`请选择${placeholder}`} showSearch allowClear onClear={handleClear} onSelect={handleSelect} {...restProps}>
|
||||||
|
<Select placeholder={`请选择${placeholder}`} showSearch allowClear onChange={handleChange} {...restProps}>
|
||||||
{data.map((item) => {
|
{data.map((item) => {
|
||||||
const value = item[idKey];
|
const value = item[idKey];
|
||||||
const label = item[nameKey];
|
const label = item[nameKey];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue