@form-create/element-ui 3.1.10 → 3.1.13

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.10
2
+ * @form-create/element-ui v3.1.13
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -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 {
@@ -4170,6 +4206,7 @@
4170
4206
  }
4171
4207
 
4172
4208
  if (!validate.length) return false;
4209
+ var hideLst = [];
4173
4210
  var flag = false;
4174
4211
  this.deferSyncValue(function () {
4175
4212
  validate.reverse().forEach(function (_ref) {
@@ -4187,7 +4224,7 @@
4187
4224
  children: rule,
4188
4225
  valid: valid
4189
4226
  }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
4190
- vue.nextTick(function () {
4227
+ hideLst[valid ? 'push' : 'unshift'](function () {
4191
4228
  _this7.api.hidden(!valid, rule);
4192
4229
  });
4193
4230
  return;
@@ -4220,6 +4257,11 @@
4220
4257
  }
4221
4258
  });
4222
4259
  });
4260
+ hideLst.length && vue.nextTick(function () {
4261
+ hideLst.forEach(function (v) {
4262
+ return v();
4263
+ });
4264
+ });
4223
4265
  this.vm.emit('control', ctx.origin, this.api);
4224
4266
  this.effect(ctx, 'control');
4225
4267
  return flag;
@@ -4766,6 +4808,11 @@
4766
4808
  var ps = this.fc.providers;
4767
4809
  Object.keys(ps).forEach(function (k) {
4768
4810
  var prop = ps[k];
4811
+
4812
+ if (is.Function(prop)) {
4813
+ prop = prop(_this.fc);
4814
+ }
4815
+
4769
4816
  prop._c = getComponent(prop);
4770
4817
 
4771
4818
  _this.onEffect(prop);
@@ -4999,7 +5046,7 @@
4999
5046
  }
5000
5047
  }
5001
5048
 
5002
- function fetch(option) {
5049
+ function fetch$1(option) {
5003
5050
  if (typeof XMLHttpRequest === 'undefined') {
5004
5051
  return;
5005
5052
  }
@@ -5212,90 +5259,103 @@
5212
5259
  render: function render(children) {}
5213
5260
  });
5214
5261
 
