@form-create/element-ui 3.2.22 → 3.2.24

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.22
2
+ * @form-create/element-ui v3.2.24
3
3
  * (c) 2018-2025 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -2357,7 +2357,7 @@
2357
2357
  v.__inject = true;
2358
2358
  return v;
2359
2359
  } else if (v.indexOf('$FNX:') === 0) {
2360
- v = makeFn('function($inject){' + v.substring(5) + '}');
2360
+ v = makeFn('function($inject){\n' + v.substring(5) + '\n}');
2361
2361
  v.__json = fn;
2362
2362
  v.__inject = true;
2363
2363
  return v;
@@ -2652,6 +2652,68 @@
2652
2652
  });
2653
2653
  return conditions.join(' && ');
2654
2654
  }
2655
+ function parseTemplateToTree(template) {
2656
+ var tokens = [];
2657
+ var current = '';
2658
+ var depth = 0;
2659
+
2660
+ for (var i = 0; i < template.length; i++) {
2661
+ var _char = template[i];
2662
+
2663
+ if (_char === '[') {
2664
+ if (depth === 0 && current) {
2665
+ tokens.push({
2666
+ type: 'key',
2667
+ value: current
2668
+ });
2669
+ current = '';
2670
+ }
2671
+
2672
+ depth++;
2673
+ current += _char;
2674
+ } else if (_char === ']') {
2675
+ depth--;
2676
+ current += _char;
2677
+
2678
+ if (depth === 0) {
2679
+ tokens.push({
2680
+ type: 'bracket',
2681
+ value: parseTemplateToTree(current.slice(1, -1))
2682
+ });
2683
+ current = '';
2684
+ }
2685
+ } else if (_char === '.' && depth === 0) {
2686
+ if (current) {
2687
+ tokens.push({
2688
+ type: 'key',
2689
+ value: current
2690
+ });
2691
+ current = '';
2692
+ }
2693
+ } else {
2694
+ current += _char;
2695
+ }
2696
+ }
2697
+
2698
+ if (current) {
2699
+ tokens.push({
2700
+ type: 'key',
2701
+ value: current
2702
+ });
2703
+ }
2704
+
2705
+ return tokens.map(function (token) {
2706
+ if (token.type === 'key') {
2707
+ return {
2708
+ key: token.value
2709
+ };
2710
+ } else {
2711
+ return {
2712
+ children: token.value
2713
+ };
2714
+ }
2715
+ });
2716
+ }
2655
2717
 
2656
2718
  var _getGroupInject = function getGroupInject(vm, parent) {
2657
2719
  if (!vm || vm === parent) {
@@ -2848,10 +2910,10 @@
2848
2910
  fapi.scope.bus.$off('$loadData.$scopeForm', emit$scopeForm);
2849
2911
  }
2850
2912
 
2851
- styleEl && document.head.removeChild(styleEl);
2852
2913
  rmSubForm();
2853
2914
  data.destroyed = true;
2854
2915
  fc.unmount();
2916
+ styleEl && (styleEl.parentNode || styleEl.parentElement) && document.head.removeChild(styleEl);
2855
2917
  });
