zy-react-library/components/Select/Basic/index.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-11-06 09:38:23 +08:00
import { Select } from "antd";
2025-11-06 16:02:51 +08:00
import { getLabelName } from "../../../utils";
2025-11-06 09:38:23 +08:00
/**
* 基础下拉组件不建议直接使用此组件二次继承使用
*/
function BasicSelect(props) {
const {
2025-11-06 16:02:51 +08:00
onGetLabel,
2025-11-06 09:38:23 +08:00
placeholder = "",
data = [],
nameKey = "name",
idKey = "id",
...restProps
} = props;
2025-11-06 16:02:51 +08:00
// 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);
}
2025-11-06 09:38:23 +08:00
return (
2025-11-06 16:02:51 +08:00
// <Select placeholder={`请选择${placeholder}`} showSearch allowClear onClear={handleClear} onSelect={handleSelect} {...restProps}>
<Select placeholder={`请选择${placeholder}`} showSearch allowClear onChange={handleChange} {...restProps}>
2025-11-06 09:38:23 +08:00
{data.map((item) => {
const value = item[idKey];
const label = item[nameKey];
return (
<Select.Option key={value} value={value}>
{label}
</Select.Option>
);
})}
</Select>
);
}
BasicSelect.displayName = "BasicSelect";
export default BasicSelect;