优化BasicSelect
parent
0a652c8ddb
commit
8e2abb8ba3
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Reference in New Issue