@form-create/iview 2.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/form-create.js +5930 -0
- package/dist/form-create.min.js +8 -0
- package/dist/form-create.min.js.map +1 -0
- package/package.json +69 -0
- package/src/components/index.js +19 -0
- package/src/core/alias.js +27 -0
- package/src/core/api.js +159 -0
- package/src/core/config.js +48 -0
- package/src/core/index.js +39 -0
- package/src/core/maker.js +93 -0
- package/src/core/manager.js +241 -0
- package/src/index.js +16 -0
- package/src/parsers/datePicker.js +78 -0
- package/src/parsers/hidden.js +12 -0
- package/src/parsers/index.js +10 -0
- package/src/parsers/input.js +21 -0
- package/src/parsers/row.js +8 -0
- package/src/parsers/slider.js +20 -0
- package/src/parsers/switch.js +10 -0
- package/src/style/index.css +7 -0
- package/types/config.d.ts +111 -0
- package/types/index.d.ts +31 -0
- package/types/maker.d.ts +14 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ivuFormCreate from './core/index';
|
|
2
|
+
|
|
3
|
+
const FormCreate = ivuFormCreate();
|
|
4
|
+
|
|
5
|
+
if (typeof window !== 'undefined') {
|
|
6
|
+
window.formCreate = FormCreate;
|
|
7
|
+
if (window.Vue) {
|
|
8
|
+
FormCreate.install(window.Vue);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const maker = FormCreate.maker;
|
|
13
|
+
|
|
14
|
+
export {maker}
|
|
15
|
+
|
|
16
|
+
export default FormCreate;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import is from '@form-create/utils/lib/type';
|
|
2
|
+
import {creatorFactory} from '@form-create/core/src/index';
|
|
3
|
+
|
|
4
|
+
export function timeStampToDate(timeStamp) {
|
|
5
|
+
if (is.Date(timeStamp))
|
|
6
|
+
return timeStamp;
|
|
7
|
+
else {
|
|
8
|
+
let date = new Date(timeStamp);
|
|
9
|
+
return date.toString() === 'Invalid Date' ? timeStamp : date;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const name = 'datePicker';
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
name,
|
|
17
|
+
maker: (function () {
|
|
18
|
+
return ['date', 'dateRange', 'datetime', 'datetimeRange', 'year', 'month'].reduce((maker, type) => {
|
|
19
|
+
maker[type] = creatorFactory(name, {type: type.toLowerCase()});
|
|
20
|
+
return maker;
|
|
21
|
+
}, {});
|
|
22
|
+
}()),
|
|
23
|
+
mergeProp(ctx) {
|
|
24
|
+
let props = ctx.prop.props;
|
|
25
|
+
if (props.startDate) {
|
|
26
|
+
props.startDate = props.startDate && timeStampToDate(props.startDate);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
isRange(el) {
|
|
31
|
+
return el.type.includes('range') || el.multiple;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
_toValue(val, ctx) {
|
|
35
|
+
const value = ctx.el.formatDate(val || ''), {separator} = ctx.el,
|
|
36
|
+
isRange = this.isRange(ctx.el);
|
|
37
|
+
if (!value)
|
|
38
|
+
return isRange ? (ctx.el.multiple ? [] : ['', '']) : value;
|
|
39
|
+
else if (isRange)
|
|
40
|
+
return value.split(separator);
|
|
41
|
+
else
|
|
42
|
+
return value;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
toValue(formValue, ctx) {
|
|
46
|
+
const el = ctx.el;
|
|
47
|
+
if (el) {
|
|
48
|
+
this.el = el;
|
|
49
|
+
return this._toValue(formValue, ctx);
|
|
50
|
+
}
|
|
51
|
+
return formValue;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
toFormValue(value, ctx) {
|
|
55
|
+
if (ctx.el) {
|
|
56
|
+
const v = ctx.el.parseDate(value);
|
|
57
|
+
return this.isRange(ctx.el) ? v : v[0];
|
|
58
|
+
} else {
|
|
59
|
+
let isArr = Array.isArray(value), props = ctx.prop.props, parseValue, type = props.type || 'date';
|
|
60
|
+
if (['daterange', 'datetimerange'].indexOf(type) !== -1) {
|
|
61
|
+
if (isArr) {
|
|
62
|
+
parseValue = value.map((time) => !time ? '' : timeStampToDate(time));
|
|
63
|
+
} else {
|
|
64
|
+
parseValue = ['', '']
|
|
65
|
+
}
|
|
66
|
+
} else if ('date' === type && props.multiple === true) {
|
|
67
|
+
parseValue = toString(value);
|
|
68
|
+
} else {
|
|
69
|
+
parseValue = isArr ? (value[0] || '') : value;
|
|
70
|
+
parseValue = !parseValue ? '' : timeStampToDate(parseValue);
|
|
71
|
+
}
|
|
72
|
+
return parseValue;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
mounted(ctx) {
|
|
76
|
+
ctx.rule.value = this.toValue(ctx.$handle.getFormData(ctx), ctx);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import datePicker from './datePicker';
|
|
2
|
+
import hidden from './hidden';
|
|
3
|
+
import input from './input';
|
|
4
|
+
import slider from './slider';
|
|
5
|
+
import iswitch from './switch';
|
|
6
|
+
import row from './row';
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
datePicker, hidden, input, slider, iswitch, row
|
|
10
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {creatorFactory} from '@form-create/core/src/index';
|
|
2
|
+
|
|
3
|
+
const name = 'input';
|
|
4
|
+
export default {
|
|
5
|
+
name,
|
|
6
|
+
maker: (function () {
|
|
7
|
+
const maker = ['password', 'url', 'email', 'text', 'textarea'].reduce((maker, type) => {
|
|
8
|
+
maker[type] = creatorFactory(name, {type});
|
|
9
|
+
return maker;
|
|
10
|
+
}, {});
|
|
11
|
+
|
|
12
|
+
maker.idate = creatorFactory(name, {type:'date'});
|
|
13
|
+
return maker
|
|
14
|
+
}()),
|
|
15
|
+
mergeProp(ctx) {
|
|
16
|
+
let {props} = ctx.prop;
|
|
17
|
+
if (props.autosize && props.autosize.minRows) {
|
|
18
|
+
props.rows = props.autosize.minRows || 2;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {creatorFactory} from '@form-create/core/src/index';
|
|
2
|
+
|
|
3
|
+
const name = 'slider';
|
|
4
|
+
export default {
|
|
5
|
+
name,
|
|
6
|
+
maker: {
|
|
7
|
+
sliderRange: creatorFactory(name, {range:true})
|
|
8
|
+
},
|
|
9
|
+
toFormValue(value, ctx) {
|
|
10
|
+
let isArr = Array.isArray(value), props = ctx.prop.props, min = props.min || 0,
|
|
11
|
+
parseValue;
|
|
12
|
+
if (props.range === true) {
|
|
13
|
+
parseValue = isArr ? value : [min, (parseFloat(value) || min)];
|
|
14
|
+
} else {
|
|
15
|
+
parseValue = isArr ? (parseFloat(value[0]) || min) : parseFloat(value);
|
|
16
|
+
}
|
|
17
|
+
return parseValue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
name: 'switch',
|
|
3
|
+
mergeProp(ctx) {
|
|
4
|
+
const prop = ctx.prop.props.slot || {};
|
|
5
|
+
const slot = ctx.prop.scopedSlots || {};
|
|
6
|
+
if (prop.open) slot.open = () => prop.open;
|
|
7
|
+
if (prop.close) slot.close = () => prop.close;
|
|
8
|
+
ctx.prop.scopedSlots = slot;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {FormData, VNodeData} from "@form-create/core";
|
|
2
|
+
import {Col, Row, Tooltip, Poptip, Button} from "iview";
|
|
3
|
+
import {Api} from "./index";
|
|
4
|
+
|
|
5
|
+
export interface OptionAttrs {
|
|
6
|
+
col?: Boolean | Col & {
|
|
7
|
+
labelWidth?: number | string;
|
|
8
|
+
show?: Boolean;
|
|
9
|
+
};
|
|
10
|
+
row?: Boolean | Row & {
|
|
11
|
+
show?: Boolean;
|
|
12
|
+
};
|
|
13
|
+
info?: Boolean | (Tooltip | Poptip) & VNodeData & {
|
|
14
|
+
show?: Boolean;
|
|
15
|
+
native?: Boolean;
|
|
16
|
+
icon?: string;
|
|
17
|
+
align?: 'left' | 'right';
|
|
18
|
+
info?: string;
|
|
19
|
+
};
|
|
20
|
+
wrap?: Boolean | VNodeData & {
|
|
21
|
+
labelWidth?: number;
|
|
22
|
+
labelFor?: string;
|
|
23
|
+
required?: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
showMessage?: boolean;
|
|
26
|
+
show?: Boolean;
|
|
27
|
+
};
|
|
28
|
+
form?: {
|
|
29
|
+
inline?: boolean;
|
|
30
|
+
labelPosition?: 'left' | 'right' | 'top';
|
|
31
|
+
labelWidth?: number;
|
|
32
|
+
showMessage?: boolean;
|
|
33
|
+
className?: any;
|
|
34
|
+
col?: Boolean;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
submitBtn?: Boolean | Button & {
|
|
38
|
+
click?: Function;
|
|
39
|
+
innerText?: string;
|
|
40
|
+
show?: Boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
resetBtn?: Boolean | Button & {
|
|
44
|
+
click?: Function;
|
|
45
|
+
innerText?: string;
|
|
46
|
+
show?: Boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare const optionAttrs: OptionAttrs & {
|
|
52
|
+
title?: Boolean | VNodeData & {
|
|
53
|
+
show?: Boolean;
|
|
54
|
+
native?: Boolean;
|
|
55
|
+
title?: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
interface children {
|
|
60
|
+
children?: VNodeData[]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface CreatorAttrs {
|
|
64
|
+
col(props: typeof optionAttrs.col): this;
|
|
65
|
+
|
|
66
|
+
wrap(props: typeof optionAttrs.wrap): this;
|
|
67
|
+
|
|
68
|
+
title(props: string | typeof optionAttrs.title & children): this;
|
|
69
|
+
|
|
70
|
+
info(props: string | typeof optionAttrs.info & children): this;
|
|
71
|
+
|
|
72
|
+
className(prop: string): this;
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface RuleAttrs {
|
|
77
|
+
col?: typeof optionAttrs.col;
|
|
78
|
+
wrap?: typeof optionAttrs.wrap;
|
|
79
|
+
title?: string | typeof optionAttrs.title & children;
|
|
80
|
+
info?: string | typeof optionAttrs.info & children;
|
|
81
|
+
className?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
export interface ApiAttrs {
|
|
86
|
+
btn: {
|
|
87
|
+
loading(loading: boolean): void;
|
|
88
|
+
disabled(disabled: boolean): void;
|
|
89
|
+
show(show: boolean): void;
|
|
90
|
+
}
|
|
91
|
+
resetBtn: {
|
|
92
|
+
loading(loading: boolean): void;
|
|
93
|
+
disabled(disabled: boolean): void;
|
|
94
|
+
show(show: boolean): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
submit(success: (formData: FormData, $f: Api) => void, fail: ($f: Api) => void): void;
|
|
98
|
+
|
|
99
|
+
clearValidateState(fields?: string | string[], clearSub?: Boolean): void;
|
|
100
|
+
|
|
101
|
+
clearSubValidateState(fields?: string | string[]): void;
|
|
102
|
+
|
|
103
|
+
validate(callback?: (valid?: boolean) => void): void;
|
|
104
|
+
|
|
105
|
+
validateField(field: string, callback?: (valid?: boolean) => void): void;
|
|
106
|
+
|
|
107
|
+
submitBtnProps(props: Button): void;
|
|
108
|
+
|
|
109
|
+
resetBtnProps(props: Button): void;
|
|
110
|
+
|
|
111
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FormCreate,
|
|
3
|
+
FormRule as $FormRule,
|
|
4
|
+
Options as $Options,
|
|
5
|
+
Rule as $Rule,
|
|
6
|
+
Creator as $Creator,
|
|
7
|
+
Control as $Control,
|
|
8
|
+
Api as $Api,
|
|
9
|
+
Effect as $Effect,
|
|
10
|
+
Parser as $Parser
|
|
11
|
+
} from "@form-create/core";
|
|
12
|
+
import Maker from "./maker";
|
|
13
|
+
import {ApiAttrs, CreatorAttrs, OptionAttrs, RuleAttrs} from "./config";
|
|
14
|
+
|
|
15
|
+
declare module 'vue/types/vue' {
|
|
16
|
+
interface Vue {
|
|
17
|
+
$formCreate: FormCreate<Maker, OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare const formCreate: FormCreate<Maker, OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>;
|
|
22
|
+
export default formCreate;
|
|
23
|
+
export declare const maker: typeof formCreate.maker;
|
|
24
|
+
export type FormRule = $FormRule<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
25
|
+
export type Options = $Options<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
26
|
+
export type Rule = $Rule<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
27
|
+
export type Effect = $Effect<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
28
|
+
export type Creator = $Creator<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
29
|
+
export type Control = $Control<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
30
|
+
export type Api = $Api<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
31
|
+
export type Parser = $Parser
|
package/types/maker.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {CreatorHelper} from "@form-create/core";
|
|
2
|
+
import {ApiAttrs, CreatorAttrs, OptionAttrs, RuleAttrs} from "./config";
|
|
3
|
+
|
|
4
|
+
declare const makerFactory: CreatorHelper<OptionAttrs, CreatorAttrs, RuleAttrs, ApiAttrs>
|
|
5
|
+
|
|
6
|
+
declare enum MakerName {
|
|
7
|
+
"datePicker", "date", "dateRange", "datetime", "datetimeRange", "year", "month", "hidden", "input", "password", "url", "email", "text", "textarea", "idate", "slider", "sliderRange", "switch", "upload", "select", "tree", "checkbox", "autoComplete", "cascader", "colorPicker", "frame", "inputNumber", "radio", "rate", "timePicker", "group", "auto", "number", "color", "image", "file", "uploadFileOne", "uploadImageOne", "uploadImage", "uploadFile", "treeSelected", "treeChecked", "selectMultiple", "selectOne", "frameInputs", "frameFiles", "frameImages", "frameInputOne", "frameFileOne", "frameImageOne", "frameInput", "frameFile", "frameImage", "time", "timeRange"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type Maker = {
|
|
11
|
+
[name in keyof typeof MakerName]: typeof makerFactory;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default Maker;
|