@form-create/element-ui 2.5.14 → 3.0.0-alpha.3

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/src/core/alias.js CHANGED
@@ -1,33 +1,33 @@
1
1
  const PRE = 'el';
2
2
  export default {
3
- button: PRE + 'Button',
3
+ button: PRE + '-button',
4
4
  icon: 'i',
5
- slider: PRE + 'Slider',
6
- rate: PRE + 'Rate',
7
- upload: 'fcUpload',
8
- cascader: PRE + 'Cascader',
9
- popover: PRE + 'Popover',
10
- tooltip: PRE + 'Tooltip',
11
- colorPicker: PRE + 'ColorPicker',
12
- timePicker: PRE + 'TimePicker',
13
- timeSelect: PRE + 'TimeSelect',
14
- datePicker: PRE + 'DatePicker',
15
- 'switch': PRE + 'Switch',
16
- select: 'fcSelect',
17
- checkbox: 'fcCheckbox',
18
- radio: 'fcRadio',
19
- inputNumber: PRE + 'InputNumber',
20
- number: PRE + 'InputNumber',
21
- input: PRE + 'Input',
22
- formItem: PRE + 'FormItem',
23
- form: PRE + 'Form',
24
- frame: 'fcFrame',
25
- col: PRE + 'Col',
26
- row: PRE + 'Row',
27
- tree: 'fcTree',
28
- autoComplete: PRE + 'Autocomplete',
29
- auto: PRE + 'Autocomplete',
30
- group: 'fcGroup',
31
- object: 'fcSubForm',
32
- subForm: 'fcSubForm',
5
+ slider: PRE + '-slider',
6
+ rate: PRE + '-rate',
7
+ upload: 'fc-upload',
8
+ cascader: PRE + '-cascader',
9
+ popover: PRE + '-popover',
10
+ tooltip: PRE + '-tooltip',
11
+ colorPicker: PRE + '-colorPicker',
12
+ timePicker: PRE + '-time-picker',
13
+ timeSelect: PRE + '-time-select',
14
+ datePicker: PRE + '-date-picker',
15
+ 'switch': PRE + '-switch',
16
+ select: 'fc-select',
17
+ checkbox: 'fc-checkbox',
18
+ radio: 'fc-radio',
19
+ inputNumber: PRE + '-input-number',
20
+ number: PRE + '-input-number',
21
+ input: PRE + '-input',
22
+ formItem: PRE + '-form-item',
23
+ form: PRE + '-form',
24
+ frame: 'fc-frame',
25
+ col: PRE + '-col',
26
+ row: PRE + '-row',
27
+ tree: 'fc-tree',
28
+ autoComplete: PRE + '-autocomplete',
29
+ auto: PRE + '-autocomplete',
30
+ group: 'fc-group',
31
+ object: 'fc-sub-form',
32
+ subForm: 'fc-sub-form',
33
33
  }
