1sm
2021-12-28 f964533701389109d90144cbefff7042cdcedbf6
提交 | 用户 | age
2407b3 1 import type { NamePath, RuleObject } from 'ant-design-vue/lib/form/interface';
2f6253 2 import type { VNode } from 'vue';
b5046f 3 import type { ButtonProps as AntdButtonProps } from '/@/components/Button';
2f6253 4 import type { FormItem } from './formItem';
5 import type { ColEx, ComponentType } from './index';
73c8e0 6 import type { TableActionType } from '/@/components/Table/src/types/table';
4ff1c4 7 import type { CSSProperties } from 'vue';
785732 8 import type { RowProps } from 'ant-design-vue/lib/grid/Row';
2f6253 9
10 export type FieldMapToTime = [string, [string, string], string?][];
11
1d4561 12 export type Rule = RuleObject & {
V 13   trigger?: 'blur' | 'change' | ['change', 'blur'];
14 };
15
2f6253 16 export interface RenderCallbackParams {
17   schema: FormSchema;
4ff1c4 18   values: Recordable;
V 19   model: Recordable;
2f6253 20   field: string;
21 }
a0c319 22
73c8e0 23 export interface ButtonProps extends AntdButtonProps {
a0c319 24   text?: string;
V 25 }
26
2407b3 27 export interface FormActionType {
a0c319 28   submit: () => Promise<void>;
4ff1c4 29   setFieldsValue: <T>(values: T) => Promise<void>;
V 30   resetFields: () => Promise<void>;
31   getFieldsValue: () => Recordable;
32   clearValidate: (name?: string | string[]) => Promise<void>;
33   updateSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>;
c639e4 34   resetSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>;
4ff1c4 35   setProps: (formProps: Partial<FormProps>) => Promise<void>;
V 36   removeSchemaByFiled: (field: string | string[]) => Promise<void>;
de5bf7 37   appendSchemaByField: (
V 38     schema: FormSchema,
39     prefixField: string | undefined,
56a966 40     first?: boolean | undefined,
de5bf7 41   ) => Promise<void>;
a0c319 42   validateFields: (nameList?: NamePath[]) => Promise<any>;
V 43   validate: (nameList?: NamePath[]) => Promise<any>;
4ff1c4 44   scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>;
2f6253 45 }
4ff1c4 46
2f6253 47 export type RegisterFn = (formInstance: FormActionType) => void;
48
49 export type UseFormReturnType = [RegisterFn, FormActionType];
50
51 export interface FormProps {
785732 52   layout?: 'vertical' | 'inline' | 'horizontal';
46e087 53   // Form value
4ff1c4 54   model?: Recordable;
46e087 55   // The width of all items in the entire form
2f6253 56   labelWidth?: number | string;
5fca9c 57   // alignment
785732 58   labelAlign?: 'left' | 'right';
5fca9c 59   // Row configuration for the entire form
785732 60   rowProps?: RowProps;
46e087 61   // Submit form on reset
d09406 62   submitOnReset?: boolean;
f96453 63   // Submit form on form changing
1 64   submitOnChange?: boolean;
46e087 65   // Col configuration for the entire form
2f6253 66   labelCol?: Partial<ColEx>;
46e087 67   // Col configuration for the entire form
2f6253 68   wrapperCol?: Partial<ColEx>;
69
b9d3d6 70   // General row style
4ff1c4 71   baseRowStyle?: CSSProperties;
b9d3d6 72
46e087 73   // General col configuration
a0c319 74   baseColProps?: Partial<ColEx>;
2f6253 75
46e087 76   // Form configuration rules
2f6253 77   schemas?: FormSchema[];
46e087 78   // Function values used to merge into dynamic control form items
4ff1c4 79   mergeDynamicData?: Recordable;
46e087 80   // Compact mode for search forms
2f6253 81   compact?: boolean;
46e087 82   // Blank line span
2f6253 83   emptySpan?: number | Partial<ColEx>;
46e087 84   // Internal component size of the form
5a6db8 85   size?: 'default' | 'small' | 'large';
46e087 86   // Whether to disable
2f6253 87   disabled?: boolean;
46e087 88   // Time interval fields are mapped into multiple
2f6253 89   fieldMapToTime?: FieldMapToTime;
46e087 90   // Placeholder is set automatically
a0c319 91   autoSetPlaceHolder?: boolean;
9b2d41 92   // Auto submit on press enter on input
N 93   autoSubmitOnEnter?: boolean;
46e087 94   // Check whether the information is added to the label
2f6253 95   rulesMessageJoinLabel?: boolean;
46e087 96   // Whether to show collapse and expand buttons
2f6253 97   showAdvancedButton?: boolean;
ac1a36 98   // Whether to focus on the first input box, only works when the first form item is input
V 99   autoFocusFirstItem?: boolean;
46e087 100   // Automatically collapse over the specified number of rows
2f6253 101   autoAdvancedLine?: number;
93f9a1 102   // Always show lines
103   alwaysShowLines?: number;
46e087 104   // Whether to show the operation button
5a6db8 105   showActionButtonGroup?: boolean;
2f6253 106
46e087 107   // Reset button configuration
a0c319 108   resetButtonOptions?: Partial<ButtonProps>;
2f6253 109
46e087 110   // Confirm button configuration
a0c319 111   submitButtonOptions?: Partial<ButtonProps>;
2f6253 112
46e087 113   // Operation column configuration
5a6db8 114   actionColOptions?: Partial<ColEx>;
2f6253 115
46e087 116   // Show reset button
5a6db8 117   showResetButton?: boolean;
46e087 118   // Show confirmation button
5a6db8 119   showSubmitButton?: boolean;
2f6253 120
5a6db8 121   resetFunc?: () => Promise<void>;
V 122   submitFunc?: () => Promise<void>;
123   transformDateFunc?: (date: any) => string;
2f6253 124   colon?: boolean;
125 }
126 export interface FormSchema {
46e087 127   // Field name
2f6253 128   field: string;
46e087 129   // Event name triggered by internal value change, default change
2f6253 130   changeEvent?: string;
46e087 131   // Variable name bound to v-model Default value
1d4561 132   valueField?: string;
46e087 133   // Label name
473e56 134   label: string | VNode;
46e087 135   // Auxiliary text
0b6110 136   subLabel?: string;
46e087 137   // Help text on the right side of the text
9b2d41 138   helpMessage?:
N 139     | string
140     | string[]
141     | ((renderCallbackParams: RenderCallbackParams) => string | string[]);
46e087 142   // BaseHelp component props
2f6253 143   helpComponentProps?: Partial<HelpComponentProps>;
46e087 144   // Label width, if it is passed, the labelCol and WrapperCol configured by itemProps will be invalid
2f6253 145   labelWidth?: string | number;
46e087 146   // Disable the adjustment of labelWidth with global settings of formModel, and manually set labelCol and wrapperCol by yourself
2f6253 147   disabledLabelWidth?: boolean;
46e087 148   // render component
2f6253 149   component: ComponentType;
46e087 150   // Component parameters
5832ee 151   componentProps?:
1d4561 152     | ((opt: {
V 153         schema: FormSchema;
154         tableAction: TableActionType;
155         formActionType: FormActionType;
4ff1c4 156         formModel: Recordable;
V 157       }) => Recordable)
5832ee 158     | object;
46e087 159   // Required
765064 160   required?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
2f6253 161
ac1a36 162   suffix?: string | number | ((values: RenderCallbackParams) => string | number);
V 163
46e087 164   // Validation rules
1d4561 165   rules?: Rule[];
46e087 166   // Check whether the information is added to the label
2f6253 167   rulesMessageJoinLabel?: boolean;
168
46e087 169   // Reference formModelItem
2f6253 170   itemProps?: Partial<FormItem>;
171
46e087 172   // col configuration outside formModelItem
2f6253 173   colProps?: Partial<ColEx>;
174
175   // 默认值
176   defaultValue?: any;
177   isAdvanced?: boolean;
178
46e087 179   // Matching details components
2f6253 180   span?: number;
181
182   ifShow?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
183
184   show?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
185
46e087 186   // Render the content in the form-item tag
2f6253 187   render?: (renderCallbackParams: RenderCallbackParams) => VNode | VNode[] | string;
188
46e087 189   // Rendering col content requires outer wrapper form-item
a0c319 190   renderColContent?: (renderCallbackParams: RenderCallbackParams) => VNode | VNode[] | string;
2f6253 191
1d4561 192   renderComponentContent?:
V 193     | ((renderCallbackParams: RenderCallbackParams) => any)
194     | VNode
195     | VNode[]
196     | string;
2f6253 197
46e087 198   // Custom slot, in from-item
2f6253 199   slot?: string;
200
46e087 201   // Custom slot, similar to renderColContent
2f6253 202   colSlot?: string;
203
204   dynamicDisabled?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
205
1d4561 206   dynamicRules?: (renderCallbackParams: RenderCallbackParams) => Rule[];
2f6253 207 }
208 export interface HelpComponentProps {
209   maxWidth: string;
46e087 210   // Whether to display the serial number
2f6253 211   showIndex: boolean;
46e087 212   // Text list
2f6253 213   text: any;
46e087 214   // colour
2f6253 215   color: string;
46e087 216   // font size
2f6253 217   fontSize: string;
218   icon: string;
219   absolute: boolean;
46e087 220   // Positioning
2f6253 221   position: any;
222 }