1 | import {CreateElement, VNodeDirective, VueConstructor} from "vue";
|
2 | import {ScopedSlot, ScopedSlotChildren} from "vue/types/vnode";
|
3 | import {ExtendedVue, Vue} from "vue/types/vue";
|
4 |
|
5 | export namespace FormCreate {
|
6 |
|
7 | export interface Install {
|
8 | (Vue): void;
|
9 | }
|
10 |
|
11 | export interface Create<FormRule, FormConfig, FormButton> {
|
12 | (rules: FormRule[], config?: FormConfig): $FApi<FormRule, FormConfig, FormButton>
|
13 | }
|
14 |
|
15 | export interface Init<FormRule, FormConfig, FormButton> {
|
16 | (rules: FormRule[], config?: FormConfig): MountApi<FormRule, FormConfig, FormButton>
|
17 | }
|
18 |
|
19 | export interface MountApi<FormRule, FormConfig, FormButton> {
|
20 | mount($el?: Element): $FApi<FormRule, FormConfig, FormButton>;
|
21 |
|
22 | remove();
|
23 |
|
24 | $f: $FApi<FormRule, FormConfig, FormButton>;
|
25 | }
|
26 |
|
27 | export interface Component {
|
28 | (): VueConstructor[];
|
29 |
|
30 | (id: string): VueConstructor;
|
31 |
|
32 | (id: string, definition): ExtendedVue<Vue, {}, {}, {}, {}>;
|
33 | }
|
34 |
|
35 | export interface FormData {
|
36 | [field: string]: any;
|
37 | }
|
38 |
|
39 | export interface BindFormData extends FormData {
|
40 | }
|
41 |
|
42 | export interface BaseButton<Col> {
|
43 | innerText?: string;
|
44 | show?: boolean;
|
45 | col?: Col;
|
46 | click?: Function;
|
47 | }
|
48 |
|
49 | export interface BaseConfig<FormConfig, Row, Upload, Button, FormRule, FormButton> {
|
50 | form?: FormConfig;
|
51 | row?: Row;
|
52 | upload?: Upload;
|
53 | submitBtn?: Button;
|
54 | resetBtn?: Button;
|
55 | el?: Element | string;
|
56 | switchMaker?: boolean;
|
57 | iframeHelper?: boolean;
|
58 | mounted?: ($f: $FApi<FormRule, BaseConfig<FormConfig, Row, Upload, Button, FormRule, FormButton>, FormButton>) => void;
|
59 | onReload?: ($f: $FApi<FormRule, BaseConfig<FormConfig, Row, Upload, Button, FormRule, FormButton>, FormButton>) => void;
|
60 | onSubmit?: (formData: FormData, $f: $FApi<FormRule, BaseConfig<FormConfig, Row, Upload, Button, FormRule, FormButton>, FormButton>) => void;
|
61 | }
|
62 |
|
63 | export interface Data {
|
64 | key?: string | number;
|
65 | slot?: string;
|
66 | scopedSlots?: { [key: string]: ScopedSlot | undefined };
|
67 | ref?: string;
|
68 | class?: any;
|
69 | style?: object[] | object;
|
70 | props?: { [key: string]: any };
|
71 | attrs?: { [key: string]: any };
|
72 | domProps?: { [key: string]: any };
|
73 | on?: { [key: string]: Function | Function[] };
|
74 | nativeOn?: { [key: string]: Function | Function[] };
|
75 | directives?: VNodeDirective[];
|
76 | }
|
77 |
|
78 | export interface BaseOption<Rule> {
|
79 | slot?: string | DefaultSlot<Rule>
|
80 | }
|
81 |
|
82 | export interface Rule<Col, FormOption extends BaseOption<Rule<Col, FormOption>>> extends Data {
|
83 | readonly type: string;
|
84 | readonly field?: string;
|
85 | event?: {
|
86 | [key: string]: Function
|
87 | };
|
88 | options?: FormOption[];
|
89 | validate?: any[];
|
90 | col?: Col;
|
91 | emit?: string[];
|
92 | template?: string;
|
93 | emitPrefix?: string;
|
94 | title?: string;
|
95 | value?: any;
|
96 | className?: any;
|
97 | defaultSlot?: any;
|
98 | children?: Array<Rule<Col, FormOption> | Creator<Rule<Col, FormOption>, Col, FormOption> | string>;
|
99 | hidden?: false
|
100 | visibility?: false
|
101 |
|
102 | [key: string]: any;
|
103 | }
|
104 |
|
105 | export class VData {
|
106 | private _data: Data;
|
107 |
|
108 | private init(): this;
|
109 |
|
110 | class(classList: any): this;
|
111 | class(_class: string, status: boolean | any): this;
|
112 |
|
113 | directives(directives: VNodeDirective | VNodeDirective[]): this;
|
114 |
|
115 | get(): Data;
|
116 |
|
117 | ref(ref: string): this;
|
118 |
|
119 | key(key: string | number): this;
|
120 |
|
121 | slot(slot: string): this;
|
122 |
|
123 | scopedSlots(scopedSlots: { [key: string]: ScopedSlot } | string, val?: ScopedSlot): this;
|
124 |
|
125 | nativeOn(nativeOn: { [key: string]: Function | Function[] } | string, val?: Function): this;
|
126 |
|
127 | on(on: { [key: string]: Function | Function[] } | string, val?: Function): this;
|
128 |
|
129 | props(props: { [key: string]: any } | string, val?: any): this;
|
130 |
|
131 | attrs(attrs: { [key: string]: any } | string, val?: any): this;
|
132 |
|
133 | style(style: { [key: string]: any } | string, val?: any): this;
|
134 |
|
135 | domProps(style: { [key: string]: any } | string, val?: any): this;
|
136 |
|
137 | }
|
138 |
|
139 | export interface DefaultSlot<Rule> {
|
140 | (rule: Rule, $h: CreateElement): ScopedSlotChildren | string
|
141 | }
|
142 |
|
143 |
|
144 | export class Creator<Rule, Col, FormOption> extends VData {
|
145 | private rule: Rule;
|
146 |
|
147 | new(type: string, title: string, field: string, value?: any, props?: object): this;
|
148 |
|
149 | type(type: string): this;
|
150 |
|
151 | get(): Data;
|
152 |
|
153 | getRule(): this;
|
154 |
|
155 | setValue(value: any): this;
|
156 |
|
157 | emitPrefix(emitPrefix: string): this;
|
158 |
|
159 | className(className: any): this;
|
160 |
|
161 | defaultSlot(slot: string | DefaultSlot<Rule>): this;
|
162 |
|
163 | event(event: object): this;
|
164 |
|
165 | col(col: Col): this;
|
166 |
|
167 | validate(validate: any[] | object): this;
|
168 |
|
169 | options(options: FormOption[]): this;
|
170 |
|
171 | children(children: Array<Rule | Creator<Rule, Col, FormOption> | string>): this;
|
172 |
|
173 | emit(emit: string[]): this;
|
174 | }
|
175 |
|
176 | type CommonMaker<Creator> = (title: string, field: string, value?: any) => Creator;
|
177 |
|
178 | export interface ParseRuleList<FormRule> extends Iterable<FormRule[]> {
|
179 | find(field: string): FormRule;
|
180 | }
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | type Components =
|
192 | 'auto'
|
193 | | 'autoComplete'
|
194 | | 'cascader'
|
195 | | 'checkbox'
|
196 | | 'color'
|
197 | | 'colorPicker'
|
198 | | 'date'
|
199 | | 'datePicker'
|
200 | | 'dateRange'
|
201 | | 'dateTime'
|
202 | | 'dateTimeRange'
|
203 | |
|
204 | 'email'
|
205 | | 'file'
|
206 | | 'frame'
|
207 | | 'frameFile'
|
208 | | 'frameFileOne'
|
209 | | 'frameFiles'
|
210 | | 'frameImage'
|
211 | | 'frameImageOne'
|
212 | | 'frameImages'
|
213 | | 'frameInput'
|
214 | | 'frameInputOne'
|
215 | |
|
216 | 'frameInputs'
|
217 | | 'idate'
|
218 | | 'image'
|
219 | | 'input'
|
220 | | 'inputNumber'
|
221 | | 'month'
|
222 | | 'number'
|
223 | | 'password'
|
224 | | 'radio'
|
225 | | 'rate'
|
226 | | 'select'
|
227 | | 'selectMultiple'
|
228 | | 'selectOne'
|
229 | | 'slider'
|
230 | |
|
231 | 'sliderRange'
|
232 | | 'switch'
|
233 | | 'text'
|
234 | | 'textarea'
|
235 | | 'time'
|
236 | | 'timePicker'
|
237 | | 'timeRange'
|
238 | | 'tree'
|
239 | | 'treeChecked'
|
240 | | 'treeSelected'
|
241 | | 'upload'
|
242 | | 'uploadFile'
|
243 | | 'uploadFileOne'
|
244 | |
|
245 | 'uploadImage'
|
246 | | 'uploadImageOne'
|
247 | | 'url'
|
248 | | 'year';
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | export interface Maker<Creator, Rule> {
|
261 | hidden(field: string, value: any): Creator;
|
262 |
|
263 | create(type: string, field?: string, title?: string): Creator;
|
264 |
|
265 | createTmp(template: string, vm: Vue, field?: string, title?: string): Creator;
|
266 |
|
267 | template(template: string, vm: Vue, field?: string, title?: string): Creator;
|
268 |
|
269 | parse(rules: string | Array<Rule | Creator>, toMaker?: boolean): ParseRuleList<Rule | Creator>;
|
270 |
|
271 | auto: CommonMaker<Creator>;
|
272 | autoComplete: CommonMaker<Creator>;
|
273 | cascader: CommonMaker<Creator>;
|
274 | checkbox: CommonMaker<Creator>;
|
275 | color: CommonMaker<Creator>;
|
276 | colorPicker: CommonMaker<Creator>;
|
277 | date: CommonMaker<Creator>;
|
278 | datePicker: CommonMaker<Creator>;
|
279 | dateRange: CommonMaker<Creator>;
|
280 | dateTime: CommonMaker<Creator>;
|
281 | dateTimeRange: CommonMaker<Creator>;
|
282 | email: CommonMaker<Creator>;
|
283 | file: CommonMaker<Creator>;
|
284 | frame: CommonMaker<Creator>;
|
285 | frameFile: CommonMaker<Creator>;
|
286 | frameFileOne: CommonMaker<Creator>;
|
287 | frameFiles: CommonMaker<Creator>;
|
288 | frameImage: CommonMaker<Creator>;
|
289 | frameImageOne: CommonMaker<Creator>;
|
290 | frameImages: CommonMaker<Creator>;
|
291 | frameInput: CommonMaker<Creator>;
|
292 | frameInputOne: CommonMaker<Creator>;
|
293 | frameInputs: CommonMaker<Creator>;
|
294 | idate: CommonMaker<Creator>;
|
295 | image: CommonMaker<Creator>;
|
296 | input: CommonMaker<Creator>;
|
297 | inputNumber: CommonMaker<Creator>;
|
298 | month: CommonMaker<Creator>;
|
299 | number: CommonMaker<Creator>;
|
300 | password: CommonMaker<Creator>;
|
301 | radio: CommonMaker<Creator>;
|
302 | rate: CommonMaker<Creator>;
|
303 | select: CommonMaker<Creator>;
|
304 | selectMultiple: CommonMaker<Creator>;
|
305 | selectOne: CommonMaker<Creator>;
|
306 | slider: CommonMaker<Creator>;
|
307 | sliderRange: CommonMaker<Creator>;
|
308 | 'switch': CommonMaker<Creator>;
|
309 | text: CommonMaker<Creator>;
|
310 | textarea: CommonMaker<Creator>;
|
311 | time: CommonMaker<Creator>;
|
312 | timePicker: CommonMaker<Creator>;
|
313 | timeRange: CommonMaker<Creator>;
|
314 | tree: CommonMaker<Creator>;
|
315 | treeChecked: CommonMaker<Creator>;
|
316 | treeSelected: CommonMaker<Creator>;
|
317 | upload: CommonMaker<Creator>;
|
318 | uploadFile: CommonMaker<Creator>;
|
319 | uploadFileOne: CommonMaker<Creator>;
|
320 | uploadImage: CommonMaker<Creator>;
|
321 | uploadImageOne: CommonMaker<Creator>;
|
322 | url: CommonMaker<Creator>;
|
323 | year: CommonMaker<Creator>;
|
324 | }
|
325 |
|
326 |
|
327 | interface ButtonHandle {
|
328 | loading(loading?: boolean): void;
|
329 |
|
330 | finish(): void;
|
331 |
|
332 | disabled(disabled?: boolean): void;
|
333 |
|
334 | show(isShow?: boolean): void;
|
335 | }
|
336 |
|
337 | export interface $FApi<FormRule, FormConfig, FormButton> {
|
338 |
|
339 | config: FormConfig;
|
340 | rule: FormRule[];
|
341 |
|
342 | formData(): FormData;
|
343 |
|
344 | getValue(field: string): any;
|
345 |
|
346 | setValue(field: string, value: any): void;
|
347 |
|
348 | setValue(formData: FormData): void;
|
349 |
|
350 | changeValue(field: string, value: any): void;
|
351 |
|
352 | changeField(field: string, value: any): void;
|
353 |
|
354 | changeField(formData: FormData): void;
|
355 |
|
356 | removeField(field: string | string[]): void;
|
357 |
|
358 | validate(successFn?: Function, failFn?: Function): void;
|
359 |
|
360 | validateField(field: string, callback?: (errorMessage: string | boolean) => void): void;
|
361 |
|
362 | resetFields(field?: string | string[]): void;
|
363 |
|
364 | destroy(): void;
|
365 |
|
366 | fields(): string[];
|
367 |
|
368 | append(rule: FormRule): void;
|
369 |
|
370 | append(rule: FormRule, after: string): void;
|
371 |
|
372 | prepend(rule: FormRule): void;
|
373 |
|
374 | prepend(rule: FormRule, before: string): void;
|
375 |
|
376 | submit(successFn?: Function, failFn?: Function): void;
|
377 |
|
378 | hidden(field: string | string[] | undefined, isHidden?: boolean): void;
|
379 |
|
380 | visibility(field: string | string[] | undefined, isVisibility?: boolean): void;
|
381 |
|
382 | disabled(field: string | string[], disabled?: boolean): void;
|
383 |
|
384 | clearValidateState(field?: string | string[]): void;
|
385 |
|
386 | model(): { [field: string]: FormRule };
|
387 |
|
388 | component(): { [field: string]: FormRule };
|
389 |
|
390 | bind(field?: string | string[]): BindFormData;
|
391 |
|
392 | submitStatus(props: FormButton): void;
|
393 |
|
394 | resetStatus(props: FormButton): void;
|
395 |
|
396 | btn: ButtonHandle;
|
397 |
|
398 | resetBtn: ButtonHandle;
|
399 |
|
400 | closeModal(field: string): void;
|
401 |
|
402 | set: <T>(object: object, key: string | number, value: T) => T;
|
403 |
|
404 | reload(rules?: FormRule[]): void;
|
405 |
|
406 | options(options: FormConfig): void;
|
407 |
|
408 | onSubmit(callback: Function): void;
|
409 |
|
410 | refresh(): void;
|
411 |
|
412 | show(isShow?: boolean): void;
|
413 | }
|
414 | }
|