优化Select

master
LiuJiaNan 2025-11-06 16:02:51 +08:00
parent c12cb39ac8
commit 8907dbd186
1 changed files with 19 additions and 1 deletions

View File

@ -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];