@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.
@@ -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.
@@ -1497,7 +1497,7 @@
1497
1497
  form: vue.markRaw(this.formCreateInject.form.$form())
1498
1498
  };
1499
1499
  },
1500
- emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
1500
+ emits: ['update:modelValue', 'change', 'itemMounted', 'remove', 'add'],
1501
1501
  watch: {
1502
1502
  rule: {
1503
1503
  handler: function handler(n, o) {
@@ -1553,7 +1553,7 @@
1553
1553
 
1554
1554
  if (len < 0) {
1555
1555
  for (var i = len; i < 0; i++) {
1556
- this.addRule(n.length + i);
1556
+ this.addRule(n.length + i, true);
1557
1557
  }
1558
1558
 
1559
1559
  for (var _i = 0; _i < total; _i++) {
@@ -1796,31 +1796,27 @@
1796
1796
  "span": button ? 20 : 24
1797
1797
  }, {
1798
1798
  "default": function _default() {
1799
- return [vue.createVNode(vue.resolveComponent("ElFormItem"), null, {
1800
- "default": function _default() {
1801
- return [vue.createVNode(Type, {
1802
- "key": key,
1803
- "inFor": true,
1804
- "onUpdate:modelValue": function onUpdateModelValue(formData) {
1805
- return _this9.formData(key, formData);
1806
- },
1807
- "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1808
- "onEmit-event": function onEmitEvent(name) {
1809
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1810
- args[_key - 1] = arguments[_key];
1811
- }
1812
-
1813
- return _this9.emitEvent(name, args, index, key);
1814
- },
1815
- "onUpdate:api": function onUpdateApi($f) {
1816
- return _this9.add$f(index, key, $f);
1817
- },
1818
- "rule": rule,
1819
- "option": options,
1820
- "extendOption": true
1821
- }, null)];
1822
- }
1823
- })];
1799
+ return [vue.createVNode(Type, {
1800
+ "key": key,
1801
+ "inFor": true,
1802
+ "onUpdate:modelValue": function onUpdateModelValue(formData) {
1803
+ return _this9.formData(key, formData);
1804
+ },
1805
+ "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1806
+ "onEmit-event": function onEmitEvent(name) {
1807
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1808
+ args[_key - 1] = arguments[_key];
1809
+ }
1810
+
1811
+ return _this9.emitEvent(name, args, index, key);
1812
+ },
1813
+ "onUpdate:api": function onUpdateApi($f) {
1814
+ return _this9.add$f(index, key, $f);
1815
+ },
1816
+ "rule": rule,
1817
+ "option": options,
1818
+ "extendOption": true
1819
+ }, null)];
1824
1820
  }
1825
1821
  }), button ? vue.createVNode(vue.resolveComponent("ElCol"), {
1826
1822
  "span": 2,
@@ -2079,13 +2075,17 @@
2079
2075
  fc.$handle.reloadRule(rule.value);
2080
2076
  vm.setupState.renderRule();
2081
2077
  });
2082
- vue.watch(props.option, function (n) {
2078
+ vue.watch(function () {
2079
+ return props.option;
2080
+ }, function (n) {
2083
2081
  fc.initOptions(n);
2084
2082
  fapi.refresh();
2083
+ }, {
2084
+ deep: true
2085
2085
  });
2086
2086
  vue.watch(modelValue, function (n) {
2087
2087
  if (JSON.stringify(n || {}) === data.updateValue) return;
2088
- fapi.setValue(n || {});
2088
+ fapi.config.forceCoverValue ? fapi.coverValue(n || {}) : fapi.setValue(n || {});
2089
2089
  }, {
2090
2090
  deep: true
2091
2091
  });
@@ -2301,7 +2301,13 @@
2301
2301
  return rule;
2302
2302
  }
2303
2303
  function getRule(rule) {
2304
- return is.Function(rule.getRule) ? rule.getRule() : rule;
2304
+ var r = is.Function(rule.getRule) ? rule.getRule() : rule;
2305
+
2306
+ if (!r.type) {
2307
+ r.type = 'input';
2308
+ }
2309
+
2310
+ return r;
2305
2311
  }
2306
2312
  function mergeGlobal(target, merge) {
2307
2313
  if (!target) return merge;
@@ -2580,15 +2586,21 @@
2580
2586
  return copy(ctx.rule.value);
2581
2587
  },
2582
2588
  coverValue: function coverValue(formData) {
2589
+ var data = _objectSpread2({}, formData || {});
2590
+
2583
2591
  h.deferSyncValue(function () {
2584
2592
  api.fields().forEach(function (key) {
2585
2593
  var ctxs = h.fieldCtx[key];
2586
- if (!ctxs) return h.appendData[key] = formData[key];
2587
- var flag = hasProperty(formData, key);
2588
- ctxs.forEach(function (ctx) {
2589
- ctx.rule.value = flag ? formData[key] : undefined;
2590
- });
2594
+
2595
+ if (ctxs) {
2596
+ var flag = hasProperty(formData, key);
2597
+ ctxs.forEach(function (ctx) {
2598
+ ctx.rule.value = flag ? formData[key] : undefined;
2599
+ });
2600
+ delete data[key];
2601
+ }
2591
2602
  });
2603
+ extend(h.appendData, data);
2592
2604
  });
2593
2605
  },
2594
2606
  setValue: function setValue(field) {
@@ -2821,6 +2833,18 @@
2821
2833
  $set(ctx.rule.effect, attr, value);
2822
2834
  }
2823
2835
  },
2836
+ clearEffectData: function clearEffectData(id, attr) {
2837
+ var ctx = h.getCtx(id);
2838
+
2839
+ if (ctx) {
2840
+ if (attr && attr[0] === '$') {
2841
+ attr = attr.substr(1);
2842
+ }
2843
+
2844
+ ctx.clearEffectData(attr);
2845
+ api.sync(id);
2846
+ }
2847
+ },
2824
2848
  updateValidate: function updateValidate(id, validate, merge) {
2825
2849
  if (merge) {
2826
2850
  api.mergeRule(id, {
@@ -2953,8 +2977,13 @@
2953
2977
  },
2954
2978
  getCache: function getCache(ctx) {
2955
2979
  var cache = this.cache[ctx.id];
2956
- cache.use = true;
2957
- return cache.vnode;
2980
+
2981
+ if (cache) {
2982
+ cache.use = true;
2983
+ return cache.vnode;
2984
+ }
2985
+
2986
+ return undefined;
2958
2987
  }
2959
2988
  });
2960
2989
  }
@@ -3625,7 +3654,7 @@
3625
3654
  });
