优化Select
parent
1107ecee47
commit
47b4f23b6d
|
|
@ -14,7 +14,7 @@ export interface BasicSelectProps extends SelectProps {
|
||||||
/** 占位符 */
|
/** 占位符 */
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
/** 获取 label */
|
/** 获取 label */
|
||||||
onGetLabel?: (label: string) => void;
|
onGetLabel?: (label: string | string[]) => void;
|
||||||
/** 获取数据 */
|
/** 获取数据 */
|
||||||
onGetData?: (data: Record<string, any>[]) => void;
|
onGetData?: (data: Record<string, any>[]) => void;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,24 @@ function BasicSelect(props) {
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const handleChange = (event, option) => {
|
const handleChange = (event, option) => {
|
||||||
|
if (Array.isArray(event)) {
|
||||||
|
if (event.length > 0) {
|
||||||
|
const name = [];
|
||||||
|
event.forEach((item) => {
|
||||||
|
name.push(getLabelName({ list: data, status: item, idKey, nameKey }));
|
||||||
|
});
|
||||||
|
onGetLabel?.(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
onGetLabel?.([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (event)
|
if (event)
|
||||||
onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
|
onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
|
||||||
else
|
else
|
||||||
onGetLabel?.("");
|
onGetLabel?.("");
|
||||||
|
}
|
||||||
onChange?.(event, option);
|
onChange?.(event, option);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue