UNPKG

jamis

Version:

一种支持通过JSON配置方式生成页面的组件库

245 lines (244 loc) 7.98 kB
import type { ActionObject, Api, DispatchEventFn, OnEventProps, Option, RendererPropsData } from 'jamis-core'; import type { ActionSchema, DialogSchema, FormItemSchemaObject } from '../types'; import type { FormBaseControl, FormControlProps, FormItemBasicConfig } from './types'; export type { Option, Options, OptionValue } from 'jamis-core'; export type OptionsControlComponent = React.ComponentType<FormControlProps>; export interface FormOptionsControl extends FormBaseControl, OnEventProps { /** * 选项集合 */ options?: Array<Option> | string[] | PlainObject; /** * 可用来通过 API 拉取 options。 */ source?: Api; /** * 默认选择选项第一个值。 */ selectFirst?: boolean; /** * 用表达式来配置 source 接口初始要不要拉取 * * @deprecated 建议用 source 接口的 sendOn */ initFetchOn?: string; /** * 配置 source 接口初始拉不拉取。 * * @deprecated 建议用 source 接口的 sendOn */ initFetch?: boolean; /** * 是否为多选模式 */ multiple?: boolean; /** * 单选模式:当用户选中某个选项时,选项中的 value 将被作为该表单项的值提交,否则,整个选项对象都会作为该表单项的值提交。 * 多选模式:选中的多个选项的 `value` 会通过 `delimiter` 连接起来,否则直接将以数组的形式提交值。 */ joinValues?: boolean; /** * 分割符 */ delimiter?: string; /** * 开启后将选中的选项 value 的值封装为数组,作为当前表单项的值。 */ extractValue?: boolean; /** * 是否可清除。 */ clearable?: boolean; /** * 点清除按钮时,将表单项设置成当前配置的值。 * * @default '' */ resetValue?: any; /** * 延时加载的 API,当选项中有 defer: true 的选项时,点开会通过此接口扩充。 */ deferApi?: Api; createConfig?: ActionSchema; /** * 添加时调用的接口 * @deprecated 请使用`createConfig`来配置schema */ addApi?: Api; /** * 新增时的表单项。 * @deprecated 请使用`createConfig`来配置schema */ addControls?: FormItemSchemaObject[]; /** * 控制新增弹框设置项 * @deprecated 请使用`createConfig`来配置schema */ addDialog?: Partial<DialogSchema>; /** * 是否可以新增 * @deprecated 请使用`createConfig`来配置schema */ creatable?: boolean; /** * 新增提示 * @deprecated 请使用`createConfig`来配置schema */ createTip?: string; /** * 新增文字 * @deprecated 请使用`createConfig`来配置schema */ createBtnLabel?: string; editConfig?: ActionSchema; /** * 是否可以编辑 * @deprecated 请使用`editConfig`来配置schema */ editable?: boolean; editTip?: string; /** * 编辑时调用的 API * @deprecated 请使用`editConfig`来配置schema */ editApi?: Api; /** * 编辑表单初始化 API * @deprecated 请使用`editConfig`来配置schema */ editInitApi?: Api | string; /** * 选项修改的表单项 * @deprecated 请使用`editConfig`来配置schema */ editControls?: FormItemSchemaObject[]; /** * 控制编辑弹框设置项 * @deprecated 请使用`editConfig`来配置schema */ editDialog?: Partial<DialogSchema>; removeConfig?: ActionSchema; /** * 是否可删除 * @deprecated 请使用`removeConfig`来配置schema */ removable?: boolean; removeTip?: string; /** * 选项删除 API * @deprecated 请使用`removeConfig`来配置schema */ deleteApi?: Api; /** * 选项删除提示文字。 * @deprecated 请使用`removeConfig`来配置schema */ deleteConfirmText?: string; /** * 自动填充,当选项被选择的时候,将选项中的其他值同步设置到表单内。 */ autoFill?: { [propName: string]: string; }; /** * 默认是label */ labelField?: string; /** * 默认是value */ valueField?: string; /** * 可选选项的名称, 用于新增/编辑选项的弹窗的标题里 */ optionLabel?: string; } export interface OptionsBasicConfig extends FormItemBasicConfig { autoLoadOptionsFromSource?: boolean; } export interface OptionsConfig extends OptionsBasicConfig { component: React.ComponentType<OptionsControlProps>; } /** * 可选项操作结果对象 */ export interface OptionOperateResult { /** 前置检查是否通过 */ checked: boolean; /** 是否确定执行操作 */ confirmed?: boolean; /** 是否被事件动作拦截住 */ isPrevented?: boolean; /** 操作结果 */ result?: boolean; } export interface OptionsControlProps extends FormControlProps, Omit<FormOptionsControl, 'type' | 'className' | 'descriptionClassName' | 'inputClassName' | 'remark' | 'labelRemark'> { options: Array<Option>; selectedOptions: Array<Option>; inputClassName?: string; onToggle: (option: Option, submitOnChange?: boolean, changeImmediately?: boolean) => void; onToggleAll: () => void; setOptions: (value: Array<any>, skipNormalize?: boolean) => void; setLoading: (value: boolean) => void; reloadOptions: (setError?: boolean) => void; deferLoad: (option: Option) => Promise<void>; leftDeferLoad: (option: Option, leftOptions: Option) => void; expandTreeOptions: (nodePathArr: any[]) => void; onAdd?: (idx?: number | Array<number>, value?: any, skipForm?: boolean) => void; onEdit?: (value: Option, origin?: Option, skipForm?: boolean) => void; onDelete?: (value: Option) => Promise<OptionOperateResult>; doAction?: (action: ActionObject, data: Record<string, any>, throwErrors?: boolean) => void; } export interface OptionProps extends Omit<FormOptionsControl, 'options' | 'className' | 'descriptionClassName' | 'inputClassName'> { className?: string; multi?: boolean; multiple?: boolean; valueField: string; labelField: string; simpleValue?: boolean; options: Option[]; loading?: boolean; joinValues?: boolean; extractValue?: boolean; delimiter?: string; clearable?: boolean; placeholder?: string; disabled?: boolean; /** @deprecated 使用 `createConfig`替代 */ creatable?: boolean; pathSeparator?: string; hasError?: boolean; block?: boolean; /** 每个选项的高度,主要用于虚拟渲染 */ itemHeight?: number; /** 数据量多大的时候开启虚拟渲染 */ virtualThreshold?: number; /** @deprecated 使用 `removeConfig`替代 */ removable?: boolean; /** @deprecated 使用 `editConfig`替代 */ editable?: boolean; onAdd?: (idx?: number | Array<number>, value?: any, skipForm?: boolean) => void; onEdit?: (value: Option, origin?: Option, skipForm?: boolean) => void; onDelete?: OptionsControlProps['onDelete']; } export type IOptionsEvent = 'change' | 'inited' | 'loadFinished' /** 添加项事件 */ | 'add' | 'edit' | 'delete'; export interface OptionsProps extends FormControlProps, Omit<OptionProps, 'className'> { source?: Api; deferApi?: Api; /** @deprecated 使用 `createConfig`替代 */ creatable?: boolean; /** @deprecated 使用 `createConfig`替代 */ addApi?: Api; /** @deprecated 使用 `editConfig`替代 */ editInitApi?: Api; /** @deprecated 使用 `editConfig`替代 */ editApi?: Api; /** @deprecated 使用 `removeConfig`替代 */ deleteApi?: Api; /** @deprecated 使用 `removeConfig`替代 */ deleteConfirmText?: string; optionLabel?: string; dispatchEvent: DispatchEventFn<RendererPropsData, IOptionsEvent>; }