3626
3655
  }
3627
3656
 
3628
- function RuleContext(handle, rule) {
3657
+ function RuleContext(handle, rule, defaultValue) {
3629
3658
  var id = uniqueId();
3630
3659
  var isInput = !!rule.field;
3631
3660
  extend(this, {
@@ -3649,7 +3678,7 @@
3649
3678
  refRule: {},
3650
3679
  input: isInput,
3651
3680
  el: undefined,
3652
- defaultValue: isInput ? deepCopy(rule.value) : undefined,
3681
+ defaultValue: isInput ? deepCopy(defaultValue) : undefined,
3653
3682
  field: rule.field || undefined
3654
3683
  });
3655
3684
  this.updateType();
@@ -3762,7 +3791,11 @@
3762
3791
  return this.payload[name];
3763
3792
  },
3764
3793
  clearEffectData: function clearEffectData(name) {
3765
- delete this.payload[name];
3794
+ if (name === undefined) {
3795
+ this.payload = {};
3796
+ } else {
3797
+ delete this.payload[name];
3798
+ }
3766
3799
  },
3767
3800
  updateKey: function updateKey(flag) {
3768
3801
  this.key = uniqueId();
@@ -4023,7 +4056,6 @@
4023
4056
  rules.map(function (_rule, index) {
4024
4057
  if (parent && (is.String(_rule) || is.Undef(_rule))) return;
4025
4058
  if (!_this6.pageEnd && !parent && index >= _this6.first) return;
4026
- if (!is.Object(_rule) || !getRule(_rule).type) return err('未定义生成规则的 type 字段', _rule);
4027
4059
 
4028
4060
  if (_rule.__fc__ && _rule.__fc__.root === rules && _this6.ctxs[_rule.__fc__.id]) {
4029
4061
  loadChildren(_rule.__fc__.loadChildrenPending(), _rule.__fc__);
@@ -4047,9 +4079,11 @@
4047
4079
  var ctx;
4048
4080
  var isCopy = false;
4049
4081
  var isInit = !!_rule.__fc__;
4082
+ var defaultValue = rule.value;
4050
4083
 
4051
4084
  if (isInit) {
4052
4085
  ctx = _rule.__fc__;
4086
+ defaultValue = ctx.defaultValue;
4053
4087
  var check = !ctx.check(_this6);
4054
4088
 
4055
4089
  if (ctx.deleted) {
@@ -4074,7 +4108,9 @@
4074
4108
  }
4075
4109
 
4076
4110
  if (!ctx) {
4077
- ctx = new RuleContext(_this6, _this6.parseRule(_rule));
4111
+ var _rule2 = _this6.parseRule(_rule);
4112
+
4113
+ ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
4078
4114
 
4079
4115
  _this6.bindParser(ctx);
4080
4116
  } else {
@@ -4322,7 +4358,7 @@
4322
4358
  }
4323
4359
  },
4324
4360
  setFormData: function setFormData(ctx, value) {
4325
- $set(this.formData, ctx.id, value === null ? undefined : value);
4361
+ $set(this.formData, ctx.id, value);
4326
4362
  },
4327
4363
  getFormData: function getFormData(ctx) {
4328
4364
  return this.formData[ctx.id];
@@ -4625,7 +4661,6 @@
4625
4661
  return val.value;
4626
4662
  }, function () {
4627
4663
  var formValue = ctx.parser.toFormValue(val.value, ctx);
4628
- formValue = formValue === null ? undefined : formValue;
4629
4664
 
4630
4665
  if (_this.isChange(ctx, formValue)) {
4631
4666
  _this.setValue(ctx, val.value, formValue, true);
@@ -4772,6 +4807,11 @@
4772
4807
  var ps = this.fc.providers;
4773
4808
  Object.keys(ps).forEach(function (k) {
4774
4809
  var prop = ps[k];
4810
+
4811
+ if (is.Function(prop)) {
4812
+ prop = prop(_this.fc);
4813
+ }
4814
+
4775
4815
  prop._c = getComponent(prop);
4776
4816
 
4777
4817
  _this.onEffect(prop);
@@ -5005,7 +5045,7 @@
5005
5045
  }
5006
5046
  }
5007
5047
 
5008
- function fetch(option) {
5048
+ function fetch$1(option) {
5009
5049
  if (typeof XMLHttpRequest === 'undefined') {
5010
5050
  return;
5011
5051
  }
@@ -5218,90 +5258,103 @@
5218
5258
  render: function render(children) {}
5219
5259
  });
5220
5260
 
5221
- var $fetch = {
5222
- name: 'fetch',
5223
- loaded: function loaded() {
5224
- run.apply(void 0, arguments);
5225
- },
5226
- watch: function watch(inject, rule, api) {
5227
- if (!run(inject, rule, api)) {
5228
- inject.clearProp();
5229
- api.sync(rule);
5261
+ var fetch = function fetch(fc) {
5262
+ function parseOpt(option) {
5263
+ if (is.String(option)) {
5264
+ option = {
5265
+ action: option,
5266
+ to: 'options'
5267
+ };
5230
5268
  }
5231
- }
5232
- };
5233
5269
 
5234
- function parseOpt(option) {
5235
- if (is.String(option)) {
5236
- option = {
5237
- action: option,
5238
- to: 'options'
5239
- };
5270
+ return option;
5240
5271
  }
5241
5272
 
5242
- return option;
5243
- }
5273
+ function run(inject, rule, api) {
5274
+ var option = inject.value;
5244
5275
 
5245
- function run(inject, rule, api) {
5246
- var option = inject.value;
5276
+ if (is.Function(option)) {
5277
+ option = option(rule, api);
5278
+ }
5247
5279
 
5248
- if (is.Function(option)) {
5249
- option = option(rule, api);
5250
- }
5280
+ option = parseOpt(option);
5251
5281
 
5252
- option = parseOpt(option);
5282
+ if (!option || !option.action) {
5283
+ return false;
5284
+ }
5253
5285
 
5254
- if (!option || !option.action) {
5255
- return false;
5256
- }
5286
+ if (!option.to) {
5287
+ option.to = 'options';
5288
+ }
5257
5289
 
5258
- if (!option.to) {
5259
- option.to = 'options';
5260
- }
5290
+ var _onError = option.onError;
5261
5291
 
5262
- var _onError = option.onError;
5292
+ var check = function check() {
5293
+ if (!inject.getValue()) {
5294
+ inject.clearProp();
5295
+ api.sync(rule);
5296
+ return true;
5297
+ }
5298
+ };
5263
5299
 
5264
- var check = function check() {
5265
- if (!inject.getValue()) {
5266
- inject.clearProp();
5267
- api.sync(rule);
5268
- return true;
5269
- }
5270
- };
5300
+ var set = function set(val) {
5301
+ if (val === undefined) {
5302
+ inject.clearProp();
5303
+ api.sync(rule);
5304
+ } else {
5305
+ deepSet(inject.getProp(), option.to, val);
5306
+ }
5307
+ };
5271
5308
 
5272
- var set = function set(val) {
5273
- if (val === undefined) {
5274
- inject.clearProp();
5275
- api.sync(rule);
5276
- } else {
5277
- deepSet(inject.getProp(), option.to, val);
5278
- }
5279
- };
5309
+ invoke(function () {
5310
+ return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5311
+ onSuccess: function onSuccess(body) {
5312
+ if (check()) return;
5280
5313
 
5281
- invoke(function () {
5282
- return fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5283
- onSuccess: function onSuccess(body) {
5284
- if (check()) return;
5285
- set((option.parse || function (v) {
5286
- return v.data;
5287
- })(body, rule, api));
5288
- api.sync(rule);
5289
- },
5290
- onError: function onError(e) {
5291
- set(undefined);
5292
- if (check()) return;
5314
+ var fn = function fn(v) {
5315
+ return v.data;
5316
+ };
5317
+
5318
+ if (is.Function(option.parse)) {
5319
+ fn = option.parse;
5320
+ }
5293
5321
 
5294
- (_onError || function (e) {
5295
- return err(e.message || 'fetch fail ' + option.action);
5296
- })(e, rule, api);
5322
+ set(fn(body, rule, api));
5323
+ api.sync(rule);
5324
+ },
5325
+ onError: function onError(e) {
5326
+ set(undefined);
5327
+ if (check()) return;
5328
+
5329
+ (_onError || function (e) {
5330
+ return err(e.message || 'fetch fail ' + option.action);
5331
+ })(e, rule, api);
5332
+ }
5333
+ }), {
5334
+ inject: inject,
5335
+ rule: rule,
5336
+ api: api
5337
+ });
5338
+ });
5339
+ return true;
5340
+ }
5341
+
5342
+ return {
5343
+ name: 'fetch',
5344
+ loaded: function loaded() {
5345
+ run.apply(void 0, arguments);
5346
+ },
5347
+ watch: function watch(inject, rule, api) {
5348
+ if (!run(inject, rule, api)) {
5349
+ inject.clearProp();
5350
+ api.sync(rule);
5297
5351
  }
5298
- }));
5299
- });
5300
- return true;
5301
- }
5352
+ }
5353
+ };
5354
+ };
5302
5355
 
5303
5356
  var $provider = {
5304
- fetch: $fetch
5357
+ fetch: fetch
5305
5358
  };
5306
5359
 
5307
5360
  var name$6 = 'html';
@@ -5649,7 +5702,7 @@
5649
5702
  componentAlias: componentAlias,
5650
5703
  copyRule: copyRule,
5651
5704
  copyRules: copyRules,
5652
- fetch: fetch,
5705
+ fetch: fetch$1,
5653
5706
  $form: $form,
5654
5707
  parseFn: parseFn,
5655
5708
  parseJson: parseJson,
@@ -5944,6 +5997,13 @@
5944
5997
  }
5945
5998
  }
5946
5999
 
6000
+ function tidyRule(rule) {
6001
+ var _rule = _objectSpread2({}, rule);
6002
+
6003
+ delete _rule.children;
6004
+ return _rule;
6005
+ }
6006
+
5947
6007
  var manager = {
5948
6008
  validate: function validate() {
5949
6009
  var form = this.form();
@@ -6103,7 +6163,7 @@
6103
6163
  if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
6104
6164
  var prop = {
6105
6165
  type: infoProp.type || 'popover',
6106
- props: _objectSpread2({}, infoProp),
6166
+ props: tidyRule(infoProp),
6107
6167
  key: "".concat(uni, "pop")
6108
6168
  };
6109
6169
  delete prop.props.icon;
@@ -6133,7 +6193,7 @@
6133
6193
  }
6134
6194
 
6135
6195
  var _prop = mergeProps([titleProp, {
6136
- props: titleProp,
6196
+ props: tidyRule(titleProp),
6137
6197
  key: "".concat(uni, "tit"),
6138
6198
  type: titleProp.type || 'span'
6139
6199
  }]);
@@ -6501,7 +6561,8 @@
6501
6561
  }, val);
6502
6562
 
6503
6563
  if (!validate.message) {
6504
- validate.message = rule.title + '不能为空';
6564
+ var title = rule.title || '';
6565
+ validate.message = ((_typeof(title) === 'object' ? title.title : title) || '') + '不能为空';
6505
6566
  }
6506
6567
 
6507
6568
  inject.getProp().validate = [validate];
@@ -6557,7 +6618,7 @@
6557
6618
  function elmFormCreate() {
6558
6619
  return FormCreateFactory({
6559
6620
  ui: 'element-ui',
6560
- version: '3.1.11',
6621
+ version: '3.1.14',
6561
6622
  manager: manager,
6562
6623
  extendApi: extendApi,
6563
6624
  install: install,