@form-create/element-ui 3.1.11 → 3.1.14

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @form-create/element-ui
2
- **form-create 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的表单生成组件。支持3个UI框架,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。**
2
+ **form-create 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的表单生成组件。支持5个UI框架,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。**
3
3
 
4
- form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON. Supports 3 UI frameworks, and supports the generation of any Vue components. Built-in 20 kinds of commonly used form components and custom components, no matter how complex forms can be easily handled.
4
+ form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON. Supports 5 UI frameworks, and supports the generation of any Vue components. Built-in 20 kinds of commonly used form components and custom components, no matter how complex forms can be easily handled.
5
5
 
6
6
  > form-create element-ui 动态表单组件
7
7
  >
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @form-create/element-ui v3.1.11
2
+ * @form-create/element-ui v3.1.14
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -1493,7 +1493,7 @@ var Group = defineComponent({
1493
1493
  form: markRaw(this.formCreateInject.form.$form())
1494
1494
  };
1495
1495
  },
1496
- emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
1496
+ emits: ['update:modelValue', 'change', 'itemMounted', 'remove', 'add'],
1497
1497
  watch: {
1498
1498
  rule: {
1499
1499
  handler: function handler(n, o) {
@@ -1549,7 +1549,7 @@ var Group = defineComponent({
1549
1549
 
1550
1550
  if (len < 0) {
1551
1551
  for (var i = len; i < 0; i++) {
1552
- this.addRule(n.length + i);
1552
+ this.addRule(n.length + i, true);
1553
1553
  }
1554
1554
 
1555
1555
  for (var _i = 0; _i < total; _i++) {
@@ -1792,31 +1792,27 @@ var Group = defineComponent({
1792
1792
  "span": button ? 20 : 24
1793
1793
  }, {
1794
1794
  "default": function _default() {
1795
- return [createVNode(resolveComponent("ElFormItem"), null, {
1796
- "default": function _default() {
1797
- return [createVNode(Type, {
1798
- "key": key,
1799
- "inFor": true,
1800
- "onUpdate:modelValue": function onUpdateModelValue(formData) {
1801
- return _this9.formData(key, formData);
1802
- },
1803
- "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1804
- "onEmit-event": function onEmitEvent(name) {
1805
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1806
- args[_key - 1] = arguments[_key];
1807
- }
1808
-
1809
- return _this9.emitEvent(name, args, index, key);
1810
- },
1811
- "onUpdate:api": function onUpdateApi($f) {
1812
- return _this9.add$f(index, key, $f);
1813
- },
1814
- "rule": rule,
1815
- "option": options,
1816
- "extendOption": true
1817
- }, null)];
1818
- }
1819
- })];
1795
+ return [createVNode(Type, {
1796
+ "key": key,
1797
+ "inFor": true,
1798
+ "onUpdate:modelValue": function onUpdateModelValue(formData) {
1799
+ return _this9.formData(key, formData);
1800
+ },
1801
+ "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1802
+ "onEmit-event": function onEmitEvent(name) {
1803
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1804
+ args[_key - 1] = arguments[_key];
1805
+ }
1806
+
1807
+ return _this9.emitEvent(name, args, index, key);
1808
+ },
1809
+ "onUpdate:api": function onUpdateApi($f) {
1810
+ return _this9.add$f(index, key, $f);
1811
+ },
1812
+ "rule": rule,
1813
+ "option": options,
1814
+ "extendOption": true
1815
+ }, null)];
1820
1816
  }
1821
1817
  }), button ? createVNode(resolveComponent("ElCol"), {
1822
1818
  "span": 2,
@@ -2075,13 +2071,17 @@ function $FormCreate(FormCreate) {
2075
2071
  fc.$handle.reloadRule(rule.value);
2076
2072
  vm.setupState.renderRule();
2077
2073
  });
2078
- watch(props.option, function (n) {
2074
+ watch(function () {
2075
+ return props.option;
2076
+ }, function (n) {
2079
2077
  fc.initOptions(n);
2080
2078
  fapi.refresh();
2079
+ }, {
2080
+ deep: true
2081
2081
  });
2082
2082
  watch(modelValue, function (n) {
2083
2083
  if (JSON.stringify(n || {}) === data.updateValue) return;
2084
- fapi.setValue(n || {});
2084
+ fapi.config.forceCoverValue ? fapi.coverValue(n || {}) : fapi.setValue(n || {});
2085
2085
  }, {
2086
2086
  deep: true
2087
2087
  });
@@ -2297,7 +2297,13 @@ function mergeRule(rule, merge) {
2297
2297
  return rule;
2298
2298
  }
2299
2299
  function getRule(rule) {
2300
- return is.Function(rule.getRule) ? rule.getRule() : rule;
2300
+ var r = is.Function(rule.getRule) ? rule.getRule() : rule;
2301
+
2302
+ if (!r.type) {
2303
+ r.type = 'input';
2304
+ }
2305
+
2306
+ return r;
2301
2307
  }
2302
2308
  function mergeGlobal(target, merge) {
2303
2309
  if (!target) return merge;
@@ -2576,15 +2582,21 @@ function Api(h) {
2576
2582
  return copy(ctx.rule.value);
2577
2583
  },
2578
2584
  coverValue: function coverValue(formData) {
2585
+ var data = _objectSpread2({}, formData || {});
2586
+
2579
2587
  h.deferSyncValue(function () {
2580
2588
  api.fields().forEach(function (key) {
2581
2589
  var ctxs = h.fieldCtx[key];
2582
- if (!ctxs) return h.appendData[key] = formData[key];
2583
- var flag = hasProperty(formData, key);
2584
- ctxs.forEach(function (ctx) {
2585
- ctx.rule.value = flag ? formData[key] : undefined;
2586
- });
2590
+
2591
+ if (ctxs) {
2592
+ var flag = hasProperty(formData, key);
2593
+ ctxs.forEach(function (ctx) {
2594
+ ctx.rule.value = flag ? formData[key] : undefined;
2595
+ });
2596
+ delete data[key];
2597
+ }
2587
2598
  });
2599
+ extend(h.appendData, data);
2588
2600
  });
2589
2601
  },
2590
2602
  setValue: function setValue(field) {
@@ -2817,6 +2829,18 @@ function Api(h) {
2817
2829
  $set(ctx.rule.effect, attr, value);
2818
2830
  }
2819
2831
  },
2832
+ clearEffectData: function clearEffectData(id, attr) {
2833
+ var ctx = h.getCtx(id);
2834
+
2835
+ if (ctx) {
2836
+ if (attr && attr[0] === '$') {
2837
+ attr = attr.substr(1);
2838
+ }
2839
+
2840
+ ctx.clearEffectData(attr);
2841
+ api.sync(id);
2842
+ }
2843
+ },
2820
2844
  updateValidate: function updateValidate(id, validate, merge) {
2821
2845
  if (merge) {
2822
2846
  api.mergeRule(id, {
@@ -2949,8 +2973,13 @@ function useCache(Render) {
2949
2973
  },
2950
2974
  getCache: function getCache(ctx) {
2951
2975
  var cache = this.cache[ctx.id];
2952
- cache.use = true;
2953
- return cache.vnode;
2976
+
2977
+ if (cache) {
2978
+ cache.use = true;
2979
+ return cache.vnode;
2980
+ }
2981
+
2982
+ return undefined;
2954
2983
  }
2955
2984
  });
2956
2985
  }
@@ -3621,7 +3650,7 @@ function bind(ctx) {
3621
3650
  });
3622
3651
  }
3623
3652
 
3624
- function RuleContext(handle, rule) {
3653
+ function RuleContext(handle, rule, defaultValue) {
3625
3654
  var id = uniqueId();
3626
3655
  var isInput = !!rule.field;
3627
3656
  extend(this, {
@@ -3645,7 +3674,7 @@ function RuleContext(handle, rule) {
3645
3674
  refRule: {},
3646
3675
  input: isInput,
3647
3676
  el: undefined,
3648
- defaultValue: isInput ? deepCopy(rule.value) : undefined,
3677
+ defaultValue: isInput ? deepCopy(defaultValue) : undefined,
3649
3678
  field: rule.field || undefined
3650
3679
  });
3651
3680
  this.updateType();
@@ -3758,7 +3787,11 @@ extend(RuleContext.prototype, {
3758
3787
  return this.payload[name];
3759
3788
  },
3760
3789
  clearEffectData: function clearEffectData(name) {
3761
- delete this.payload[name];
3790
+ if (name === undefined) {
3791
+ this.payload = {};
3792
+ } else {
3793
+ delete this.payload[name];
3794
+ }
3762
3795
  },
3763
3796
  updateKey: function updateKey(flag) {
3764
3797
  this.key = uniqueId();
@@ -4019,7 +4052,6 @@ function useLoader(Handler) {
4019
4052
  rules.map(function (_rule, index) {
4020
4053
  if (parent && (is.String(_rule) || is.Undef(_rule))) return;
4021
4054
  if (!_this6.pageEnd && !parent && index >= _this6.first) return;
4022
- if (!is.Object(_rule) || !getRule(_rule).type) return err('未定义生成规则的 type 字段', _rule);
4023
4055
 
4024
4056
  if (_rule.__fc__ && _rule.__fc__.root === rules && _this6.ctxs[_rule.__fc__.id]) {
4025
4057
  loadChildren(_rule.__fc__.loadChildrenPending(), _rule.__fc__);
@@ -4043,9 +4075,11 @@ function useLoader(Handler) {
4043
4075
  var ctx;
4044
4076
  var isCopy = false;
4045
4077
  var isInit = !!_rule.__fc__;
4078
+ var defaultValue = rule.value;
4046
4079
 
4047
4080
  if (isInit) {
4048
4081
  ctx = _rule.__fc__;
4082
+ defaultValue = ctx.defaultValue;
4049
4083
  var check = !ctx.check(_this6);
4050
4084
 
4051
4085
  if (ctx.deleted) {
@@ -4070,7 +4104,9 @@ function useLoader(Handler) {
4070
4104
  }
4071
4105
 
4072
4106
  if (!ctx) {
4073
- ctx = new RuleContext(_this6, _this6.parseRule(_rule));
4107
+ var _rule2 = _this6.parseRule(_rule);
4108
+
4109
+ ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
4074
4110
 
4075
4111
  _this6.bindParser(ctx);
4076
4112
  } else {
@@ -4318,7 +4354,7 @@ function useInput(Handler) {
4318
4354
  }
4319
4355
  },
4320
4356
  setFormData: function setFormData(ctx, value) {
4321
- $set(this.formData, ctx.id, value === null ? undefined : value);
4357
+ $set(this.formData, ctx.id, value);
4322
4358
  },
4323
4359
  getFormData: function getFormData(ctx) {
4324
4360
  return this.formData[ctx.id];
@@ -4621,7 +4657,6 @@ function useContext(Handler) {
4621
4657
  return val.value;
4622
4658
  }, function () {
4623
4659
  var formValue = ctx.parser.toFormValue(val.value, ctx);
4624
- formValue = formValue === null ? undefined : formValue;
4625
4660
 
4626
4661
  if (_this.isChange(ctx, formValue)) {
4627
4662
  _this.setValue(ctx, val.value, formValue, true);
@@ -4768,6 +4803,11 @@ function useEffect(Handler) {
4768
4803
  var ps = this.fc.providers;
4769
4804
  Object.keys(ps).forEach(function (k) {
4770
4805
  var prop = ps[k];
4806
+
4807
+ if (is.Function(prop)) {
4808
+ prop = prop(_this.fc);
4809
+ }
4810
+
4771
4811
  prop._c = getComponent(prop);
4772
4812
 
4773
4813
  _this.onEffect(prop);
@@ -5001,7 +5041,7 @@ function getBody(xhr) {
5001
5041
  }
5002
5042
  }
5003
5043
 
5004
- function fetch(option) {
5044
+ function fetch$1(option) {
5005
5045
  if (typeof XMLHttpRequest === 'undefined') {
5006
5046
  return;
5007
5047
  }
@@ -5214,90 +5254,103 @@ extend(Manager.prototype, {
5214
5254
  render: function render(children) {}
5215
5255
  });
5216
5256
 
5217
- var $fetch = {
5218
- name: 'fetch',
5219
- loaded: function loaded() {
5220
- run.apply(void 0, arguments);
5221
- },
5222
- watch: function watch(inject, rule, api) {
5223
- if (!run(inject, rule, api)) {
5224
- inject.clearProp();
5225
- api.sync(rule);
5257
+ var fetch = function fetch(fc) {
5258
+ function parseOpt(option) {
5259
+ if (is.String(option)) {
5260
+ option = {
5261
+ action: option,
5262
+ to: 'options'
5263
+ };
5226
5264
  }
5227
- }
5228
- };
5229
5265
 
5230
- function parseOpt(option) {
5231
- if (is.String(option)) {
5232
- option = {
5233
- action: option,
5234
- to: 'options'
5235
- };
5266
+ return option;
5236
5267
  }
5237
5268
 
5238
- return option;
5239
- }
5269
+ function run(inject, rule, api) {
5270
+ var option = inject.value;
5240
5271
 
5241
- function run(inject, rule, api) {
5242
- var option = inject.value;
5272
+ if (is.Function(option)) {
5273
+ option = option(rule, api);
5274
+ }
5243
5275
 
5244
- if (is.Function(option)) {
5245
- option = option(rule, api);
5246
- }
5276
+ option = parseOpt(option);
5247
5277
 
5248
- option = parseOpt(option);
5278
+ if (!option || !option.action) {
5279
+ return false;
5280
+ }
5249
5281
 
5250
- if (!option || !option.action) {
5251
- return false;
5252
- }
5282
+ if (!option.to) {
5283
+ option.to = 'options';
5284
+ }
5253
5285
 
5254
- if (!option.to) {
5255
- option.to = 'options';
5256
- }
5286
+ var _onError = option.onError;
5257
5287
 
5258
- var _onError = option.onError;
5288
+ var check = function check() {
5289
+ if (!inject.getValue()) {
5290
+ inject.clearProp();
5291
+ api.sync(rule);
5292
+ return true;
5293
+ }
5294
+ };
5259
5295
 
5260
- var check = function check() {
5261
- if (!inject.getValue()) {
5262
- inject.clearProp();
5263
- api.sync(rule);
5264
- return true;
5265
- }
5266
- };
5296
+ var set = function set(val) {
5297
+ if (val === undefined) {
5298
+ inject.clearProp();
5299
+ api.sync(rule);
5300
+ } else {
5301
+ deepSet(inject.getProp(), option.to, val);
5302
+ }
5303
+ };
5267
5304
 
5268
- var set = function set(val) {
5269
- if (val === undefined) {
5270
- inject.clearProp();
5271
- api.sync(rule);
5272
- } else {
5273
- deepSet(inject.getProp(), option.to, val);
5274
- }
5275
- };
5305
+ invoke(function () {
5306
+ return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5307
+ onSuccess: function onSuccess(body) {
5308
+ if (check()) return;
5276
5309
 
5277
- invoke(function () {
5278
- return fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5279
- onSuccess: function onSuccess(body) {
5280
- if (check()) return;
5281
- set((option.parse || function (v) {
5282
- return v.data;
5283
- })(body, rule, api));
5284
- api.sync(rule);
5285
- },
5286
- onError: function onError(e) {
5287
- set(undefined);
5288
- if (check()) return;
5310
+ var fn = function fn(v) {
5311
+ return v.data;
5312
+ };
5313
+
5314
+ if (is.Function(option.parse)) {
5315
+ fn = option.parse;
5316
+ }
5289
5317
 
5290
- (_onError || function (e) {
5291
- return err(e.message || 'fetch fail ' + option.action);
5292
- })(e, rule, api);
5318
+ set(fn(body, rule, api));
5319
+ api.sync(rule);
5320
+ },
5321
+ onError: function onError(e) {
5322
+ set(undefined);
5323
+ if (check()) return;
5324
+
5325
+ (_onError || function (e) {
5326
+ return err(e.message || 'fetch fail ' + option.action);
5327
+ })(e, rule, api);
5328
+ }
5329
+ }), {
5330
+ inject: inject,
5331
+ rule: rule,
5332
+ api: api
5333
+ });
5334
+ });
5335
+ return true;
5336
+ }
5337
+
5338
+ return {
5339
+ name: 'fetch',
5340
+ loaded: function loaded() {
5341
+ run.apply(void 0, arguments);
5342
+ },
5343
+ watch: function watch(inject, rule, api) {
5344
+ if (!run(inject, rule, api)) {
5345
+ inject.clearProp();
5346
+ api.sync(rule);
5293
5347
  }
5294
- }));
5295
- });
5296
- return true;
5297
- }
5348
+ }
5349
+ };
5350
+ };
5298
5351
 
5299
5352
  var $provider = {
5300
- fetch: $fetch
5353
+ fetch: fetch
5301
5354
  };
5302
5355
 
5303
5356
  var name$6 = 'html';
@@ -5645,7 +5698,7 @@ function FormCreateFactory(config) {
5645
5698
  componentAlias: componentAlias,
5646
5699
  copyRule: copyRule,
5647
5700
  copyRules: copyRules,
5648
- fetch: fetch,
5701
+ fetch: fetch$1,
5649
5702
  $form: $form,
5650
5703
  parseFn: parseFn,
5651
5704
  parseJson: parseJson,
@@ -5940,6 +5993,13 @@ function tidyBool(opt, name) {
5940
5993
  }
5941
5994
  }
5942
5995
 
5996
+ function tidyRule(rule) {
5997
+ var _rule = _objectSpread2({}, rule);
5998
+
5999
+ delete _rule.children;
6000
+ return _rule;
6001
+ }
6002
+
5943
6003
  var manager = {
5944
6004
  validate: function validate() {
5945
6005
  var form = this.form();
@@ -6099,7 +6159,7 @@ var manager = {
6099
6159
  if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
6100
6160
  var prop = {
6101
6161
  type: infoProp.type || 'popover',
6102
- props: _objectSpread2({}, infoProp),
6162
+ props: tidyRule(infoProp),
6103
6163
  key: "".concat(uni, "pop")
6104
6164
  };
6105
6165
  delete prop.props.icon;
@@ -6129,7 +6189,7 @@ var manager = {
6129
6189
  }
6130
6190
 
6131
6191
  var _prop = mergeProps([titleProp, {
6132
- props: titleProp,
6192
+ props: tidyRule(titleProp),
6133
6193
  key: "".concat(uni, "tit"),
6134
6194
  type: titleProp.type || 'span'
6135
6195
  }]);
@@ -6497,7 +6557,8 @@ var required = {
6497
6557
  }, val);
6498
6558
 
6499
6559
  if (!validate.message) {
6500
- validate.message = rule.title + '不能为空';
6560
+ var title = rule.title || '';
6561
+ validate.message = ((_typeof(title) === 'object' ? title.title : title) || '') + '不能为空';
6501
6562
  }
6502
6563
 
6503
6564
  inject.getProp().validate = [validate];
@@ -6553,7 +6614,7 @@ function install(FormCreate) {
6553
6614
  function elmFormCreate() {
6554
6615
  return FormCreateFactory({
6555
6616
  ui: 'element-ui',
6556
- version: '3.1.11',
6617
+ version: '3.1.14',
6557
6618
  manager: manager,
6558
6619
  extendApi: extendApi,
6559
6620
  install: install,