@form-create/element-ui 3.2.10 → 3.2.12

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.2.10
2
+ * @form-create/element-ui v3.2.12
3
3
  * (c) 2018-2024 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -2145,7 +2145,7 @@
2145
2145
  },
2146
2146
  inFor: Boolean
2147
2147
  },
2148
- emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update', 'validate-field-fail', 'validate-fail', 'created'],
2148
+ emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'reset', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update', 'validate-field-fail', 'validate-fail', 'created'],
2149
2149
  render: function render() {
2150
2150
  return this.fc.render();
2151
2151
  },
@@ -2448,7 +2448,7 @@
2448
2448
  };
2449
2449
  };
2450
2450
 
2451
- var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'slotUpdate', 'computed', 'preview', 'component', 'cache', 'modelEmit'];
2451
+ var keyAttrs = ['type', 'slot', 'ignore', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'slotUpdate', 'computed', 'preview', 'component', 'cache', 'modelEmit'];
2452
2452
  var arrayAttrs = ['validate', 'children', 'control'];
2453
2453
  var normalAttrs = ['effect', 'deep'];
2454
2454
  function attrs() {
@@ -3076,16 +3076,32 @@
3076
3076
  },
3077
3077
 
3078
3078
  formData: function formData(fields) {
3079
- return tidyFields(fields).reduce(function (initial, id) {
3080
- var ctx = h.getFieldCtx(id);
3081
- if (!ctx) return initial;
3082
- initial[ctx.field] = copy(ctx.rule.value);
3083
- return initial;
3084
- }, h.options.appendValue !== false ? copy(h.appendData) : {});
3079
+ if (fields == null) {
3080
+ var data = {};
3081
+ Object.keys(h.form).forEach(function (k) {
3082
+ if (h.ignoreFields.indexOf(k) === -1) {
3083
+ data[k] = copy(h.form[k]);
3084
+ }
3085
+ });
3086
+ return data;
3087
+ } else {
3088
+ return tidyFields(fields).reduce(function (initial, id) {
3089
+ initial[id] = api.getValue(id);
3090
+ return initial;
3091
+ }, {});
3092
+ }
3085
3093
  },
3086
3094
  getValue: function getValue(field) {
3087
3095
  var ctx = h.getFieldCtx(field);
3088
- if (!ctx) return;
3096
+
3097
+ if (!ctx) {
3098
+ if (h.options.appendValue !== false && hasProperty(h.appendData, field)) {
3099
+ return copy(h.appendData[field]);
3100
+ }
3101
+
3102
+ return undefined;
3103
+ }
3104
+
3089
3105
  return copy(ctx.rule.value);
3090
3106
  },
3091
3107
  coverValue: function coverValue(formData) {
@@ -3393,6 +3409,13 @@
3393
3409
  vue.nextTick(function () {
3394
3410
  api.clearValidateState();
3395
3411
  });
3412
+
3413
+ if (fields == null) {
3414
+ is.Function(h.options.onReset) && invoke(function () {
3415
+ return h.options.onReset(api);
3416
+ });
3417
+ h.vm.emit('reset', api);
3418
+ }
3396
3419
  },
