import React from 'react'; import { Field, FieldConfigs, FieldError } from '../../components/formFields/common'; import Step, { StepConfig, StepProps } from '../common'; import { ColumnsConfig, ParamConfig } from '../../interface'; import { ConditionConfig } from '../../util/condition'; import { StatementConfig } from '../../util/statement'; import OperationHelper, { OperationConfig } from '../../util/operation'; /** * 表单步骤配置文件格式定义 * - layout: 表单布局类型 * - * horizontal: 左侧文本、右侧输入框、纵向排列 * - * vertical: 顶部文本、底部输入框、纵向排列 * - * inline: 左侧文本、右侧输入框、横向排列 * - columns: 分栏设置 * - * type: 分栏类型 * - * - * span: 固定分栏 * - * - * width: 宽度分栏 * - * value: 分栏相关配置值 * - * wrap: 分栏后是否换行 * - * gap: 分栏边距 * - fields: 表单项配置列表 * - defaultValue: 默认值 * - hiddenSubmit: 是否隐藏提交按钮 * - hiddenCancel: 是否隐藏取消按钮 * - submitText: 自定义确认按钮文本 * - cancelText: 自定义取消按钮文本 * - validations: 全局校验 * - * - condition: (全局校验子项中)校验条件 * - * - message: 校验失败提示文本 * - actions: 表单步骤按钮列表 */ export interface FormConfig extends StepConfig { type: 'form'; layout?: 'horizontal' | 'vertical' | 'inline'; columns?: ColumnsConfig; /** * 表单组件配置文件格式定义 * 参照其它组件定义 */ fields?: FieldConfigs[]; defaultValue?: ParamConfig; validations?: Array<{ condition?: ConditionConfig; message?: StatementConfig; }>; actions: Array | []; rightTopActions: Array | []; stringify?: string[]; unstringify?: string[]; hiddenSubmit?: boolean; hiddenCancel?: boolean; submitText?: string; cancelText?: string; } /** * 表单步骤按钮列表按钮项配置 * - type: 按钮操作类型 * - * - submit: 提交 * - * - cancel: 取消 * - * - ccms: 自定义(搭建页面) * - label: 按钮文案 * - mode: 按钮形式 * - * - normal: 普通按钮 * - * - primary: 主按钮 * - * - link: 链接 * - condition: 展示条件 * - callback: 自定义操作 - 回调 * - * - type: 回调操作类型 * - * - * - none: 无操作 * - * - * - submit: 提交表单 * - * - * - cancel: 取消表单 */ export interface ActionConfig { type: 'submit' | 'cancel' | 'ccms'; label: string; mode: 'normal' | 'primary' | 'link'; submitValidate: boolean; condition?: ConditionConfig; handle?: OperationConfig; callback?: { type: 'none' | 'submit' | 'cancel'; }; } /** * 全局校验 modal组件 - 入参格式 * message: 提示文案 */ export interface IFormStepModal { message: string; } /** * 表单步骤组件 - UI渲染方法 - 入参格式 * - layout: 表单布局类型 * - columns: 分栏设置 * - * type: 分栏类型 * - * - * span: 固定分栏 * - * - * width: 宽度分栏 * - * value: 分栏相关配置值 * - * wrap: 分栏后是否换行 * - * gap: 分栏边距 * - * horizontal: 左侧文本、右侧输入框、纵向排列 * - * vertical: 顶部文本、底部输入框、纵向排列 * - * inline: 左侧文本、右侧输入框、横向排列 * - submit: 表单提交操作事件 * - cancel: 表单取消操作事件 * - children: 表单内容 */ export interface IForm { layout: 'horizontal' | 'vertical' | 'inline'; columns?: ColumnsConfig; actions?: React.ReactNode[]; rightTopActions?: React.ReactNode[]; children: React.ReactNode[]; onSubmit?: () => Promise; onCancel?: () => Promise; submitText?: string; cancelText?: string; } /** * 表单步骤按钮config * - label: 按钮文案 * - type: 按钮形式 * - onClick: 按钮操作 */ export interface IButtonProps { label: string; mode: 'normal' | 'primary' | 'link'; onClick: () => void; } /** * 表单项容器组件 - UI渲染方法 - 入参格式 * - key: react需要的unique key * - label: 表单项名称 * - status: 表单项状态 * - * normal 默认状态 * - * error 错误 * - * loading 加载中 * - description: 表单项说明 * - message: 表单项消息 * - layout: 表单项布局 * - * horizontal: 左侧文本、右侧输入框、纵向排列 * - * vertical: 顶部文本、底部输入框、纵向排列 * - * inline: 左侧文本、右侧输入框、横向排列 * - children: 表单项内容 */ export interface IFormItem { key: string | number; label: string; subLabel?: React.ReactNode; status: 'normal' | 'error' | 'loading'; required: boolean; description?: string; message?: string; extra?: string; layout: 'horizontal' | 'vertical' | 'inline'; columns?: ColumnsConfig; visitable: boolean; fieldType: string; children: React.ReactNode; } /** * 表单步骤组件 - 状态 * - formData: 表单的值 */ interface FormState { ready: boolean; formValue: { [field: string]: any; }; formData: { status: 'normal' | 'error' | 'loading'; message?: string; name: string; }[]; } /** * 表单步骤组件 */ export default class FormStep extends Step { getALLComponents: (type: any) => typeof Field; OperationHelper: typeof OperationHelper; formFields: Array, any> | null>; formFieldsMounted: Array; dependentFields_: string[]; formValue: { [field: string]: any; }; formData: { status: 'normal' | 'error' | 'loading'; message?: string; name: string; }[]; canSubmit: boolean; submitData: object; /** * 初始化表单的值 * @param props */ constructor(props: StepProps); /** * 重写表单步骤装载事件 */ stepPush: () => Promise; handleFormFieldMount: (formFieldIndex: number) => Promise; /** * 触发表单校验 */ handleValidations: () => Promise; /** * 处理表单提交事件 */ handleSubmit: () => Promise; /** * 处理表单返回事件 */ handleCancel: () => Promise; /** * 处理表单项change事件 * @param field 表单项配置 * @param value 目标值 */ handleChange: (formFieldIndex: number, value: any) => Promise; handleValueSet: (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean; }) => Promise; handleValueUnset: (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean; }) => Promise; handleValueListAppend: (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean; }) => Promise; handleValueListSplice: (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean; }) => Promise; handleValueListSort: (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean; }) => Promise; /** * 处理表单步骤按钮列表按钮项回调 * @param action 按钮项配置 */ handleCallback: (action: ActionConfig, success: boolean) => Promise; /** * 表单步骤组件 - UI渲染方法 * 各UI库需重写该方法 * @param props */ renderComponent: (props: IForm) => JSX.Element; /** * 表单步骤按钮项button组件 * @param props */ renderButtonComponent: (props: IButtonProps) => JSX.Element; /** * 表单项组件 - UI渲染方法 * 各UI库需重写该方法 * @param props */ renderItemComponent: (props: IFormItem) => JSX.Element; /** * modal组件 - UI渲染方法 * 各UI库需重写该方法 * @param props */ renderModalComponent: (props: IFormStepModal) => Promise; getActios: (actions: Array | [], formValue: { [field: string]: any; }, data: any[]) => any; render(): JSX.Element; } export {};