@form-create/element-ui 3.2.9 → 3.2.11

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.9
2
+ * @form-create/element-ui v3.2.11
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,33 @@
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
+ return api.fields().reduce(function (initial, id) {
3081
+ var ctx = (h.fieldCtx[id] || []).filter(function (ctx) {
3082
+ return !h.isIgnore(ctx.rule);
3083
+ })[0];
3084
+ if (!ctx) return initial;
3085
+ initial[ctx.field] = copy(ctx.rule.value);
3086
+ return initial;
3087
+ }, h.options.appendValue !== false ? copy(h.appendData) : {});
3088
+ } else {
3089
+ return tidyFields(fields).reduce(function (initial, id) {
3090
+ initial[id] = api.getValue(id);
3091
+ return initial;
3092
+ }, {});
3093
+ }
3085
3094
  },
3086
3095
  getValue: function getValue(field) {
3087
3096
  var ctx = h.getFieldCtx(field);
3088
- if (!ctx) return;
3097
+
3098
+ if (!ctx) {
3099
+ if (h.options.appendValue !== false && hasProperty(h.appendData, field)) {
3100
+ return copy(h.appendData[field]);
3101
+ }
3102
+
3103
+ return undefined;
3104
+ }
3105
+
3089
3106
  return copy(ctx.rule.value);
3090
3107
  },
3091
3108
  coverValue: function coverValue(formData) {
@@ -3393,6 +3410,13 @@
3393
3410
  vue.nextTick(function () {
3394
3411
  api.clearValidateState();
3395
3412
  });
3413
+
3414
+ if (fields == null) {
3415
+ is.Function(h.options.onReset) && invoke(function () {
3416
+ return h.options.onReset(api);
3417
+ });
3418
+ h.vm.emit('reset', api);
3419
+ }
3396
3420
  },
3397
3421
  method: function method(id, name) {
3398
3422
  var el = api.el(id);
@@ -3553,7 +3577,17 @@
3553
3577
  opt = deepCopy(opt);
3554
3578
  opt = h.loadFetchVar(opt);
3555
3579
  h.beforeFetch(opt).then(function () {
3556
- return asyncFetch(opt, h.fc.create.fetch).then(resolve)["catch"](reject);
3580
+ return asyncFetch(opt, h.fc.create.fetch).then(function (res) {
3581
+ invoke(function () {
3582
+ return opt.onSuccess && opt.onSuccess(res);
3583
+ });
3584
+ resolve(res);
3585
+ })["catch"](function (e) {
3586
+ invoke(function () {
3587
+ return opt.onError && opt.onError(e);
3588
+ });
3589
+ reject(e);
3590
+ });
3557
3591
  });
3558
3592
  });
3559
3593
  },
@@ -3564,8 +3598,14 @@
3564
3598
  _opt = h.loadFetchVar(_opt, get);
3565
3599
  h.beforeFetch(_opt).then(function () {
3566
3600
  return asyncFetch(_opt, h.fc.create.fetch).then(function (res) {
3601
+ invoke(function () {
3602
+ return _opt.onSuccess && _opt.onSuccess(res);
3603
+ });
3567
3604
  callback && callback(res, change);
3568
3605
  })["catch"](function (e) {
3606
+ invoke(function () {
3607
+ return _opt.onError && _opt.onError(e);
3608
+ });
3569
3609
  error && error(e);
3570
3610
  });
3571
3611
  });
@@ -3953,6 +3993,9 @@
3953
3993
  getSubForm: function getSubForm() {
3954
3994
  return _this6.$handle.subForm[ctx.id];
3955
3995
  },
3996
+ slots: function slots() {
3997
+ return _this6.vm.setupState.top.slots;
3998
+ },
3956
3999
  options: [],
3957
4000
  children: [],
3958
4001
  preview: false,
@@ -5283,12 +5326,18 @@
5283
5326
  fields.reduce(function (initial, field) {
5284
5327
  var ctx = _this2.getCtx(field);
5285
5328
 
5286
- initial[field] = vue.toRef(ctx.rule, 'value');
5329
+ if (!_this2.isIgnore(ctx.rule)) {
5330
+ initial[field] = vue.toRef(ctx.rule, 'value');
5331
+ }
5332
+
5287
5333
  return initial;
5288
5334
  }, data);
5289
5335
  this.form = data;
5290
5336
  this.syncValue();
5291
5337
  },