5215
- var $fetch = {
5216
- name: 'fetch',
5217
- loaded: function loaded() {
5218
- run.apply(void 0, arguments);
5219
- },
5220
- watch: function watch(inject, rule, api) {
5221
- if (!run(inject, rule, api)) {
5222
- inject.clearProp();
5223
- api.sync(rule);
5262
+ var fetch = function fetch(fc) {
5263
+ function parseOpt(option) {
5264
+ if (is.String(option)) {
5265
+ option = {
5266
+ action: option,
5267
+ to: 'options'
5268
+ };
5224
5269
  }
5225
- }
5226
- };
5227
5270
 
5228
- function parseOpt(option) {
5229
- if (is.String(option)) {
5230
- option = {
5231
- action: option,
5232
- to: 'options'
5233
- };
5271
+ return option;
5234
5272
  }
5235
5273
 
5236
- return option;
5237
- }
5274
+ function run(inject, rule, api) {
5275
+ var option = inject.value;
5238
5276
 
5239
- function run(inject, rule, api) {
5240
- var option = inject.value;
5277
+ if (is.Function(option)) {
5278
+ option = option(rule, api);
5279
+ }
5241
5280
 
5242
- if (is.Function(option)) {
5243
- option = option(rule, api);
5244
- }
5281
+ option = parseOpt(option);
5245
5282
 
5246
- option = parseOpt(option);
5283
+ if (!option || !option.action) {
5284
+ return false;
5285
+ }
5247
5286
 
5248
- if (!option || !option.action) {
5249
- return false;
5250
- }
5287
+ if (!option.to) {
5288
+ option.to = 'options';
5289
+ }
5251
5290
 
5252
- if (!option.to) {
5253
- option.to = 'options';
5254
- }
5291
+ var _onError = option.onError;
5255
5292
 
5256
- var _onError = option.onError;
5293
+ var check = function check() {
5294
+ if (!inject.getValue()) {
5295
+ inject.clearProp();
5296
+ api.sync(rule);
5297
+ return true;
5298
+ }
5299
+ };
5257
5300
 
5258
- var check = function check() {
5259
- if (!inject.getValue()) {
5260
- inject.clearProp();
5261
- api.sync(rule);
5262
- return true;
5263
- }
5264
- };
5301
+ var set = function set(val) {
5302
+ if (val === undefined) {
5303
+ inject.clearProp();
5304
+ api.sync(rule);
5305
+ } else {
5306
+ deepSet(inject.getProp(), option.to, val);
5307
+ }
5308
+ };
5265
5309
 
5266
- var set = function set(val) {
5267
- if (val === undefined) {
5268
- inject.clearProp();
5269
- api.sync(rule);
5270
- } else {
5271
- deepSet(inject.getProp(), option.to, val);
5272
- }
5273
- };
5310
+ invoke(function () {
5311
+ return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5312
+ onSuccess: function onSuccess(body) {
5313
+ if (check()) return;
5274
5314
 
5275
- invoke(function () {
5276
- return fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5277
- onSuccess: function onSuccess(body) {
5278
- if (check()) return;
5279
- set((option.parse || function (v) {
5280
- return v.data;
5281
- })(body, rule, api));
5282
- api.sync(rule);
5283
- },
5284
- onError: function onError(e) {
5285
- set(undefined);
5286
- if (check()) return;
5315
+ var fn = function fn(v) {
5316
+ return v.data;
5317
+ };
5318
+
5319
+ if (is.Function(option.parse)) {
5320
+ fn = option.parse;
5321
+ }
5287
5322
 
5288
- (_onError || function (e) {
5289
- return err(e.message || 'fetch fail ' + option.action);
5290
- })(e, rule, api);
5323
+ set(fn(body, rule, api));
5324
+ api.sync(rule);
5325
+ },
5326
+ onError: function onError(e) {
5327
+ set(undefined);
5328
+ if (check()) return;
5329
+
5330
+ (_onError || function (e) {
5331
+ return err(e.message || 'fetch fail ' + option.action);
5332
+ })(e, rule, api);
5333
+ }
5334
+ }), {
5335
+ inject: inject,
5336
+ rule: rule,
5337
+ api: api
5338
+ });
5339
+ });
5340
+ return true;
5341
+ }
5342
+
5343
+ return {
5344
+ name: 'fetch',
5345
+ loaded: function loaded() {
5346
+ run.apply(void 0, arguments);
5347
+ },
5348
+ watch: function watch(inject, rule, api) {
5349
+ if (!run(inject, rule, api)) {
5350
+ inject.clearProp();
5351
+ api.sync(rule);
5291
5352
  }
5292
- }));
5293
- });
5294
- return true;
5295
- }
5353
+ }
5354
+ };
5355
+ };
5296
5356
 
5297
5357
  var $provider = {
5298
- fetch: $fetch
5358
+ fetch: fetch
5299
5359
  };
5300
5360
 
5301
5361
  var name$6 = 'html';
@@ -5643,7 +5703,7 @@
5643
5703
  componentAlias: componentAlias,
5644
5704
  copyRule: copyRule,
5645
5705
  copyRules: copyRules,
5646
- fetch: fetch,
5706
+ fetch: fetch$1,
5647
5707
  $form: $form,
5648
5708
  parseFn: parseFn,
5649
5709
  parseJson: parseJson,
@@ -6495,7 +6555,8 @@
6495
6555
  }, val);
6496
6556
 
6497
6557
  if (!validate.message) {
6498
- validate.message = rule.title + ' is required';
6558
+ var title = rule.title || '';
6559
+ validate.message = ((_typeof(title) === 'object' ? title.title : title) || '') + '不能为空';
6499
6560
  }
6500
6561
 
6501
6562
  inject.getProp().validate = [validate];
@@ -6551,7 +6612,7 @@
6551
6612
  function elmFormCreate() {
6552
6613
  return FormCreateFactory({
6553
6614
  ui: 'element-ui',
6554
- version: '3.1.10',
6615
+ version: '3.1.13',
6555
6616
  manager: manager,
6556
6617
  extendApi: extendApi,
6557
6618
  install: install,