2856
2918
  vue.onUpdated(function () {
2857
2919
  fc.updated();
@@ -3744,9 +3806,7 @@
3744
3806
 
3745
3807
  if (!config) {
3746
3808
  resolve(h.fc.loadData[name]);
3747
- }
3748
-
3749
- if (config.type === 'fetch') {
3809
+ } else if (config.type === 'fetch') {
3750
3810
  api.fetch(config).then(function (res) {
3751
3811
  resolve(res);
3752
3812
  })["catch"](inject);
@@ -4615,6 +4675,58 @@
4615
4675
  if (str && typeof str === 'string' && str.indexOf('{{') > -1 && str.indexOf('}}') > -1) {
4616
4676
  var tmp = str;
4617
4677
  var vars = extractVar(str);
4678
+
4679
+ var getValue = function getValue(field) {
4680
+ var flag = false;
4681
+ var val;
4682
+
4683
+ if (group && field.indexOf('$form.') === 0) {
4684
+ var _split = field.split('.');
4685
+
4686
+ _split.shift();
4687
+
4688
+ if (hasProperty(group.value, _split[0])) {
4689
+ flag = true;
4690
+ val = get ? get({
4691
+ id: '$form.' + _split[0] + '_' + group.rule.__fc__.id,
4692
+ getValue: function getValue() {
4693
+ return deepGet(group.value, _split);
4694
+ }
4695
+ }) : deepGet(group.value, _split);
4696
+ }
4697
+ }
4698
+
4699
+ if (!flag) {
4700
+ val = get ? get(field) : _this3.fc.getLoadData(field);
4701
+ }
4702
+
4703
+ return val;
4704
+ };
4705
+
4706
+ var treeToVal = function treeToVal(tree) {
4707
+ var fields = [];
4708
+ tree.forEach(function (item) {
4709
+ if (item.key) {
4710
+ fields.push(item.key);
4711
+ } else if (item.children) {
4712
+ fields.push(treeToVal(item.children));
4713
+ }
4714
+ });
4715
+ var flag = false;
4716
+ fields.forEach(function (field, idx) {
4717
+ if (field != null && (field.indexOf('\'') === 0 || field.indexOf('"') === 0)) {
4718
+ fields[idx] = field.slice(1, -1);
4719
+ flag = true;
4720
+ }
4721
+ });
4722
+
4723
+ if (fields.length === 1 && (flag || !isNaN(Number(fields[0])))) {
4724
+ return fields[0];
4725
+ }
4726
+
4727
+ return getValue(fields.join('.'));
4728
+ };
4729
+
4618
4730
  var lastVal;
4619
4731
  vars.forEach(function (v) {
4620
4732
  var split = v.split('||');
@@ -4622,27 +4734,13 @@
4622
4734
 
4623
4735
  if (field) {
4624
4736
  var def = (split[1] || '').trim();
4625
- var val;
4626
- var flag = false;
4627
-
4628
- if (group && field.indexOf('$form.') === 0) {
4629
- var _split = field.split('.');
4630
-
4631
- _split.shift();
4632
-
4633
- if (hasProperty(group.value, _split[0])) {
4634
- flag = true;
4635
- val = get ? get({
4636
- id: '$form.' + _split[0] + '_' + group.rule.__fc__.id,
4637
- getValue: function getValue() {
4638
- return deepGet(group.value, _split);
4639
- }
4640
- }) : deepGet(group.value, _split);
4641
- }
4642
- }
4737
+ var tree = parseTemplateToTree(field);
4738
+ var val = invoke(function () {
4739
+ return treeToVal(tree);
4740
+ });
4643
4741
 
4644
- if (!flag) {
4645
- val = get ? get(field, def) : _this3.fc.getLoadData(field, def);
4742
+ if ((val == null || val === '') && split.length > 1) {
4743
+ val = def;
4646
4744
  }
4647
4745
 
4648
4746
  lastVal = val;
@@ -4967,6 +5065,9 @@
4967
5065
  initNone: function initNone() {
4968
5066
  this.none = !(is.Undef(this.prop.display) || !!this.prop.display);
4969
5067
  },
5068
+ hasHidden: function hasHidden() {
5069
+ return !!this.rule.hidden || (this.parent ? this.parent.hasHidden() : false);
5070
+ },
4970
5071
  injectValidate: function injectValidate() {
4971
5072
  return this.prop.validate;
4972
5073
  },
@@ -5642,10 +5743,11 @@
5642
5743
 
5643
5744
  fields.reduce(function (initial, field) {
5644
5745
  var ctx = (_this3.fieldCtx[field] || []).filter(function (ctx) {
5645
- return !_this3.isIgnore(ctx.rule);
5646
- })[0] || _this3.fieldCtx[field][0];
5746
+ return !_this3.isIgnore(ctx);
5747
+ })[0];
5647
5748
 
5648
- if (_this3.isIgnore(ctx.rule)) {
5749
+ if (!ctx) {
5750
+ ctx = _this3.fieldCtx[field][0];
5649
5751
  ignoreFields.push(field);
5650
5752
  }
5651
5753
 
@@ -5656,8 +5758,8 @@
5656
5758
  this.ignoreFields = ignoreFields;
5657
5759
  this.syncValue();
5658
5760
  },
5659
- isIgnore: function isIgnore(rule) {
5660
- return rule.ignore === true || rule.ignore === 'hidden' && rule.hidden || this.options.ignoreHiddenFields && rule.hidden;
5761
+ isIgnore: function isIgnore(ctx) {
5762
+ return ctx.rule.ignore === true || (ctx.rule.ignore === 'hidden' || this.options.ignoreHiddenFields) && ctx.hasHidden();
5661
5763
  },
5662
5764
  appendValue: function appendValue(rule) {
5663
5765
  if ((!rule.field || !hasProperty(this.appendData, rule.field)) && !this.options.forceCoverValue) {
@@ -6073,7 +6175,6 @@
6073
6175
  }
6074
6176
 
6075
6177
  Object.keys(computedRule).forEach(function (k) {
6076
- var oldValue = undefined;
6077
6178
  var computedValue = vue.computed(function () {
6078
6179
  var item = computedRule[k];
6079
6180
  if (!item) return undefined;
@@ -6081,7 +6182,7 @@
6081
6182
  var value = _this.compute(ctx, item);
6082
6183
 
6083
6184
  if (item.linkage && value === oldValueTag) {
6084
- return oldValue;
6185
+ return oldValueTag;
6085
6186
  }
6086
6187
 
6087
6188
  return value;
@@ -6102,10 +6203,15 @@
6102
6203
  }
6103
6204
 
6104
6205
  ctx.watch.push(vue.watch(computedValue, function (n) {
6105
- oldValue = n;
6206
+ if (n === oldValueTag) {
6207
+ return;
6208
+ }
6209
+
6106
6210
  setTimeout(function () {
6107
6211
  callback(n);
6108
6212
  });
6213
+ }, {
6214
+ deep: true
6109
6215
  }));
6110
6216
  });
6111
6217
  });
@@ -6127,7 +6233,7 @@
6127
6233
  if (before === false) {
6128
6234
  callback();
6129
6235
  } else {
6130
- var key = _this2.validator(value, validate);
6236
+ var key = _this2.validator(ctx, value, validate);
6131
6237
 
6132
6238
  if (!key) {
6133
6239
  if (validate.validator) {
@@ -6180,7 +6286,9 @@
6180
6286
  var formatRule = Array.isArray(invalid.rule) ? invalid.rule.join(',') : '' + invalid.rule;
6181
6287
  return this.api.t(invalid.key === 'required' ? invalid.key : 'validate.' + invalid.key, (_this$api$t = {}, _defineProperty(_this$api$t, invalid.key, formatRule), _defineProperty(_this$api$t, "title", (_ctx$refRule2 = ctx.refRule) === null || _ctx$refRule2 === void 0 ? void 0 : (_ctx$refRule2$__$titl = _ctx$refRule2.__$title) === null || _ctx$refRule2$__$titl === void 0 ? void 0 : _ctx$refRule2$__$titl.value), _this$api$t));
6182
6288
  },
6183
- validator: function validator(value, validate) {
6289
+ validator: function validator(ctx, value, validate) {
6290
+ var _this3 = this;
6291
+
6184
6292
  var isEmpty = is.empty(value);
6185
6293
 
6186
6294
  if (isEmpty) {
@@ -6374,6 +6482,15 @@
6374
6482
  };
6375
6483
  }
6376
6484
 
6485
+ break;
6486
+
6487
+ case 'computed':
6488
+ if (!_this3.compute(ctx, rule)) {
6489
+ return {
6490
+ v: key
6491
+ };
6492
+ }
6493
+
6377
6494
  break;
6378
6495
  }
6379
6496
  };
@@ -6385,7 +6502,7 @@
6385
6502
  }
6386
6503
  },
6387
6504
  compute: function compute(ctx, item) {
6388
- var _this3 = this;
6505
+ var _this4 = this;
6389
6506
 
6390
6507
  var fn;
6391
6508
 
@@ -6411,7 +6528,7 @@
6411
6528
  var field = null;
6412
6529
 
6413
6530
  if (one.variable) {
6414
- field = JSON.stringify(_this3.fc.getLoadData(one.variable) || '');
6531
+ field = JSON.stringify(_this4.fc.getLoadData(one.variable) || '');
6415
6532
  } else if (one.field) {
6416
6533
  field = convertFieldToConditions(one.field || '');
6417
6534
  } else if (!one.mode) {
@@ -6432,11 +6549,11 @@
6432
6549
  flag = false;
6433
6550
  } else if (is.Function(one.handler)) {
6434
6551
  flag = invoke(function () {
6435
- return one.handler(_this3.api, ctx.rule);
6552
+ return one.handler(_this4.api, ctx.rule);
6436
6553
  });
6437
6554
  } else {
6438
6555
  flag = invoke(function () {
6439
- return new Function('$condition', '$val', '$form', '$scope', '$group', '$rule', "with($form){with($scope){with(this){with($group){ return $condition['".concat(one.condition, "'](").concat(field, ", ").concat(compare ? compare : '$val', "); }}}}")).call(_this3.api.form, condition, one.value, _this3.api.top.form, _this3.api.top === _this3.api.scope ? {} : _this3.api.scope.form, group ? _this3.subRuleData[group.id] || {} : {}, ctx.rule);
6556
+ return new Function('$condition', '$val', '$form', '$scope', '$group', '$rule', "with($form){with($scope){with(this){with($group){ return $condition['".concat(one.condition, "'](").concat(field, ", ").concat(compare ? compare : '$val', "); }}}}")).call(_this4.api.form, condition, one.value, _this4.api.top.form, _this4.api.top === _this4.api.scope ? {} : _this4.api.scope.form, group ? _this4.subRuleData[group.id] || {} : {}, ctx.rule);
6440
6557
  });
6441
6558
  }
6442
6559
 
@@ -6465,27 +6582,27 @@
6465
6582
 
6466
6583
  if (item.linkage) {
6467
6584
  return val ? invoke(function () {
6468
- return _this3.computeValue(item.linkage, ctx, group);
6585
+ return _this4.computeValue(item.linkage, ctx, group);
6469
6586
  }, undefined) : oldValueTag;
6470
6587
  }
6471
6588
 
6472
6589
  return val;
6473
6590
  } else if (is.Function(item)) {
6474
6591
  fn = function fn() {
6475
- return item(_this3.api.form, _this3.api);
6592
+ return item(_this4.api.form, _this4.api);
6476
6593
  };
6477
6594
  } else {
6478
6595
  var _group = ctx.getParentGroup();
6479
6596
 
6480
6597
  fn = function fn() {
6481
- return _this3.computeValue(item, ctx, _group);
6598
+ return _this4.computeValue(item, ctx, _group);
6482
6599
  };
6483
6600
  }
6484
6601
 
6485
6602
  return invoke(fn, undefined);
6486
6603
  },
6487
6604
  computeValue: function computeValue(str, ctx, group) {
6488
- var _this4 = this;
6605
+ var _this5 = this;
6489
6606
 
6490
6607
  var that = this;
6491
6608
  var formulas = Object.keys(this.fc.formulas).reduce(function (obj, k) {
@@ -6507,35 +6624,35 @@
6507
6624
  return obj;
6508
6625
  }, {});
6509
6626
  return invoke(function () {
6510
- return new Function('$formulas', '$form', '$scope', '$group', '$rule', '$api', "with($form){with($scope){with(this){with($group){with($formulas){ return ".concat(str, " }}}}}")).call(_this4.api.form, formulas, _this4.api.top.form, _this4.api.top === _this4.api.scope ? {} : _this4.api.scope.form, group ? _this4.subRuleData[group.id] || {} : {}, ctx.rule, _this4.api);
6627
+ return new Function('$formulas', '$form', '$scope', '$group', '$rule', '$api', "with($form){with($scope){with(this){with($group){with($formulas){ return ".concat(str, " }}}}}")).call(_this5.api.form, formulas, _this5.api.top.form, _this5.api.top === _this5.api.scope ? {} : _this5.api.scope.form, group ? _this5.subRuleData[group.id] || {} : {}, ctx.rule, _this5.api);
6511
6628
  }, undefined);
6512
6629
  },
6513
6630
  updateChildren: function updateChildren(ctx, n, o) {
6514
- var _this5 = this;
6631
+ var _this6 = this;
6515
6632
 
6516
6633
  this.deferSyncValue(function () {
6517
6634
  o && o.forEach(function (child) {
6518
6635
  if ((n || []).indexOf(child) === -1 && child && !is.String(child) && child.__fc__ && child.__fc__.parent === ctx) {
6519
- _this5.rmCtx(child.__fc__);
6636
+ _this6.rmCtx(child.__fc__);
6520
6637
  }
6521
6638
  });
6522
6639
 
6523
6640
  if (is.trueArray(n)) {
6524
- _this5.loadChildren(n, ctx);
6641
+ _this6.loadChildren(n, ctx);
6525
6642
 
6526
- _this5.bus.$emit('update', _this5.api);
6643
+ _this6.bus.$emit('update', _this6.api);
6527
6644
  }
6528
6645
  });
6529
6646
  },
6530
6647
  rmSub: function rmSub(sub) {
6531
- var _this6 = this;
6648
+ var _this7 = this;
6532
6649
 
6533
6650
  is.trueArray(sub) && sub.forEach(function (r) {
6534
- r && r.__fc__ && _this6.rmCtx(r.__fc__);
6651
+ r && r.__fc__ && _this7.rmCtx(r.__fc__);
6535
6652
  });
6536
6653
  },
6537
6654
  rmCtx: function rmCtx(ctx) {
6538
- var _this7 = this;
6655
+ var _this8 = this;
6539
6656
 
6540
6657
  if (ctx.deleted) return;
6541
6658
  var id = ctx.id,
@@ -6564,19 +6681,19 @@
6564
6681
  }
6565
6682
 
6566
6683
  this.deferSyncValue(function () {
6567
- if (!_this7.reloading) {
6684
+ if (!_this8.reloading) {
6568
6685
  if (ctx.parser.loadChildren !== false) {
6569
6686
  var children = ctx.getPending('children', ctx.rule.children);
6570
6687
 
6571
6688
  if (is.trueArray(children)) {
6572
6689
  children.forEach(function (h) {
6573
- return h.__fc__ && _this7.rmCtx(h.__fc__);
6690
+ return h && h.__fc__ && _this8.rmCtx(h.__fc__);
6574
6691
  });
6575
6692
  }
6576
6693
  }
6577
6694
 
6578
- if (ctx.root === _this7.rules) {
6579
- _this7.vm.setupState.renderRule();
6695
+ if (ctx.root === _this8.rules) {
6696
+ _this8.vm.setupState.renderRule();
6580
6697
  }
6581
6698
  }
6582
6699
  }, input);
@@ -7017,7 +7134,9 @@
7017
7134
  function CreateNodeFactory() {
7018
7135
  var aliasMap = {};
7019
7136
 
7020
- function CreateNode() {}
7137
+ function CreateNode(vm) {
7138
+ this.vm = vm;
7139
+ }
7021
7140
 
7022
7141
  extend(CreateNode.prototype, {
7023
7142
  make: function make(tag, data, children) {
@@ -7032,7 +7151,7 @@
7032
7151
  }
7033
7152
  },
7034
7153
  h: function h(tag, data, children) {
7035
- var isNativeTag = vue.getCurrentInstance().appContext.config.isNativeTag(tag);
7154
+ var isNativeTag = this.vm.appContext.config.isNativeTag(tag);
7036
7155
 
7037
7156
  if (isNativeTag) {
7038
7157
  delete data.formCreateInject;
@@ -7187,14 +7306,30 @@
7187
7306
  attrs.forEach(function (attr) {
7188
7307
  if (attr && (attr.attr || attr.template)) {
7189
7308
  var fn = function fn(get) {
7309
+ var group;
7310
+
7311
+ if (rule && rule.__fc__) {
7312
+ group = rule.__fc__.getParentGroup();
7313
+ }
7314
+
7190
7315
  var value;
7191
7316
 
7192
7317
  if (attr.template) {
7193
- value = fc.$handle.loadStrVar(attr.template, get);
7318
+ value = fc.$handle.loadStrVar(attr.template, get, group ? {
7319
+ rule: rule,
7320
+ value: fc.$handle.subRuleData[group.id] || {}
7321
+ } : null);
7194
7322
  } else if (attr.handler && is.Function(attr.handler)) {
7195
7323
  value = attr.handler(get, rule, api);
7196
7324
  } else {
7197
- value = get(attr.attr, attr["default"]);
7325
+ value = fc.$handle.loadStrVar("{{".concat(attr.attr, "}}"), get, group ? {
7326
+ rule: rule,
7327
+ value: fc.$handle.subRuleData[group.id] || {}
7328
+ } : null);
7329
+ }
7330
+
7331
+ if ((value == null || value === '') && attr["default"] != null) {
7332
+ value = attr["default"];
7198
7333
  }
7199
7334
 
7200
7335
  if (attr.copy !== false) {
@@ -8330,7 +8465,7 @@
8330
8465
 
8331
8466
  if (!unwatch[id]) {
8332
8467
  return;
8333
- } else if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
8468
+ } else if ((temp instanceof Function || is.Object(temp) || Array.isArray(temp)) && temp === unwatch[id].val || JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
8334
8469
  unwatch[id].val = temp;
8335
8470
  run(true);
8336
8471
  }
@@ -9472,7 +9607,7 @@
9472
9607
  function elmFormCreate() {
9473
9608
  return FormCreateFactory({
9474
9609
  ui: 'element-ui',
9475
- version: '3.2.22',
9610
+ version: '3.2.24',
9476
9611
  manager: manager,
9477
9612
  extendApi: extendApi,
9478
9613
  install: install,