package/src/core/api.js CHANGED
@@ -13,75 +13,38 @@ function tidyBtnProp(btn, def) {
13
13
  export default function extendApi(api, h) {
14
14
  extend(api, {
15
15
  validate(callback) {
16
- let flag;
17
- const forms = api.children;
18
- let len = forms.length;
19
- const validate = () => {
20
- h.$manager.validate((...args) => {
21
- if (!args[0] || !flag) {
22
- flag = args;
23
- }
24
- callback && callback(...flag);
25
- });
26
- };
27
-
28
- const validFn = (args) => {
29
- setTimeout(() => {
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: (field, callback) => {
50
- const ctx = h.getFieldCtx(field);
51
- if (!ctx) return;
52
- const sub = h.subForm[ctx.id];
53
- let len = 0;
54
- let flag;
55
- const validate = () => {
56
- h.$manager.validateField(ctx.id, (...args) => {
57
- if (args[0]) {
58
- flag = args;
59
- } else if (flag) {
60
- return callback && callback('子表单验证未通过', flag[1]);
61
- }
62
- callback && callback(...flag || args);
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 => {
@@ -141,18 +104,17 @@ export default function extendApi(api, h) {
141
104
  api.refreshOptions();
142
105
  },
143
106
  submit(successFn, failFn) {
144
- api.validate((valid) => {
145
- if (valid) {
107
+ return new Promise((resolve, reject) => {
108
+ api.validate().then(() => {
146
109
  let formData = api.formData();
147
- if (is.Function(successFn))
148
- invoke(() => successFn(formData, this));
149
- else {
150
- is.Function(h.options.onSubmit) && invoke(() => h.options.onSubmit(formData, this));
151
- h.vm.$emit('submit', formData, this);
152
- }
153
- } else {
154
- is.Function(failFn) && invoke(() => failFn(this, ...arguments));
155
- }
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
+ })
156
118
  });
157
119
  },
158
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: `${process.env.UI}`,
29
- version: `${process.env.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: {
@@ -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(call) {
36
- this.form().validate(call);
37
- },
38
- validateField(field, call) {
39
- this.form().validateField(field, call);
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.$refs[ctx.wrapRef];
40
+ const fItem = this.vm.refs[ctx.wrapRef];
43
41
  if (fItem) {
44
- fItem.validateMessage = '';
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
- nativeOn: {
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.length) {
108
- children.push(this.makeFormBtn());
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;
@@ -128,7 +118,7 @@ export default {
128
118
  key: `${uni}fi`,
129
119
  ref: ctx.wrapRef,
130
120
  type: 'formItem',
131
- }]), [children, isTitle ? this.makeInfo(rule, uni) : null]);
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) {
@@ -147,25 +137,29 @@ export default {
147
137
  const prop = {
148
138
  type: infoProp.type || 'popover',
149
139
  props: {...infoProp},
150
- key: `${uni}pop`,
151
- slot: 'label'
140
+ key: `${uni}pop`
152
141
  };
142
+
143
+ delete prop.props.icon;
144
+ delete prop.props.show;
145
+ delete prop.props.info;
146
+
153
147
  const field = 'content';
154
148
  if (infoProp.info && !hasProperty(prop.props, field)) {
155
149
  prop.props[field] = infoProp.info;
156
150
  }
157
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), [
158
- this.$r({
151
+
152
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), {
153
+ [titleProp.slot || (isTip ? 'default' : 'reference')]: () => this.$r({
159
154
  type: 'i',
160
- slot: isTip ? 'default' : 'reference',
161
155
  class: infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
162
156
  key: `${uni}i`
163
- })
164
- ]));
157
+ }, {}, true)
158
+ }));
165
159
  }
160
+
166
161
  return this.$r(mergeProps([titleProp, {
167
162
  props: titleProp,
168
- slot: titleProp.slot || 'label',
169
163
  key: `${uni}tit`,
170
164
  type: titleProp.type || 'span',
171
165
  }]), children);
@@ -213,7 +207,9 @@ export default {
213
207
  }, [item]);
214
208
  },
215
209
  makeResetBtn() {
216
- const resetBtn = this.options.resetBtn;
210
+ const resetBtn = {...this.options.resetBtn};
211
+ const text = resetBtn.innerText;
212
+ delete resetBtn.innerText;
217
213
  return this.$r({
218
214
  type: 'button',
219
215
  props: resetBtn,
@@ -227,10 +223,12 @@ export default {
227
223
  }
228
224
  },
229
225
  key: `${this.key}b2`,
230
- }, [resetBtn.innerText]);
226
+ }, [text]);
231
227
  },
232
228
  makeSubmitBtn() {
233
- const submitBtn = this.options.submitBtn;
229
+ const submitBtn = {...this.options.submitBtn};
230
+ const text = submitBtn.innerText;
231
+ delete submitBtn.innerText;
234
232
 
235
233
  return this.$r({
236
234
  type: 'button',
@@ -245,6 +243,6 @@ export default {
245
243
  }
246
244
  },
247
245
  key: `${this.key}b1`,
248
- }, [submitBtn.innerText]);
246
+ }, [text]);
249
247
  }
250
248
  }
package/src/index.js CHANGED
@@ -4,9 +4,6 @@ const FormCreate = elmFormCreate();
4
4
 
5
5
  if (typeof window !== 'undefined') {
6
6
  window.formCreate = FormCreate;
7
- if (window.Vue) {
8
- FormCreate.install(window.Vue);
9
- }
10
7
  }
11
8
 
12
9
  const maker = FormCreate.maker;
@@ -1,15 +1,14 @@
1
1
  import {creatorFactory} from '@form-create/core/src/index';
2
2
 
3
3
  const DEFAULT_FORMATS = {
4
- date: 'yyyy-MM-dd',
5
- month: 'yyyy-MM',
6
- datetime: 'yyyy-MM-dd HH:mm:ss',
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: 'yyyy-MM-dd',
10
- monthrange: 'yyyy-MM',
11
- datetimerange: 'yyyy-MM-dd HH:mm:ss',
12
- year: 'yyyy'
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';
@@ -1,8 +1,10 @@
1
1
  export default {
2
2
  name: 'FcRow',
3
3
  render(_, ctx) {
4
- return ctx.vNode.col({props: {span: 24}}, [
5
- ctx.vNode.row(ctx.prop, _)
6
- ])
4
+ return ctx.vNode.col({props: {span: 24}}, {
5
+ default:()=>[
6
+ ctx.vNode.row(ctx.prop, _)
7
+ ]
8
+ })
7
9
  }
8
- }
10
+ }