import { ReactNode, CSSProperties } from 'react'; import { Service, Options } from 'ahooks/lib/useRequest/src/types'; import type { ProFormOtherType } from '../ProForm/propsType'; /** * 树数据结构 * @description 定义树节点的数据结构 */ export interface ProTreeModalDataType { /** * 节点标签 * @description 显示的节点文本 * @default undefined */ label: string; /** * 节点值 * @description 节点的唯一标识 * @default undefined */ value: string; /** * 子节点 * @description 当前节点的子节点数组 * @default undefined */ children?: ProTreeModalDataType[]; /** * 是否禁用 * @description 禁用不可操作 * @default false */ disabled?: boolean; /** * 固定位置 * @description 处理固定场景 * @default undefined */ fixed?: 'left' | 'right'; /** * 是否可勾选 * @description 是否可以勾选复选框 * @default undefined */ checkable?: boolean; /** * 自定义属性 * @description 可添加任意其他属性 * @default undefined */ [key: string]: any; } /** * 值类型 * @description 组件接受的值类型 */ export type ProTreeModalValueType = string | number; /** * ProTreeModal操作对象 * @description ProTreeModal组件的操作接口 */ export interface ProTreeModalActionType { /** * 值变更方法 * @description 用于获取当前选中的值数组 * @default undefined */ onChange: () => ProTreeModalValueType[]; } /** * 字段名称映射 * @description 定义树节点字段的映射关系 */ export interface ProTreeModalFieldNamesType { /** * 标签字段名 * @description 指定节点标签的属性名 * @default 'label' */ label: string; /** * 值字段名 * @description 指定节点值的属性名 * @default 'value' */ value: string; /** * 子节点字段名 * @description 指定子节点的属性名 * @default 'children' */ children?: string; } /** * 树弹框模式 * @description 弹框展示模式类型 */ export type ProTreeModalModeType = 'tree' | 'list' | 'Cascader' | 'Tree' | 'List'; /** * 指定模式属性 * @description 指定模式下的配置属性 */ export interface ProTreeModalAppointType { /** * 是否禁用 * @description 禁用指定项或全部项 * @default undefined */ disabled?: boolean | boolean[]; } /** * ProTreeModal组件属性 * @description ProTreeModal组件的主要配置属性 */ export interface ProTreeModalType { /** * 选中值 * @description 当前选中的节点值 * @default undefined */ value?: ProTreeModalValueType | string[]; /** * 字段名称映射 * @description 自定义节点的字段名称映射 * @default { label: 'label', value: 'value', children: 'children' } */ fieldNames?: ProTreeModalFieldNamesType; /** * 是否展开弹框 * @description 自定义控制modal的显示,此时没有trigger * @default undefined */ open?: boolean; /** * 列表布局 * @description 列表模式下一行放几个 * @default 24 */ span?: number; /** * 展示类型 * @description 展示模式,list为列表展示形式,tree为树形展示,appoint为指定模式 * @default 'list' */ mode?: ProTreeModalModeType; /** * 是否指定模式 * @description 是否开启指定模式,开启后展示形式会不同 * @default false */ appoint?: boolean; /** * 指定模式参数 * @description 指定模式下传递的额外参数 * @default undefined */ appointProps?: ProTreeModalAppointType; /** * 值包含标签 * @description 开启后提交给后端的格式为 [{ label:xx, value: ""}] * @default false */ labelInValue?: boolean; /** * 查看模式 * @description 是否为查看模式,与disabled效果相同 * @default false */ isView?: boolean; /** * 枚举代码 * @description 使用ProEnum的数据源 * @default undefined */ code?: string; /** * 触发元素 * @description 触发弹框展开的容器 * @default undefined */ trigger?: string | ReactNode; /** * 显示代码名称 * @description 是否展示code-label形式 * @default false */ showCodeName?: boolean; /** * 数据源 * @description 静态数据源 * @default [] */ dataSource?: ProTreeModalDataType[]; /** * 最小选择个数 * @description 设置最小选择个数限制 * @default undefined */ min?: number; /** * 最大选择个数 * @description 设置最大选择个数限制 * @default undefined */ max?: number; /** * 超限提示 * @description 超过最大数量的提示信息,如'最多为{max}个' * @default undefined */ maxMessage?: string; /** * 是否可拖拽 * @description 列表模式下已选择项是否可拖拽排序 * @default false */ draggable?: boolean; /** * 是否禁用 * @description 禁用整个组件 * @default false */ disabled?: any; /** * 弹框标题 * @description 弹框的标题文本 * @default undefined */ title?: string | ReactNode; /** * 全选值 * @description 全选时传给后端的标识 * @default undefined */ allValue?: string | number; /** * 占位提示 * @description 搜索框提示文本 * @default '请输入' */ placeholder?: string; /** * 严格选择 * @description 父子节点选中状态不再关联 * @default false */ checkStrictly?: boolean; /** * 触发器样式 * @description trigger元素的样式设置 * @default undefined */ style?: CSSProperties; /** * 标签集合 * @description 用于标记分类的标签集合 * @default undefined */ tags?: string[]; /** * 其他属性 * @description 表单其他配置属性 * @default undefined */ otherProps?: ProFormOtherType; /** * 远程请求 * @description 远程请求接口配置 * @default undefined */ useRequest?: { service?: Service; options?: Options; }; /** * 值变化回调 * @description value变化的回调函数 * @default undefined */ onChange?: (values: ProTreeModalValueType[] | ProTreeModalValueType) => void; /** * 自定义渲染 * @description 自定义选项内容渲染 * @default undefined */ optionRender?: (item: any, searchStr: string) => string | ReactNode; /** * 响应数据转换 * @description 对后台返回数据进行格式化 * @default undefined */ transformResponse?: (data: any) => ProTreeModalDataType[]; /** * 打开状态变化 * @description 弹框打开/关闭回调 * @default undefined */ openChange?: (open: boolean) => void; }