优化BasicSelect

master
LiuJiaNan 2025-12-16 14:53:35 +08:00
parent 0a652c8ddb
commit 8e2abb8ba3
2 changed files with 7 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import type { SelectProps } from "antd/es/select";
import type { FC } from "react";
import type { FC, ReactNode } from "react";
/**
*
@ -19,11 +19,13 @@ export interface BasicSelectProps extends SelectProps {
onGetOption?: (option: Record<string, any> | Record<string, any>[]) => void;
/** 获取数据 */
onGetData?: (data: Record<string, any>[]) => void;
/** 自定义 label 的渲染函数 */
labelRender?: (item: Record<string, any>) => ReactNode;
}
/**
* 使使
*/
declare const BasicSelectTree: FC<BasicSelectProps>;
declare const BasicSelect: FC<BasicSelectProps>;
export default BasicSelectTree;
export default BasicSelect;

View File

@ -14,6 +14,7 @@ function BasicSelect(props) {
data = [],
nameKey = "name",
idKey = "id",
labelRender,
...restProps
} = props;
@ -59,7 +60,7 @@ function BasicSelect(props) {
<Select placeholder={`请选择${placeholder}`} showSearch allowClear optionFilterProp="children" onChange={handleChange} {...restProps}>
{data.map((item) => {
const value = item[idKey];
const label = item[nameKey];
const label = labelRender ? labelRender(item) : item[nameKey];
return (
<Select.Option key={value} value={value}>
{label}