@form-create/element-ui 2.5.9 → 3.0.0-alpha.2
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/dist/form-create.esm.js +5845 -0
- package/dist/form-create.esm.min.js +7 -0
- package/dist/form-create.js +1862 -1912
- package/dist/form-create.min.js +2 -3
- package/package.json +33 -19
- package/src/core/alias.js +29 -29
- package/src/core/api.js +54 -90
- package/src/core/index.js +9 -2
- package/src/core/manager.js +34 -41
- package/src/index.js +0 -3
- package/src/parsers/datePicker.js +7 -8
- package/src/parsers/row.js +6 -4
- package/src/style/index.css +4 -0
- package/dist/form-create.min.js.map +0 -1
- package/types/config.d.ts +0 -119
- package/types/index.d.ts +0 -31
- package/types/maker.d.ts +0 -14
package/src/core/api.js
CHANGED
|
@@ -13,95 +13,60 @@ function tidyBtnProp(btn, def) {
|
|
|
13
13
|
export default function extendApi(api, h) {
|
|
14
14
|
extend(api, {
|
|
15
15
|
validate(callback) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
callback && callback(
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!args[0]) {
|
|
31
|
-
if (!flag) {
|
|
32
|
-
flag = args;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (!--len) {
|
|
36
|
-
validate();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
forms.forEach(form => {
|
|
42
|
-
form.validate((...args) => validFn(args))
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
if (!len) {
|
|
46
|
-
validate();
|
|
47
|
-
}
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const forms = api.children;
|
|
18
|
+
const all = [h.$manager.validate()];
|
|
19
|
+
forms.forEach(v => {
|
|
20
|
+
all.push(v.validate());
|
|
21
|
+
})
|
|
22
|
+
Promise.all(all).then(() => {
|
|
23
|
+
resolve(true);
|
|
24
|
+
callback && callback(true);
|
|
25
|
+
}).catch((e) => {
|
|
26
|
+
reject(e);
|
|
27
|
+
callback && callback(e);
|
|
28
|
+
})
|
|
29
|
+
});
|
|
48
30
|
},
|
|
49
|
-
validateField
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const validFn = (args) => {
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
if (!args[0]) {
|
|
68
|
-
if (!flag) {
|
|
69
|
-
flag = args;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (!--len) {
|
|
73
|
-
validate();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
sub && toArray(sub).forEach(form => {
|
|
78
|
-
len++;
|
|
79
|
-
form.validate((...args) => validFn(args))
|
|
31
|
+
validateField(field, callback) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const ctx = h.getFieldCtx(field);
|
|
34
|
+
if (!ctx) return;
|
|
35
|
+
const sub = h.subForm[ctx.id];
|
|
36
|
+
const all = [h.$manager.validateField(ctx.id)];
|
|
37
|
+
toArray(sub).forEach(v => {
|
|
38
|
+
all.push(v.validate());
|
|
39
|
+
})
|
|
40
|
+
Promise.all(all).then(() => {
|
|
41
|
+
resolve(null);
|
|
42
|
+
callback && callback(null);
|
|
43
|
+
}).catch((e) => {
|
|
44
|
+
reject(e);
|
|
45
|
+
callback && callback(e);
|
|
46
|
+
})
|
|
80
47
|
});
|
|
81
|
-
|
|
82
|
-
if (!len) {
|
|
83
|
-
validate();
|
|
84
|
-
}
|
|
85
48
|
},
|
|
86
49
|
clearValidateState(fields, clearSub = true) {
|
|
87
50
|
api.helper.tidyFields(fields).forEach(field => {
|
|
88
51
|
if (clearSub) this.clearSubValidateState(field);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
52
|
+
h.getCtxs(field).forEach(ctx => {
|
|
53
|
+
h.$manager.clearValidateState(ctx);
|
|
54
|
+
});
|
|
92
55
|
});
|
|
93
56
|
},
|
|
94
57
|
clearSubValidateState(fields) {
|
|
95
58
|
api.helper.tidyFields(fields).forEach(field => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
subForm
|
|
104
|
-
|
|
59
|
+
h.getCtxs(field).forEach(ctx => {
|
|
60
|
+
const subForm = h.subForm[ctx.id];
|
|
61
|
+
if (!subForm) return;
|
|
62
|
+
if (Array.isArray(subForm)) {
|
|
63
|
+
subForm.forEach(form => {
|
|
64
|
+
form.clearValidateState();
|
|
65
|
+
})
|
|
66
|
+
} else if (subForm) {
|
|
67
|
+
subForm.clearValidateState();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
105
70
|
})
|
|
106
71
|
},
|
|
107
72
|
btn: {
|
|
@@ -139,18 +104,17 @@ export default function extendApi(api, h) {
|
|
|
139
104
|
api.refreshOptions();
|
|
140
105
|
},
|
|
141
106
|
submit(successFn, failFn) {
|
|
142
|
-
|
|
143
|
-
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
api.validate().then(() => {
|
|
144
109
|
let formData = api.formData();
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
110
|
+
is.Function(successFn) && invoke(() => successFn(formData, api));
|
|
111
|
+
is.Function(h.options.onSubmit) && invoke(() => h.options.onSubmit(formData, api));
|
|
112
|
+
h.vm.emit('submit', formData, api);
|
|
113
|
+
resolve(formData);
|
|
114
|
+
}).catch((...args) => {
|
|
115
|
+
is.Function(failFn) && invoke(() => failFn(api, ...args));
|
|
116
|
+
reject(...args)
|
|
117
|
+
})
|
|
154
118
|
});
|
|
155
119
|
},
|
|
156
120
|
});
|
package/src/core/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import FormCreateFactory from '@form-create/core/src/index';
|
|
|
6
6
|
import makers from './maker';
|
|
7
7
|
import '../style/index.css';
|
|
8
8
|
import extendApi from './api';
|
|
9
|
+
import ElementPlus from 'element-plus';
|
|
9
10
|
|
|
10
11
|
function install(FormCreate) {
|
|
11
12
|
FormCreate.componentAlias(alias);
|
|
@@ -23,11 +24,17 @@ function install(FormCreate) {
|
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
function appUse(app)
|
|
28
|
+
{
|
|
29
|
+
app.use(ElementPlus);
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
export default function elmFormCreate() {
|
|
27
33
|
return FormCreateFactory({
|
|
28
|
-
ui:
|
|
29
|
-
version:
|
|
34
|
+
ui:'process.env.UI',
|
|
35
|
+
version: 'process.env.VERSION',
|
|
30
36
|
manager,
|
|
37
|
+
appUse,
|
|
31
38
|
extendApi,
|
|
32
39
|
install,
|
|
33
40
|
attrs: {
|
package/src/core/manager.js
CHANGED
|
@@ -8,12 +8,6 @@ function isTooltip(info) {
|
|
|
8
8
|
return info.type === 'tooltip';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const upperCaseReg = /[A-Z]/;
|
|
12
|
-
|
|
13
|
-
export function isAttr(name, value) {
|
|
14
|
-
return (!upperCaseReg.test(name) && (is.String(value) || is.Number(value)))
|
|
15
|
-
}
|
|
16
|
-
|
|
17
11
|
function tidy(props, name) {
|
|
18
12
|
if (!hasProperty(props, name)) return;
|
|
19
13
|
if (is.String(props[name])) {
|
|
@@ -32,17 +26,20 @@ function tidyBool(opt, name) {
|
|
|
32
26
|
}
|
|
33
27
|
|
|
34
28
|
export default {
|
|
35
|
-
validate(
|
|
36
|
-
this.form().validate(
|
|
37
|
-
},
|
|
38
|
-
validateField(field
|
|
39
|
-
|
|
29
|
+
validate() {
|
|
30
|
+
return this.form().validate();
|
|
31
|
+
},
|
|
32
|
+
validateField(field) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
this.form().validateField(field, (res) => {
|
|
35
|
+
res ? reject(res) : resolve(null);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
40
38
|
},
|
|
41
39
|
clearValidateState(ctx) {
|
|
42
|
-
const fItem = this.vm
|
|
40
|
+
const fItem = this.vm.refs[ctx.wrapRef];
|
|
43
41
|
if (fItem) {
|
|
44
|
-
fItem.
|
|
45
|
-
fItem.validateState = '';
|
|
42
|
+
fItem.clearValidate();
|
|
46
43
|
}
|
|
47
44
|
},
|
|
48
45
|
tidyOptions(options) {
|
|
@@ -57,13 +54,7 @@ export default {
|
|
|
57
54
|
return prop;
|
|
58
55
|
},
|
|
59
56
|
mergeProp(ctx) {
|
|
60
|
-
let props = ctx.prop.props;
|
|
61
57
|
ctx.prop = mergeProps([{
|
|
62
|
-
attrs: Object.keys(props).reduce((initial, val) => {
|
|
63
|
-
if (isAttr(val, props[val]))
|
|
64
|
-
initial[val] = props[val];
|
|
65
|
-
return initial;
|
|
66
|
-
}, {}),
|
|
67
58
|
info: this.options.info || {},
|
|
68
59
|
wrap: this.options.wrap || {},
|
|
69
60
|
col: this.options.col || {},
|
|
@@ -85,7 +76,7 @@ export default {
|
|
|
85
76
|
const form = this.options.form;
|
|
86
77
|
this.rule = {
|
|
87
78
|
props: {...form},
|
|
88
|
-
|
|
79
|
+
on: {
|
|
89
80
|
submit: (e) => {
|
|
90
81
|
e.preventDefault();
|
|
91
82
|
}
|
|
@@ -100,14 +91,13 @@ export default {
|
|
|
100
91
|
extend(this.rule, {key, ref});
|
|
101
92
|
extend(this.rule.props, {
|
|
102
93
|
model: $handle.formData,
|
|
103
|
-
rules: $handle.validate(),
|
|
104
94
|
});
|
|
105
95
|
},
|
|
106
96
|
render(children) {
|
|
107
|
-
if (children.
|
|
108
|
-
children.
|
|
97
|
+
if (children.slotLen()) {
|
|
98
|
+
children.setSlot(undefined, () => this.makeFormBtn());
|
|
109
99
|
}
|
|
110
|
-
return this.$r(this.rule, isFalse(this.options.row.show) ? children : [this.makeRow(children)]);
|
|
100
|
+
return this.$r(this.rule, isFalse(this.options.row.show) ? children.getSlots() : [this.makeRow(children)]);
|
|
111
101
|
},
|
|
112
102
|
makeWrap(ctx, children) {
|
|
113
103
|
const rule = ctx.prop;
|
|
@@ -118,20 +108,21 @@ export default {
|
|
|
118
108
|
const {inline, col: _col} = this.rule.props;
|
|
119
109
|
const item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
|
|
120
110
|
props: {
|
|
121
|
-
label: rule.title.title,
|
|
122
111
|
labelWidth: labelWidth === void 0 ? labelWidth : toString(labelWidth),
|
|
112
|
+
label: isTitle ? rule.title.title : undefined,
|
|
123
113
|
...(rule.wrap || {}),
|
|
124
|
-
prop: ctx.
|
|
114
|
+
prop: ctx.id,
|
|
125
115
|
rules: rule.validate,
|
|
126
116
|
},
|
|
127
117
|
class: rule.className,
|
|
128
118
|
key: `${uni}fi`,
|
|
129
119
|
ref: ctx.wrapRef,
|
|
130
120
|
type: 'formItem',
|
|
131
|
-
}]),
|
|
121
|
+
}]), {default: () => children, ...(isTitle ? {label: () => this.makeInfo(rule, uni)} : {})});
|
|
132
122
|
return (inline === true || isFalse(_col) || isFalse(col.show)) ? item : this.makeCol(rule, uni, [item]);
|
|
133
123
|
},
|
|
134
124
|
isTitle(rule) {
|
|
125
|
+
if (this.options.form.title === false) return false;
|
|
135
126
|
const title = rule.title;
|
|
136
127
|
return !((!title.title && !title.native) || isFalse(title.show))
|
|
137
128
|
},
|
|
@@ -140,10 +131,9 @@ export default {
|
|
|
140
131
|
const infoProp = rule.info;
|
|
141
132
|
const isTip = isTooltip(infoProp);
|
|
142
133
|
const form = this.options.form;
|
|
143
|
-
const children = [titleProp.title + (form.labelSuffix || form['label-suffix'] || '')];
|
|
144
|
-
const titleFn = (
|
|
134
|
+
const children = [(titleProp.title || '') + (form.labelSuffix || form['label-suffix'] || '')];
|
|
135
|
+
const titleFn = () => this.$r(mergeProps([titleProp, {
|
|
145
136
|
props: titleProp,
|
|
146
|
-
slot: titleProp.slot || (pop ? (isTip ? 'default' : 'reference') : 'label'),
|
|
147
137
|
key: `${uni}tit`,
|
|
148
138
|
type: titleProp.type || 'span',
|
|
149
139
|
}]), children);
|
|
@@ -154,13 +144,12 @@ export default {
|
|
|
154
144
|
type: 'i',
|
|
155
145
|
class: infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
|
|
156
146
|
key: `${uni}i`
|
|
157
|
-
}));
|
|
147
|
+
}, {}, true));
|
|
158
148
|
}
|
|
159
149
|
const prop = {
|
|
160
150
|
type: infoProp.type || 'popover',
|
|
161
151
|
props: {...infoProp},
|
|
162
|
-
key: `${uni}pop
|
|
163
|
-
slot: 'label'
|
|
152
|
+
key: `${uni}pop`
|
|
164
153
|
};
|
|
165
154
|
|
|
166
155
|
const field = 'content';
|
|
@@ -168,9 +157,9 @@ export default {
|
|
|
168
157
|
prop.props[field] = infoProp.info;
|
|
169
158
|
}
|
|
170
159
|
|
|
171
|
-
return this.$r(mergeProps([infoProp, prop]),
|
|
172
|
-
titleFn(
|
|
173
|
-
|
|
160
|
+
return this.$r(mergeProps([infoProp, prop]), {
|
|
161
|
+
[titleProp.slot || (isTip ? 'default' : 'reference')]: () => titleFn()
|
|
162
|
+
})
|
|
174
163
|
}
|
|
175
164
|
return titleFn();
|
|
176
165
|
},
|
|
@@ -217,7 +206,9 @@ export default {
|
|
|
217
206
|
}, [item]);
|
|
218
207
|
},
|
|
219
208
|
makeResetBtn() {
|
|
220
|
-
const resetBtn = this.options.resetBtn;
|
|
209
|
+
const resetBtn = {...this.options.resetBtn};
|
|
210
|
+
const text = resetBtn.innerText;
|
|
211
|
+
delete resetBtn.innerText;
|
|
221
212
|
return this.$r({
|
|
222
213
|
type: 'button',
|
|
223
214
|
props: resetBtn,
|
|
@@ -231,10 +222,12 @@ export default {
|
|
|
231
222
|
}
|
|
232
223
|
},
|
|
233
224
|
key: `${this.key}b2`,
|
|
234
|
-
}, [
|
|
225
|
+
}, [text]);
|
|
235
226
|
},
|
|
236
227
|
makeSubmitBtn() {
|
|
237
|
-
const submitBtn = this.options.submitBtn;
|
|
228
|
+
const submitBtn = {...this.options.submitBtn};
|
|
229
|
+
const text = submitBtn.innerText;
|
|
230
|
+
delete submitBtn.innerText;
|
|
238
231
|
|
|
239
232
|
return this.$r({
|
|
240
233
|
type: 'button',
|
|
@@ -249,6 +242,6 @@ export default {
|
|
|
249
242
|
}
|
|
250
243
|
},
|
|
251
244
|
key: `${this.key}b1`,
|
|
252
|
-
}, [
|
|
245
|
+
}, [text]);
|
|
253
246
|
}
|
|
254
247
|
}
|
package/src/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {creatorFactory} from '@form-create/core/src/index';
|
|
2
2
|
|
|
3
3
|
const DEFAULT_FORMATS = {
|
|
4
|
-
date: '
|
|
5
|
-
month: '
|
|
6
|
-
datetime: '
|
|
7
|
-
week: 'yyyywWW',
|
|
4
|
+
date: 'YYYY-MM-DD',
|
|
5
|
+
month: 'YYYY-MM',
|
|
6
|
+
datetime: 'YYYY-MM-DD HH:mm:ss',
|
|
8
7
|
timerange: 'HH:mm:ss',
|
|
9
|
-
daterange: '
|
|
10
|
-
monthrange: '
|
|
11
|
-
datetimerange: '
|
|
12
|
-
year: '
|
|
8
|
+
daterange: 'YYYY-MM-DD',
|
|
9
|
+
monthrange: 'YYYY-MM',
|
|
10
|
+
datetimerange: 'YYYY-MM-DD HH:mm:ss',
|
|
11
|
+
year: 'YYYY'
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
const name = 'datePicker';
|
package/src/parsers/row.js
CHANGED