import { ReactNode } from 'react'; import { Service, Options, Result } from 'ahooks/lib/useRequest/src/types'; import type { TreeSelectProps } from 'antd'; import type { ProFormOtherType } from '../ProForm/propsType'; /** * 树数据结构 * @description 定义树节点的数据结构 */ export interface ProTreeDataType { /** * 节点标签 * @description 显示的节点文本 * @default undefined */ label?: string; /** * 节点值 * @description 节点的唯一标识 * @default undefined */ value?: string; /** * 子节点 * @description 当前节点的子节点数组 * @default undefined */ children?: ProTreeDataType[]; /** * 自定义属性 * @description 可添加任意其他属性 * @default undefined */ [key: string]: any; } type ProTreeValueType = string | number; type ProTreeKeyType = string | number; /** * 字段名称映射 * @description 定义树节点字段的映射关系 */ export interface ProTreeFieldNamesType { /** * 标签字段名 * @description 指定节点标签的属性名 * @default 'label' */ label?: string; /** * 值字段名 * @description 指定节点值的属性名 * @default 'value' */ value: string; /** * 子节点字段名 * @description 指定子节点的属性名 * @default 'children' */ children?: string; } /** * ProTree组件属性 * @description ProTree组件的主要配置属性 */ export interface ProTreeType extends ProTreeSelectType { /** * 树标题 * @description 树组件的标题 * @default undefined */ title?: string; /** * 选中值 * @description 当前选中的节点值 * @default undefined */ value?: ProTreeValueType | string[]; /** * 选中值 * @description 选中的树节点value * @default undefined */ checkedValues?: any; /** * 是否展示展开全部按钮 * @description 是否展示展开全部按钮,控制展开功能的显示 * @default false */ showExpand?: boolean; /** * 字段名称映射 * @description 自定义节点的字段名称映射 * @default { label: 'label', value: 'value', children: 'children' } */ fieldNames?: ProTreeFieldNamesType; /** * 是否展开下拉菜单 * @description 控制下拉菜单是否展开 * @default undefined */ open?: boolean; /** * 展示类型 * @description 组件的展示模式 * @default 'treeSelect' */ mode?: 'tree' | 'list' | 'treeSelect'; /** * 值包含标签 * @description 开启后提交给后端的格式为 [{ label:xx, value: ""}] * @default false */ labelInValue?: boolean; /** * 查看模式 * @description 是否为查看模式,与 disabled 效果相同 * @default false */ isView?: boolean; /** * 枚举代码 * @description 使用 ProEnum 的数据源 * @default undefined */ code?: string; /** * 显示代码名称 * @description 是否展示 code-label 形式 * @default false */ showCodeName?: boolean; /** * 显示搜索框 * @description 是否展示搜索输入框 * @default false */ showSearch?: boolean; /** * 数据源 * @description 静态数据源 * @default [] */ dataSource?: ProTreeDataType[]; /** * 是否禁用 * @description 禁用整个组件 * @default false */ disabled?: boolean; /** * 禁用模式 * @description 复选模式下只读是否全显示节点,hide--隐藏未勾选 * @default undefined */ disabledMode?: string; /** * 全选值 * @description 全选时传给后端的标识 * @default undefined */ allValue?: string | number; /** * 占位提示 * @description 提示语,treeSelect时使用 * @default undefined */ placeholder?: string; /** * 严格选择 * @description 父子节点选中状态不再关联 * @default false */ checkStrictly?: boolean; /** * 页脚 * @description 树底部操作项 * @default undefined */ footer?: ReactNode; /** * 树高度 * @description 树容器高度 * @default undefined */ height?: string; /** * 显示省略号 * @description 树节点文本超长是否展示省略号 * @default false */ showEllipse?: boolean; /** * 省略宽度 * @description 树节点文本宽度 * @default undefined */ ellipseWidth?: string; /** * 值变化回调 * @description value 改变的回调 * @default undefined */ onChange?: (value: any, labelList?: ReactNode[], extra?: any) => void; /** * 选择回调 * @description 点击树节点触发 * @default undefined */ onSelect?: (values: string[] | ProTreeValueType, info?: any) => any; /** * 勾选回调 * @description 复选情况下点击checkbox触发,参照antd * @default undefined */ onCheck?: (values: string[] | ProTreeValueType, info?: any) => any; /** * 展开回调 * @description 展开/收起节点时触发 * @default undefined */ onExpand?: (newExpandedKeys: React.Key[], nextPara: { expanded: boolean; node: ProTreeDataOptionType; nativeEvent: PointerEvent; }) => void; /** * 自定义渲染 * @description 自定义展示内容 * @default undefined */ optionRender?: (item: any, searchStr: string) => string | ReactNode; /** * 响应数据转换 * @description 对后台返回数据进行格式化 * @default undefined */ transformResponse?: (data: any) => ProTreeDataType[]; /** * 标签集合 * @description 标签集合 * @default undefined */ tags?: string[]; /** * 其他属性 * @description 表单其他配置属性 * @default undefined */ otherProps?: ProFormOtherType; /** * 远程请求 * @description 远程请求接口配置 * @default undefined */ useRequest?: { service: Service; options?: Options; }; /** * 菜单配置 * @description 自定义配置操作按钮函数,返回react node节点 * @default undefined */ menu?: (key: ProTreeKeyType, item?: any) => ReactNode[]; /** * 是否加载中 * @description 点击树节点是否开启loading遮罩 * @default false */ loading?: boolean; /** * 显示连接线 * @description 是否显示连接线 * @default false */ showLine?: boolean; /** * 自定义类名 * @description 自定义CSS类名 * @default undefined */ className?: string; /** * 是否多选 * @description 是否支持多选 * @default false */ multiple?: boolean; /** * 自动展开父节点 * @description 是否自动展开父节点 * @default true */ autoExpandParent?: boolean; /** * 可勾选 * @description 节点前添加 Checkbox 复选框 * @default false */ checkable?: boolean; /** * 可勾选 * @description 是否显示 checkbox * @default false */ treeCheckable?: boolean; /** * 默认展开所有 * @description 默认展开所有树节点 * @default false */ defaultExpandAll?: boolean; /** * 默认展开父节点 * @description 默认展开父节点 * @default true */ defaultExpandParent?: boolean; /** * 默认展开的节点 * @description 默认展开指定的树节点 * @default [] */ defaultExpandedKeys?: ProTreeKeyType[]; /** * 展开的节点 * @description (受控)展开指定的树节点 * @default undefined */ expandedKeys?: ProTreeKeyType[]; /** * 选中的节点 * @description (受控)选中复选框的树节点 * @default undefined */ checkedKeys?: ProTreeKeyType[] | { checked: ProTreeKeyType[]; halfChecked: ProTreeKeyType[]; }; /** * 默认选中的节点 * @description 默认选中复选框的树节点 * @default [] */ defaultCheckedKeys?: ProTreeKeyType[]; /** * 选中的节点 * @description (受控)设置选中的树节点 * @default undefined */ selectedKeys?: ProTreeKeyType[]; /** * 默认选中的节点 * @description 默认选中的树节点 * @default [] */ defaultSelectedKeys?: ProTreeKeyType[]; /** * 可选中 * @description 是否可以选中 * @default true */ selectable?: boolean; /** * 已加载的节点 * @description 已经加载的节点,配合 loadData 使用 * @default [] */ loadedKeys?: ProTreeKeyType[]; /** * 自定义样式 * @description 自定义内联样式 * @default undefined */ style?: any; /** * 显示图标 * @description 是否显示节点图标 * @default false */ showIcon?: boolean; /** * 前缀类名 * @description 自定义类名前缀 * @default undefined */ prefixCls?: string; /** * 子节点 * @description 子元素内容 * @default undefined */ children?: any; /** * 节点占满一行 * @description 是否节点占据一行 * @default false */ blockNode?: boolean; /** * 选中节点键值 * @description 点中的树节点key,表单模式下value有值该配置优先级降低 * @default undefined */ selectedKey?: string | number | undefined; } /** * 数据属性 * @description 定义节点的基本数据属性 */ export interface ProTreeDataPropsType { /** * 节点标签 * @description 显示的节点文本 * @default undefined */ label?: string; /** * 节点值 * @description 节点的唯一标识 * @default undefined */ value?: string; /** * 是否禁用 * @description 是否禁用节点 * @default false */ disabled?: boolean; /** * 禁用复选框 * @description 是否禁用复选框 * @default false */ disableCheckbox?: boolean; /** * 是否可选 * @description 是否可以选中 * @default true */ selectable?: boolean; /** * 是否可勾选 * @description 是否可以勾选 * @default undefined */ checkable?: boolean; /** * 标题 * @description 节点标题 * @default undefined */ title?: string; } /** * 数据选项 * @description 扩展的数据选项接口 */ export interface ProTreeDataOptionType { /** * 节点标签 * @description 显示的节点文本 * @default undefined */ label?: string; /** * 节点值 * @description 节点的唯一标识 * @default undefined */ value?: string; /** * 是否禁用 * @description 是否禁用节点 * @default false */ disabled?: boolean; /** * 禁用复选框 * @description 是否禁用复选框 * @default false */ disableCheckbox?: boolean; /** * 是否可选 * @description 是否可以选中 * @default true */ selectable?: boolean; /** * 是否可勾选 * @description 是否可以勾选 * @default undefined */ checkable?: boolean; /** * 子节点 * @description 当前节点的子节点数组 * @default undefined */ children?: ProTreeDataPropsType[]; /** * 标题 * @description 节点标题 * @default undefined */ title?: string; /** * 自定义属性 * @description 可添加任意其他属性 * @default undefined */ [key: string]: any; } /** * 基础选项类型 * @description 基础选项类型定义 */ export interface ProTreeBaseOptionType { /** * 是否禁用 * @description 是否禁用节点 * @default false */ disabled?: boolean; /** * 是否可勾选 * @description 是否可以勾选 * @default undefined */ checkable?: boolean; /** * 禁用复选框 * @description 是否禁用复选框 * @default false */ disableCheckbox?: boolean; /** * 子节点 * @description 当前节点的子节点数组 * @default undefined */ children?: ProTreeBaseOptionType[]; /** * 自定义属性 * @description 可添加任意其他属性 * @default undefined */ [name: string]: any; } /** * 默认选项类型 * @description 扩展基础选项类型的默认选项类型 */ export interface ProTreeDefaultOptionType extends ProTreeBaseOptionType { /** * 节点值 * @description 节点的值 * @default undefined */ value?: any; /** * 标题 * @description 节点的标题 * @default undefined */ title?: ReactNode; /** * 标签 * @description 节点的显示标签 * @default undefined */ label?: ReactNode; /** * 键值 * @description 节点的键值 * @default undefined */ key?: ProTreeKeyType; /** * 子节点 * @description 子节点数组 * @default undefined */ children?: ProTreeDefaultOptionType[]; } /** * 树选择属性 * @description 树选择组件的配置属性 */ export interface ProTreeSelectType extends Omit { /** * 是否查看模式 * @description 是否为查看模式 * @default false */ isView?: boolean; /** * 过滤树节点 * @description 是否根据输入项进行筛选 * @default true */ filterTreeNode?: boolean; /** * 树节点过滤属性 * @description 输入项过滤对应的 treeNode 属性 * @default 'label' */ treeNodeFilterProp?: string; /** * 默认展开所有 * @description 是否展开所有树 * @default false */ treeDefaultExpandAll?: boolean; /** * 树可选择 * @description 是否支持复选、多选 * @default true */ treeCheckable?: boolean; /** * 宽度 * @description 输入框宽度 * @default '100%' */ width?: any; /** * 枚举代码 * @description 从localStorage里面根据此code取枚举值 * @default undefined */ code?: string; /** * 数据源 * @description 选择项数据源 * @default [] */ dataSource?: ProTreeDataOptionType[]; /** * 默认禁用值 * @description 兼容2.0版本、3.0使用view模式,查看模式值 * @default undefined */ defaultDisableValue?: string; /** * 响应数据转换 * @description 格式化接口响应数据 * @default undefined */ transformResponse?: (data: any) => ProTreeDataOptionType[]; /** * 是否显示提示 * @description 是否展示tooltip,当label特别长的时候使用 * @default false */ tooltip?: boolean; /** * 显示代码名称 * @description 是否展示code-label形式 * @default false */ showCodeName?: boolean; /** * 其他属性 * @description 集成表单form的属性 * @default undefined */ otherProps?: ProFormOtherType; /** * 搜索回调 * @description 搜索时的回调函数 * @default undefined */ onSearch?: (value: string, useRequest: Result) => void; /** * 远程请求 * @description 远程请求接口配置 * @default undefined */ useRequest?: { service: Service; options?: Options; }; /** * 可勾选 * @description 是否可以勾选 * @default undefined */ checkable?: boolean; } /** * ProSelect操作 * @description ProSelect组件的操作接口 */ export interface ProTreeSelectActionType { /** * useRequest引用 * @description 获取发生请求的useRequest的ref * @default undefined */ useRequestRef: Result; } /** * 树节点数据 * @description 树节点的数据结构 */ export interface ProTreeNodeDataType extends ProTreeDataOptionType { /** * 标题 * @description 节点的标题 * @default undefined */ title: string; /** * 值 * @description 节点的值 * @default undefined */ value: string; /** * 子节点 * @description 子节点数组 * @default undefined */ children?: ProTreeNodeDataType[]; /** * 图标 * @description 节点的图标 * @default undefined */ icon?: ReactNode; /** * 隐藏节点类名 * @description 隐藏节点的类名 * @default undefined */ hideNodeClass?: string; } /** * 树选择表单属性 * @description 树选择表单的配置属性 */ export interface ProTreeSelectFormType { /** * 类型 * @description 表单项类型 * @default undefined */ type?: string; /** * 标签 * @description 表单项标签 * @default undefined */ label?: string; /** * 名称 * @description 表单项字段名 * @default undefined */ name?: string; /** * 字段属性 * @description 树选择组件的属性配置 * @default undefined */ fieldProps?: ProTreeSelectType; /** * 自定义属性 * @description 其他自定义属性 * @default undefined */ [key: string]: any; } /** * 响应数据 * @description API响应数据结构 */ export interface ProTreeResponseDataType { /** * 状态码 * @description 接口返回的状态码 * @default undefined */ status: number; /** * 消息 * @description 接口返回的消息 * @default undefined */ message: string; /** * 数据 * @description 接口返回的数据 * @default undefined */ data: any; /** * 是否成功 * @description 请求是否成功 * @default undefined */ success?: boolean; /** * 代码 * @description 业务代码 * @default undefined */ code?: number; } export {};