跳到主要内容

BusinessTreeSelect - 业务树下拉

与 BusinessSelect 功能一致,区别是 BusinessTreeSelect 处理的是 树形 数据。

只需一次定义, 全页面都能方便使用。

下面是组件的初始化示例:

import { BusinessTreeSelectBuilder } from 'react-admin-kit';

// 定义 type 类型, 方便在使用时有代码提示
type TreeSelectType = 'org';

const BusinessTreeSelect = BusinessTreeSelectBuilder<TreeSelectType>(
{
apis: [
{
type: 'org',
api: queryOrgFunction,
},
],
})

// 在页面中使用
<BusinessTreeSelect type="org" />;

由于处理的是树形数据,因此树形组件没有分页功能。请求接口返回的格式直接为一个对象数组,组件默认读取 name 作为文本显示,id 作为下拉取值。

基本的使用方法

BusinessTreeSelectAntd TreeSelect 的封装,因此组件可以接受 Antd TreeSelect 的所有属性。

级联

  • 该例子中部门会根据公司级联。

  • 可以使用 queryParams 传参数给请求接口。

清除缓存

使用clearTreeSelectCache(type: string)方法清除缓存。type 不传时清除所有类型的缓存。

onLoad 事件

当下拉数据加载完成后会触发 onLoad 事件。这个事件对于某些场景非常有用,例如可以用它实现默认选中第一条数据。

API

BusinessTreeSelectBuilder

属性名描述类型默认值
apis定义所有的业务下拉;[]
defaultProps默认属性;{}

ApiType

属性名描述类型默认值
api获取下拉数据的接口(params: { [key: string]: any; }) => Promise<any>'-'
type树形业务下拉的类型string'-'
defaultProps默认属性, 比 Builder 上的优先级更高'-'

BusinessTreeSelect

BusinessTreeSelect 类型是 BusinessTreeSelectSelfTypeTreeSelectProps 的结合。

BusinessTreeSelectSelfType

属性名描述类型默认值
type业务树下拉类型;string(必选)
nodeDisabled禁用某节点;((node: any) => boolean)--
queryParams查询接口的参数. 用法见示例Record<string, any>--
noCache不缓存数据booleanfalse
onLoad下拉数据加载完成后的回调;((options: any) => void)-