/** * @author luohq * @date 2022/11/7 10:32 AM * @description 多值框组件接口定义 */ import { ReactNode } from 'react'; import { TextFieldProps, SelectProps, SwitchProps, InputNumberProps, InputLangProps, ComboSelectProps, DatePickerProps } from '../index'; import { LabelProps } from "../Label"; import { TooltipProps } from "../Tooltip"; /**组件类型:输入框,下拉框,开关,数字输入框,国际化输入框,日期框,时间选择框,组合选择器,自定义组件*/ export type IInputType = 'TextField' | 'Select' | 'Switch' | 'InputNumber' | 'InputLang' | 'ComboSelect' | 'DatePicker' | 'custom'; /** 配置项*/ export type IConfig = { /** 字段名,用于匹配*/ name?: string; /** 组件类型*/ inputType?: IInputType; /** 渲染自定义组件*/ customRender?: (name: string, rowIndex: number, valueList: IValueList[], errors?: IErrors[]) => ReactNode; /** 禁用置灰组件*/ isDisabled?: boolean | ((rowIndex: number, name: string, valueList?: IValueList) => boolean); /** 固定字段,不需要显示在筛选器中的需要设置为true, 若不设置无法显示表单*/ isFixed?: boolean; /** 用于switch*/ text?: ReactNode | ((rowIndex: number, name: string, valueList: IValueList[]) => ReactNode); /** 是否必填*/ required?: boolean; /** 下拉列表数据,若某一列的每一行的下拉列表数据一致, 则只需传入数组,若需要自定义任意下拉列表数据,则传入函数*/ list?: ((rowIndex: number, id: string, name: string, valueList: IValueList[]) => any[]) | any[]; /** 样式 */ style?: React.CSSProperties; /** 标题样式 */ labelProps?: LabelProps; /** 组件其他样式,返回每个组件的样式 */ otherProps?: (rowIndex: number, name: string, valueList?: IValueList) => any; /** 其他*/ [name: string]: any; } & (TextFieldProps | SelectProps | SwitchProps | InputNumberProps | InputLangProps | ComboSelectProps | DatePickerProps); /** 操作按钮配置项 */ export interface IOperationButton { /** 按钮标识 */ key: string; /** 按钮图标 */ icon?: ReactNode; /** 按钮文本 */ text?: string; /** 是否禁用 */ disabled?: boolean | ((rowIndex: number, item: IValueList, valueList: IValueList[]) => boolean); /** 点击事件 */ onClick: (rowIndex: number, item: IValueList, valueList: IValueList[]) => void; /** 自定义渲染 */ render?: (rowIndex: number, item: IValueList, valueList: IValueList[]) => ReactNode; /** 样式 */ className?: string; /** 提示 */ tooltip?: TooltipProps; /** 排序位置: * 0 - 插入到删除按钮之前 * 1 - 插入到删除按钮之后,排序按钮之前(如果有排序按钮) * 2 - 插入到排序按钮之后(如果有排序按钮),否则删除按钮之后 * 3+ - 默认放在最后 */ order?: number; } /** value集合*/ export interface IValueList { /** 每行value值集合, name映射configItem中的name*/ [name: string]: any; } export interface IErrors { /** 每行错误集合,name映射configItem中的name*/ [name: string]: any; } export interface ICurrentItem { /** 表单名*/ name?: string; /** 表单值*/ value?: any; /** 表单所处下标*/ rowIndex?: number; [name: string]: any; } /** 过滤回调出参*/ export interface IFilterParams { /** 当前过滤操作项*/ name?: string; /** 是否选中*/ checkedVal?: string[]; /** 更新后的valueList*/ valueList?: IValueList[]; /** 更新后的错误信息*/ errors?: IErrors[]; } /** 主体接口定义*/ export interface IMultiValueProps { /** 指定每行key */ rowKey?: string; /** * 组件配置项 */ config?: IConfig[]; /** * 筛选配置 */ filterConfig?: IConfig[]; /** * @desc 回调 * @param valueList 整个value值集合 * @param currentItem 当前操作表单项 * */ onChange?: (valueList: IValueList[], currentItem?: ICurrentItem) => void; /** * @desc 新增 * @param valueList 新增前valueList值集合 * @param errors 新增后错误集合 * */ onAdd?: (valueList: IValueList[], errors: IErrors[]) => void; /** * 自定义删除 * */ deleteRender?: (index: number, item: IValueList, valueList: IValueList[]) => ReactNode; /** * @desc 删除, * @param valueList 删除后整个valueList值集合 * @param deleteItem 删除项 */ onDelete?: (valueList: IValueList[], errors: IErrors[]) => void; /** * @desc 筛选函数 * @param name 当前筛选项的name * @param checked 是否选中, true选中, false反选 * @param valueList 筛选后的value * */ onFilter?: (data: IFilterParams) => void; /** * @desc 排序 * @param newValueList * @param swapIds 交换顺序的两个下标 * */ onSort?: (newValueList: IValueList[], swapIds?: number[]) => void; /** * @desc 筛选值的集合 * */ checkedValue?: string[]; /** * 表单value集合 */ valueList?: IValueList[]; /** * 表单错误集合 */ errors?: IErrors[]; /** * 是否需要支持排序,默认不支持 */ isSort?: boolean; /** * 是否支持筛选组件,默认不支持 */ isFilter?: boolean; /** * 标题模式 none 不显示, single 只有第一列才显示, all 每列都显示 */ titleMode?: 'none' | 'single' | 'all'; /** * 禁用新增标识 */ disabledAdd?: boolean; /** * 禁用提示 */ disabledAddTooltip?: TooltipProps; /** * 列之间icon * */ icon?: ReactNode; /** * 隐藏删除icon, string[] 指定某些行隐藏删除按钮, 入参为valueList中的id集合 * */ deleteDisable?: string[]; /** * 单个标题名称 * */ singleTitle?: { label: ReactNode; required: boolean; }; /** * 自定义类名 */ className?: string; /** * 新增项行表单的默认值 */ initValue?: Record; /** * 筛选器弹出框样式 */ popoverClassName?: string; /** * 是否保持最后一条 * */ keepLastItem?: boolean; /** * 自定义操作按钮,支持每行配置多个操作按钮 */ operationButtons?: IOperationButton[]; }