3397
3420
  method: function method(id, name) {
3398
3421
  var el = api.el(id);
@@ -3969,6 +3992,9 @@
3969
3992
  getSubForm: function getSubForm() {
3970
3993
  return _this6.$handle.subForm[ctx.id];
3971
3994
  },
3995
+ slots: function slots() {
3996
+ return _this6.vm.setupState.top.slots;
3997
+ },
3972
3998
  options: [],
3973
3999
  children: [],
3974
4000
  preview: false,
@@ -5063,9 +5089,9 @@
5063
5089
  __ctrl: true,
5064
5090
  children: rule,
5065
5091
  valid: valid
5066
- }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
5092
+ }) : ctrl && ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl) >>> 0, 1);
5067
5093
  hideLst[valid ? 'push' : 'unshift'](function () {
5068
- if (method === 'disabled') {
5094
+ if (method === 'disabled' || method === 'enabled') {
5069
5095
  _this7.api.disabled(!valid, rule);
5070
5096
  } else if (method === 'display') {
5071
5097
  _this7.api.display(valid, rule);
@@ -5285,6 +5311,7 @@
5285
5311
 
5286
5312
  var data = vue.reactive({});
5287
5313
  var fields = this.fields();
5314
+ var ignoreFields = [];
5288
5315
 
5289
5316
  if (this.options.appendValue !== false) {
5290
5317
  Object.keys(this.appendData).reduce(function (initial, field) {
@@ -5297,14 +5324,24 @@
5297
5324
  }
5298
5325
 
5299
5326
  fields.reduce(function (initial, field) {
5300
- var ctx = _this2.getCtx(field);
5327
+ var ctx = (_this2.fieldCtx[field] || []).filter(function (ctx) {
5328
+ return !_this2.isIgnore(ctx.rule);
5329
+ })[0] || _this2.fieldCtx[field][0];
5330
+
5331
+ if (_this2.isIgnore(ctx.rule)) {
5332
+ ignoreFields.push(field);
5333
+ }
5301
5334
 
5302
5335
  initial[field] = vue.toRef(ctx.rule, 'value');
5303
5336
  return initial;
5304
5337
  }, data);
5305
5338
  this.form = data;
5339
+ this.ignoreFields = ignoreFields;
5306
5340
  this.syncValue();
5307
5341
  },
5342
+ isIgnore: function isIgnore(rule) {
5343
+ return rule.ignore || this.options.ignoreHiddenFields && rule.hidden;
5344
+ },
5308
5345
  appendValue: function appendValue(rule) {
5309
5346
  if ((!rule.field || !hasProperty(this.appendData, rule.field)) && !this.options.forceCoverValue) {
5310
5347
  return;
@@ -5336,11 +5373,19 @@
5336
5373
  }
5337
5374
  },
5338
5375
  syncValue: function syncValue() {
5376
+ var _this3 = this;
5377
+
5339
5378
  if (this.deferSyncFn) {
5340
5379
  return this.deferSyncFn.sync = true;
5341
5380
  }
5342
5381
 
5343
- this.vm.setupState.updateValue(_objectSpread2({}, this.form));
5382
+ var data = {};
5383
+ Object.keys(this.form).forEach(function (k) {
5384
+ if (_this3.ignoreFields.indexOf(k) === -1) {
5385
+ data[k] = _this3.form[k];
5386
+ }
5387
+ });
5388
+ this.vm.setupState.updateValue(data);
5344
5389
  },
5345
5390
  isChange: function isChange(ctx, value) {
5346
5391
  return JSON.stringify(this.getFormData(ctx), strFn) !== JSON.stringify(value, strFn);
@@ -5349,11 +5394,11 @@
5349
5394
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
5350
5395
  },
5351
5396
  refreshUpdate: function refreshUpdate(ctx, val, origin, field) {
5352
- var _this3 = this;
5397
+ var _this4 = this;
5353
5398
 
5354
5399
  if (is.Function(ctx.rule.update)) {
5355
5400
  var state = invoke(function () {
5356
- return ctx.rule.update(val, ctx.origin, _this3.api, {
5401
+ return ctx.rule.update(val, ctx.origin, _this4.api, {
5357
5402
  origin: origin || 'change',
5358
5403
  linkField: field
5359
5404
  });
@@ -5377,18 +5422,18 @@
5377
5422
  this.refreshUpdate(ctx, val, origin, field);
5378
5423
  },
5379
5424
  appendLink: function appendLink(ctx) {
5380
- var _this4 = this;
5425
+ var _this5 = this;
5381
5426
 
5382
5427
  var link = ctx.rule.link;
5383
5428
  is.trueArray(link) && link.forEach(function (field) {
5384
5429
  var fn = function fn() {
5385
- return _this4.refreshRule(ctx, ctx.rule.value, 'link', field);
5430
+ return _this5.refreshRule(ctx, ctx.rule.value, 'link', field);
5386
5431
  };
5387
5432
 
5388
- _this4.bus.$on('change-' + field, fn);
5433
+ _this5.bus.$on('change-' + field, fn);
5389
5434
 
5390
5435
  ctx.linkOn.push(function () {
5391
- return _this4.bus.$off('change-' + field, fn);
5436
+ return _this5.bus.$off('change-' + field, fn);
5392
5437
  });
5393
5438
  });
5394
5439
  },
@@ -5542,7 +5587,13 @@
5542
5587
 
5543
5588
  _this.watching = true;
5544
5589
 
5545
- if (key === 'link') {
5590
+ if (key === 'hidden' && Boolean(n) !== Boolean(o)) {
5591
+ _this.$render.clearCacheAll();
5592
+ }
5593
+
5594
+ if (key === 'ignore' && ctx.input || key === 'hidden' && ctx.input && _this.options.ignoreHiddenFields) {
5595
+ _this.syncForm();
5596
+ } else if (key === 'link') {
5546
5597
  ctx.link();
5547
5598
  return;
5548
5599
  } else if (['props', 'on', 'deep'].indexOf(key) > -1) {
@@ -5553,8 +5604,6 @@
5553
5604
  }
5554
5605
  } else if (key === 'emit') {
5555
5606
  _this.parseEmit(ctx);
5556
- } else if (key === 'hidden' && Boolean(n) !== Boolean(o)) {
5557
- _this.$render.clearCacheAll();
5558
5607
  } else if (['prefix', 'suffix'].indexOf(key) > -1) n && _this.loadFn(n, ctx.rule);else if (key === 'type') {
5559
5608
  ctx.updateType();
5560
5609
 
@@ -5609,10 +5658,18 @@
5609
5658
  }
5610
5659
 
5611
5660
  Object.keys(computedRule).forEach(function (k) {
5661
+ var oldValue = undefined;
5612
5662
  var computedValue = vue.computed(function () {
5613
5663
  var item = computedRule[k];
5614
5664
  if (!item) return undefined;
5615
- return _this.compute(ctx, item);
5665
+
5666
+ var value = _this.compute(ctx, item);
5667
+
5668
+ if (item.linkage && value === undefined) {
5669
+ return oldValue;
5670
+ }
5671
+
5672
+ return value;
5616
5673
  });
5617
5674
 
5618
5675
  var callback = function callback(n) {
@@ -5630,6 +5687,7 @@
5630
5687
  }
5631
5688
 
5632
5689
  ctx.watch.push(vue.watch(computedValue, function (n) {
5690
+ oldValue = n;
5633
5691
  setTimeout(function () {
5634
5692
  callback(n);
5635
5693
  });
@@ -5684,41 +5742,51 @@
5684
5742
  };
5685
5743
 
5686
5744
  var val = checkCondition(item);
5687
- return item.invert === true ? !val : val;
5745
+ val = item.invert === true ? !val : val;
5746
+
5747
+ if (item.linkage) {
5748
+ return val ? invoke(function () {
5749
+ return _this2.computeValue(item.linkage, ctx, group);
5750
+ }, undefined) : undefined;
5751
+ }
5752
+
5753
+ return val;
5688
5754
  } else if (is.Function(item)) {
5689
5755
  fn = function fn() {
5690
5756
  return item(_this2.api.form, _this2.api);
5691
5757
  };
5692
5758
  } else {
5693
- var that = this;
5694
- var formulas = Object.keys(this.fc.formulas).reduce(function (obj, k) {
5695
- obj[k] = function () {
5696
- var _that$fc$formulas$k;
5697
-
5698
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5699
- args[_key] = arguments[_key];
5700
- }
5701
-
5702
- return (_that$fc$formulas$k = that.fc.formulas[k]).call.apply(_that$fc$formulas$k, [{
5703
- that: this,
5704
- rule: ctx.rule,
5705
- api: that.api,
5706
- fc: that.fc
5707
- }].concat(args));
5708
- };
5709
-
5710
- return obj;
5711
- }, {});
5712
-
5713
5759
  var _group = ctx.getParentGroup();
5714
5760
 
5715
5761
  fn = function fn() {
5716
- return new Function('$formulas', '$form', '$group', '$rule', '$api', "with($form){with(this){with($group){with($formulas){ return ".concat(item, " }}}}")).call(_this2.api.form, formulas, _this2.api.top.form, _group ? _this2.subRuleData[_group.id] || {} : {}, ctx.rule, _this2.api);
5762
+ return _this2.computeValue(item, ctx, _group);
5717
5763
  };
5718
5764
  }
5719
5765
 
5720
5766
  return invoke(fn, undefined);
5721
5767
  },
5768
+ computeValue: function computeValue(str, ctx, group) {
5769
+ var that = this;
5770
+ var formulas = Object.keys(this.fc.formulas).reduce(function (obj, k) {
5771
+ obj[k] = function () {
5772
+ var _that$fc$formulas$k;
5773
+
5774
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5775
+ args[_key] = arguments[_key];
5776
+ }
5777
+
5778
+ return (_that$fc$formulas$k = that.fc.formulas[k]).call.apply(_that$fc$formulas$k, [{
5779
+ that: this,
5780
+ rule: ctx.rule,
5781
+ api: that.api,
5782
+ fc: that.fc
5783
+ }].concat(args));
5784
+ };
5785
+
5786
+ return obj;
5787
+ }, {});
5788
+ return new Function('$formulas', '$form', '$group', '$rule', '$api', "with($form){with(this){with($group){with($formulas){ return ".concat(str, " }}}}")).call(this.api.form, formulas, this.api.top.form, group ? this.subRuleData[group.id] || {} : {}, ctx.rule, this.api);
5789
+ },
5722
5790
  updateChildren: function updateChildren(ctx, n, o) {
5723
5791
  var _this3 = this;
5724
5792
 
@@ -6041,6 +6109,7 @@
6041
6109
  subForm: {},
6042
6110
  form: vue.reactive({}),
6043
6111
  appendData: {},
6112
+ ignoreFields: [],
6044
6113
  providers: {},
6045
6114
  cycleLoad: null,
6046
6115
  loadedId: 1,
@@ -6700,6 +6769,7 @@
6700
6769
  var CreateNode = CreateNodeFactory();
6701
6770
  var formulas = {};
6702
6771
  var isMobile = config.isMobile === true;
6772
+ var prototype = {};
6703
6773
  exportAttrs(config.attrs || {});
6704
6774
 
6705
6775
  function getApi(name) {
@@ -6814,6 +6884,8 @@
6814
6884
  return vm.$refs.fc.fapi;
6815
6885
  }
6816
6886
 
6887
+ setPrototypeOf(create, prototype);
6888
+
6817
6889
  function factory(inherit) {
6818
6890
  var _config = _objectSpread2({}, config);
6819
6891
 
@@ -7161,9 +7233,9 @@
7161
7233
  var split = id.split('.');
7162
7234
  var key = split.shift();
7163
7235
 
7164
- if (key === '$form') {
7236
+ if (key === '$topForm') {
7165
7237
  val = this.$handle.api.top.formData();
7166
- } else if (key === '$subForm') {
7238
+ } else if (key === '$form') {
7167
7239
  val = this.$handle.api.formData();
7168
7240
  } else if (key === '$options') {
7169
7241
  val = this.options.value;
@@ -7175,7 +7247,7 @@
7175
7247
  split = [];
7176
7248
  } else {
7177
7249
  var tmpData = this.vm.setupState.top.setupState.fc.tmpData;
7178
- val = hasProperty(tmpData, key) ? deepGet(tmpData, id) : getData(key);
7250
+ val = hasProperty(tmpData, key) ? deepGet(tmpData, id) : getData(id);
7179
7251
  split = [];
7180
7252
  }
7181
7253
 
@@ -7210,7 +7282,9 @@
7210
7282
  var callback = debounce(function () {
7211
7283
  var temp = _this6.getLoadData(id, def);
7212
7284
 
7213
- if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
7285
+ if (!unwatch[id]) {
7286
+ return;
7287
+ } else if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
7214
7288
  unwatch[id].val = temp;
7215
7289
  run(true);
7216
7290
  }
@@ -7331,6 +7405,7 @@
7331
7405
  extend(formCreate, {
7332
7406
  version: config.version,
7333
7407
  ui: config.ui,
7408
+ isMobile: isMobile,
7334
7409
  extendApi: extendApi,
7335
7410
  getData: getData,
7336
7411
  setDataDriver: setDataDriver,
@@ -7351,6 +7426,7 @@
7351
7426
  componentAlias: componentAlias,
7352
7427
  copyRule: copyRule,
7353
7428
  copyRules: copyRules,
7429
+ mergeRule: mergeRule,
7354
7430
  fetch: fetch$1,
7355
7431
  $form: $form,
7356
7432
  parseFn: parseFn,
@@ -7365,7 +7441,6 @@
7365
7441
  function useStatic(formCreate) {
7366
7442
  extend(formCreate, {
7367
7443
  create: create,
7368
- isMobile: isMobile,
7369
7444
  install: function install(app, options) {
7370
7445
  globalConfig = _objectSpread2(_objectSpread2({}, globalConfig), options || {});
7371
7446
  var key = '_installedFormCreate_' + config.ui;
@@ -7390,8 +7465,8 @@
7390
7465
  });
7391
7466
  }
7392
7467
 
7393
- useAttr(create);
7394
- useStatic(create);
7468
+ useAttr(prototype);
7469
+ useStatic(prototype);
7395
7470
  setDataDriver('$cookie', cookieDriver);
7396
7471
  setDataDriver('$localStorage', localStorageDriver);
7397
7472
  CreateNode.use({
@@ -7419,18 +7494,18 @@
7419
7494
  }
7420
7495
 
7421
7496
  var FcComponent = $form();
7422
- setPrototypeOf(FcComponent, create);
7497
+ setPrototypeOf(FcComponent, prototype);
7423
7498
  Object.defineProperties(FcComponent, {
7424
7499
  fetch: {
7425
7500
  get: function get() {
7426
- return create.fetch;
7501
+ return prototype.fetch;
7427
7502
  },
7428
7503
  set: function set(val) {
7429
- create.fetch = val;
7504
+ prototype.fetch = val;
7430
7505
  }
7431
7506
  }
7432
7507
  });
7433
- FcComponent.util = create;
7508
+ FcComponent.util = prototype;
7434
7509
  return FcComponent;
7435
7510
  }
7436
7511
 
@@ -8315,7 +8390,7 @@
8315
8390
  function elmFormCreate() {
8316
8391
  return FormCreateFactory({
8317
8392
  ui: 'element-ui',
8318
- version: '3.2.10',
8393
+ version: '3.2.12',
8319
8394
  manager: manager,
8320
8395
  extendApi: extendApi,
8321
8396
  install: install,