5338
+ isIgnore: function isIgnore(rule) {
5339
+ return rule.ignore || this.options.ignoreHiddenFields && rule.hidden;
5340
+ },
5292
5341
  appendValue: function appendValue(rule) {
5293
5342
  if ((!rule.field || !hasProperty(this.appendData, rule.field)) && !this.options.forceCoverValue) {
5294
5343
  return;
@@ -5526,7 +5575,13 @@
5526
5575
 
5527
5576
  _this.watching = true;
5528
5577
 
5529
- if (key === 'link') {
5578
+ if (key === 'hidden' && Boolean(n) !== Boolean(o)) {
5579
+ _this.$render.clearCacheAll();
5580
+ }
5581
+
5582
+ if (key === 'ignore' && ctx.input || key === 'hidden' && ctx.input && _this.options.ignoreHiddenFields) {
5583
+ _this.syncForm();
5584
+ } else if (key === 'link') {
5530
5585
  ctx.link();
5531
5586
  return;
5532
5587
  } else if (['props', 'on', 'deep'].indexOf(key) > -1) {
@@ -5537,8 +5592,6 @@
5537
5592
  }
5538
5593
  } else if (key === 'emit') {
5539
5594
  _this.parseEmit(ctx);
5540
- } else if (key === 'hidden' && Boolean(n) !== Boolean(o)) {
5541
- _this.$render.clearCacheAll();
5542
5595
  } else if (['prefix', 'suffix'].indexOf(key) > -1) n && _this.loadFn(n, ctx.rule);else if (key === 'type') {
5543
5596
  ctx.updateType();
5544
5597
 
@@ -5593,10 +5646,18 @@
5593
5646
  }
5594
5647
 
5595
5648
  Object.keys(computedRule).forEach(function (k) {
5649
+ var oldValue = undefined;
5596
5650
  var computedValue = vue.computed(function () {
5597
5651
  var item = computedRule[k];
5598
5652
  if (!item) return undefined;
5599
- return _this.compute(ctx, item);
5653
+
5654
+ var value = _this.compute(ctx, item);
5655
+
5656
+ if (item.linkage && value === undefined) {
5657
+ return oldValue;
5658
+ }
5659
+
5660
+ return value;
5600
5661
  });
5601
5662
 
5602
5663
  var callback = function callback(n) {
@@ -5614,6 +5675,7 @@
5614
5675
  }
5615
5676
 
5616
5677
  ctx.watch.push(vue.watch(computedValue, function (n) {
5678
+ oldValue = n;
5617
5679
  setTimeout(function () {
5618
5680
  callback(n);
5619
5681
  });
@@ -5668,7 +5730,15 @@
5668
5730
  };
5669
5731
 
5670
5732
  var val = checkCondition(item);
5671
- return item.invert === true ? !val : val;
5733
+ val = item.invert === true ? !val : val;
5734
+
5735
+ if (item.linkage) {
5736
+ return val ? invoke(function () {
5737
+ return _this2.computeValue(item.linkage, ctx, group);
5738
+ }, undefined) : undefined;
5739
+ }
5740
+
5741
+ return val;
5672
5742
  } else if (is.Function(item)) {
5673
5743
  fn = function fn() {
5674
5744
  return item(_this2.api.form, _this2.api);
@@ -5677,12 +5747,34 @@
5677
5747
  var _group = ctx.getParentGroup();
5678
5748
 
5679
5749
  fn = function fn() {
5680
- return new Function('$formulas', '$form', '$group', '$rule', '$api', "with($form){with(this){with($group){with($formulas){ return ".concat(item, " }}}}")).call(_this2.api.form, _this2.fc.formulas, _this2.api.top.form, _group ? _this2.subRuleData[_group.id] || {} : {}, ctx.rule, _this2.api);
5750
+ return _this2.computeValue(item, ctx, _group);
5681
5751
  };
5682
5752
  }
5683
5753
 
5684
5754
  return invoke(fn, undefined);
5685
5755
  },
5756
+ computeValue: function computeValue(str, ctx, group) {
5757
+ var that = this;
5758
+ var formulas = Object.keys(this.fc.formulas).reduce(function (obj, k) {
5759
+ obj[k] = function () {
5760
+ var _that$fc$formulas$k;
5761
+
5762
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5763
+ args[_key] = arguments[_key];
5764
+ }
5765
+
5766
+ return (_that$fc$formulas$k = that.fc.formulas[k]).call.apply(_that$fc$formulas$k, [{
5767
+ that: this,
5768
+ rule: ctx.rule,
5769
+ api: that.api,
5770
+ fc: that.fc
5771
+ }].concat(args));
5772
+ };
5773
+
5774
+ return obj;
5775
+ }, {});
5776
+ 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);
5777
+ },
5686
5778
  updateChildren: function updateChildren(ctx, n, o) {
5687
5779
  var _this3 = this;
5688
5780
 
@@ -5988,7 +6080,7 @@
5988
6080
  return fc.bus;
5989
6081
  },
5990
6082
  preview: function preview() {
5991
- return fc.vm.props.preview != null ? fc.vm.props.preview : this.options.preview || false;
6083
+ return fc.vm.props.preview != null ? fc.vm.props.preview : fc.options.value.preview || false;
5992
6084
  }
5993
6085
  });
5994
6086
  extend(this, {
@@ -6664,6 +6756,7 @@
6664
6756
  var CreateNode = CreateNodeFactory();
6665
6757
  var formulas = {};
6666
6758
  var isMobile = config.isMobile === true;
6759
+ var prototype = {};
6667
6760
  exportAttrs(config.attrs || {});
6668
6761
 
6669
6762
  function getApi(name) {
@@ -6778,6 +6871,8 @@
6778
6871
  return vm.$refs.fc.fapi;
6779
6872
  }
6780
6873
 
6874
+ setPrototypeOf(create, prototype);
6875
+
6781
6876
  function factory(inherit) {
6782
6877
  var _config = _objectSpread2({}, config);
6783
6878
 
@@ -7125,9 +7220,9 @@
7125
7220
  var split = id.split('.');
7126
7221
  var key = split.shift();
7127
7222
 
7128
- if (key === '$form') {
7223
+ if (key === '$topForm') {
7129
7224
  val = this.$handle.api.top.formData();
7130
- } else if (key === '$subForm') {
7225
+ } else if (key === '$form') {
7131
7226
  val = this.$handle.api.formData();
7132
7227
  } else if (key === '$options') {
7133
7228
  val = this.options.value;
@@ -7139,7 +7234,7 @@
7139
7234
  split = [];
7140
7235
  } else {
7141
7236
  var tmpData = this.vm.setupState.top.setupState.fc.tmpData;
7142
- val = hasProperty(tmpData, key) ? deepGet(tmpData, id) : getData(key);
7237
+ val = hasProperty(tmpData, key) ? deepGet(tmpData, id) : getData(id);
7143
7238
  split = [];
7144
7239
  }
7145
7240
 
@@ -7172,14 +7267,12 @@
7172
7267
  var key = split.shift();
7173
7268
  var key2 = split.shift() || '';
7174
7269
  var callback = debounce(function () {
7175
- if (key !== id) {
7176
- var temp = _this6.getLoadData(id, def);
7270
+ var temp = _this6.getLoadData(id, def);
7177
7271
 
7178
- if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
7179
- unwatch[id].val = temp;
7180
- run(true);
7181
- }
7182
- } else {
7272
+ if (!unwatch[id]) {
7273
+ return;
7274
+ } else if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
7275
+ unwatch[id].val = temp;
7183
7276
  run(true);
7184
7277
  }
7185
7278
  }, 0);
@@ -7299,6 +7392,7 @@
7299
7392
  extend(formCreate, {
7300
7393
  version: config.version,
7301
7394
  ui: config.ui,
7395
+ isMobile: isMobile,
7302
7396
  extendApi: extendApi,
7303
7397
  getData: getData,
7304
7398
  setDataDriver: setDataDriver,
@@ -7319,6 +7413,7 @@
7319
7413
  componentAlias: componentAlias,
7320
7414
  copyRule: copyRule,
7321
7415
  copyRules: copyRules,
7416
+ mergeRule: mergeRule,
7322
7417
  fetch: fetch$1,
7323
7418
  $form: $form,
7324
7419
  parseFn: parseFn,
@@ -7333,7 +7428,6 @@
7333
7428
  function useStatic(formCreate) {
7334
7429
  extend(formCreate, {
7335
7430
  create: create,
7336
- isMobile: isMobile,
7337
7431
  install: function install(app, options) {
7338
7432
  globalConfig = _objectSpread2(_objectSpread2({}, globalConfig), options || {});
7339
7433
  var key = '_installedFormCreate_' + config.ui;
@@ -7358,8 +7452,8 @@
7358
7452
  });
7359
7453
  }
7360
7454
 
7361
- useAttr(create);
7362
- useStatic(create);
7455
+ useAttr(prototype);
7456
+ useStatic(prototype);
7363
7457
  setDataDriver('$cookie', cookieDriver);
7364
7458
  setDataDriver('$localStorage', localStorageDriver);
7365
7459
  CreateNode.use({
@@ -7387,18 +7481,18 @@
7387
7481
  }
7388
7482
 
7389
7483
  var FcComponent = $form();
7390
- setPrototypeOf(FcComponent, create);
7484
+ setPrototypeOf(FcComponent, prototype);
7391
7485
  Object.defineProperties(FcComponent, {
7392
7486
  fetch: {
7393
7487
  get: function get() {
7394
- return create.fetch;
7488
+ return prototype.fetch;
7395
7489
  },
7396
7490
  set: function set(val) {
7397
- create.fetch = val;
7491
+ prototype.fetch = val;
7398
7492
  }
7399
7493
  }
7400
7494
  });
7401
- FcComponent.util = create;
7495
+ FcComponent.util = prototype;
7402
7496
  return FcComponent;
7403
7497
  }
7404
7498
 
@@ -7734,7 +7828,7 @@
7734
7828
  ref: ref
7735
7829
  });
7736
7830
  extend(this.rule.props, {
7737
- model: $handle.formData
7831
+ model: _objectSpread2({}, $handle.formData)
7738
7832
  });
7739
7833
  },
7740
7834
  render: function render(children) {
@@ -8283,7 +8377,7 @@
8283
8377
  function elmFormCreate() {
8284
8378
  return FormCreateFactory({
8285
8379
  ui: 'element-ui',
8286
- version: '3.2.9',
8380
+ version: '3.2.11',
8287
8381
  manager: manager,
8288
8382
  extendApi: extendApi,
8289
8383
  install: install,