vben
2020-11-13 1d45617e4a311e339eb008a629cd342cd673ecf1
提交 | 用户 | age
2407b3 1 import type { NamePath, RuleObject } from 'ant-design-vue/lib/form/interface';
2f6253 2 import type { VNode } from 'vue';
3 import type { BasicButtonProps } from '/@/components/Button/types';
4 import type { FormItem } from './formItem';
5 import type { ColEx, ComponentType } from './index';
5832ee 6 import { TableActionType } from '../../../Table/src/types/table';
2f6253 7
8 export type FieldMapToTime = [string, [string, string], string?][];
9
1d4561 10 export type Rule = RuleObject & {
V 11   trigger?: 'blur' | 'change' | ['change', 'blur'];
12 };
13
2f6253 14 export interface RenderCallbackParams {
15   schema: FormSchema;
16   values: any;
17   model: any;
18   field: string;
19 }
a0c319 20
V 21 export interface ButtonProps extends BasicButtonProps {
22   text?: string;
23 }
24
2407b3 25 export interface FormActionType {
a0c319 26   submit: () => Promise<void>;
V 27   setFieldsValue: <T>(values: T) => void;
28   resetFields: () => Promise<any>;
2f6253 29   getFieldsValue: () => any;
30   clearValidate: (name?: string | string[]) => void;
a0c319 31   updateSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => void;
V 32   setProps: (formProps: Partial<FormProps>) => void;
33   removeSchemaByFiled: (field: string | string[]) => void;
34   appendSchemaByField: (schema: FormSchema, prefixField?: string) => void;
35   validateFields: (nameList?: NamePath[]) => Promise<any>;
36   validate: (nameList?: NamePath[]) => Promise<any>;
2407b3 37   scrollToField: (name: NamePath, options?: ScrollOptions) => void;
2f6253 38 }
39 export type RegisterFn = (formInstance: FormActionType) => void;
40
41 export type UseFormReturnType = [RegisterFn, FormActionType];
42
43 export interface FormProps {
84c9d7 44   // 表单值
V 45   model?: any;
2f6253 46   // 整个表单所有项宽度
47   labelWidth?: number | string;
d09406 48   // 重置时提交
V 49   submitOnReset?: boolean;
2f6253 50   // 整个表单通用Col配置
51   labelCol?: Partial<ColEx>;
52   // 整个表单通用Col配置
53   wrapperCol?: Partial<ColEx>;
54
55   // 通用col配置
a0c319 56   baseColProps?: Partial<ColEx>;
2f6253 57
58   // 表单配置规则
59   schemas?: FormSchema[];
60   // 用于合并到动态控制表单项的 函数values
61   mergeDynamicData?: any;
62   // 紧凑模式,用于搜索表单
63   compact?: boolean;
64   // 空白行span
65   emptySpan?: number | Partial<ColEx>;
66   // 表单内部组件大小
5a6db8 67   size?: 'default' | 'small' | 'large';
2f6253 68   // 是否禁用
69   disabled?: boolean;
70   // 时间区间字段映射成多个
71   fieldMapToTime?: FieldMapToTime;
72   // 自动设置placeholder
a0c319 73   autoSetPlaceHolder?: boolean;
2f6253 74   // 校验信息是否加入label
75   rulesMessageJoinLabel?: boolean;
76   // 是否显示收起展开按钮
77   showAdvancedButton?: boolean;
78   // 超过指定行数自动收起
79   autoAdvancedLine?: number;
80   // 是否显示操作按钮
5a6db8 81   showActionButtonGroup?: boolean;
2f6253 82
83   // 重置按钮配置
a0c319 84   resetButtonOptions?: Partial<ButtonProps>;
2f6253 85
86   // 确认按钮配置
a0c319 87   submitButtonOptions?: Partial<ButtonProps>;
2f6253 88
89   // 操作列配置
5a6db8 90   actionColOptions?: Partial<ColEx>;
2f6253 91
92   // 显示重置按钮
5a6db8 93   showResetButton?: boolean;
2f6253 94   // 显示确认按钮
5a6db8 95   showSubmitButton?: boolean;
2f6253 96
5a6db8 97   resetFunc?: () => Promise<void>;
V 98   submitFunc?: () => Promise<void>;
99   transformDateFunc?: (date: any) => string;
2f6253 100   colon?: boolean;
101 }
102 export interface FormSchema {
103   // 字段名
104   field: string;
1d4561 105   // 内部值更改触发的事件名,默认 change
2f6253 106   changeEvent?: string;
1d4561 107   // v-model绑定的变量名 默认 value
V 108   valueField?: string;
2f6253 109   // 标签名
110   label: string;
111   // 文本右侧帮助文本
112   helpMessage?: string | string[];
113   // BaseHelp组件props
114   helpComponentProps?: Partial<HelpComponentProps>;
115   // label宽度,有传的话 itemProps配置的 labelCol 和WrapperCol会失效
116   labelWidth?: string | number;
117   // 禁用调有formModel全局设置的labelWidth,自己手动设置 labelCol和wrapperCol
118   disabledLabelWidth?: boolean;
119   // 组件
120   component: ComponentType;
121   // 组件参数
5832ee 122   componentProps?:
1d4561 123     | ((opt: {
V 124         schema: FormSchema;
125         tableAction: TableActionType;
126         formActionType: FormActionType;
127         formModel: any;
128       }) => any)
5832ee 129     | object;
285906 130   // 必填
V 131   required?: boolean;
2f6253 132
133   // 校验规则
1d4561 134   rules?: Rule[];
2f6253 135   // 校验信息是否加入label
136   rulesMessageJoinLabel?: boolean;
137
138   // 参考formModelItem
139   itemProps?: Partial<FormItem>;
140
141   // formModelItem外层的col配置
142   colProps?: Partial<ColEx>;
143
144   // 默认值
145   defaultValue?: any;
146   isAdvanced?: boolean;
147
148   // 配合详情组件
149   span?: number;
150
151   ifShow?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
152
153   show?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
154
155   // 渲染form-item标签内的内容
156   render?: (renderCallbackParams: RenderCallbackParams) => VNode | VNode[] | string;
157
158   // 渲染 col内容,需要外层包裹 form-item
a0c319 159   renderColContent?: (renderCallbackParams: RenderCallbackParams) => VNode | VNode[] | string;
2f6253 160
1d4561 161   renderComponentContent?:
V 162     | ((renderCallbackParams: RenderCallbackParams) => any)
163     | VNode
164     | VNode[]
165     | string;
2f6253 166
167   // 自定义slot, 在 from-item内
168   slot?: string;
169
170   // 自定义slot,类似renderColContent
171   colSlot?: string;
172
173   dynamicDisabled?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
174
1d4561 175   dynamicRules?: (renderCallbackParams: RenderCallbackParams) => Rule[];
2f6253 176 }
177 export interface HelpComponentProps {
178   maxWidth: string;
179   // 是否显示序号
180   showIndex: boolean;
181   // 文本列表
182   text: any;
183   // 颜色
184   color: string;
185   // 字体大小
186   fontSize: string;
187   icon: string;
188   absolute: boolean;
189   // 定位
190   position: any;
191 }