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:31:49 +08:00
|
|
|
|
onChange,
|
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:31:49 +08:00
|
|
|
|
const handleChange = (event, option) => {
|
2025-11-06 16:02:51 +08:00
|
|
|
|
if (event)
|
|
|
|
|
|
onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
|
|
|
|
|
|
else
|
2025-11-06 16:28:49 +08:00
|
|
|
|
onGetLabel?.("");
|
2025-11-06 16:31:49 +08:00
|
|
|
|
onChange?.(event, option);
|
2025-11-06 16:28:49 +08:00
|
|
|
|
};
|
2025-11-06 16:02:51 +08:00
|
|
|
|
|
2025-11-06 09:38:23 +08:00
|
|
|
|
return (
|
2025-11-06 16:02:51 +08:00
|
|
|
|
<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;
|