@form-create/element-ui 2.5.28 → 2.5.29

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 v2.5.28
2
+ * @form-create/element-ui v2.5.29
3
3
  * (c) 2018-2023 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -293,19 +293,19 @@
293
293
  }));
294
294
  },
295
295
  update: function update() {
296
- var _this = this;
297
- this.trueValue = this.value ? this.options().filter(function (opt) {
298
- return _this.value.indexOf(opt.value) !== -1;
296
+ var checked = Array.isArray(this.value) ? this.value : [this.value];
297
+ this.trueValue = this.options().filter(function (opt) {
298
+ return checked.indexOf(opt.value) !== -1;
299
299
  }).map(function (option) {
300
300
  return option.label;
301
- }) : [];
301
+ });
302
302
  }
303
303
  },
304
304
  created: function created() {
305
305
  this.update();
306
306
  },
307
307
  render: function render() {
308
- var _this2 = this;
308
+ var _this = this;
309
309
  var h = arguments[0];
310
310
  return h("ElCheckboxGroup", helper([{}, this.formCreateInject.prop, {}, {
311
311
  "props": {
@@ -317,7 +317,7 @@
317
317
  }
318
318
  }]), [this.options().map(function (opt, index) {
319
319
  var props = _objectSpread2({}, opt);
320
- var Type = _this2.type === 'button' ? 'ElCheckboxButton' : 'ElCheckbox';
320
+ var Type = _this.type === 'button' ? 'ElCheckboxButton' : 'ElCheckbox';
321
321
  delete props.value;
322
322
  return h(Type, helper([{}, {
323
323
  "props": props
@@ -1227,7 +1227,7 @@
1227
1227
  }).filter(function (url) {
1228
1228
  return url !== undefined;
1229
1229
  });
1230
- if (this.cacheFiles.length !== files.length) {
1230
+ if (this.cacheFiles.length !== files.length || !files.length) {
1231
1231
  this.cacheFiles = _toConsumableArray(files);
1232
1232
  this.$emit('input', this.limit === 1 ? files[0] || '' : files);
1233
1233
  }
@@ -2759,11 +2759,16 @@
2759
2759
  clearOrgChildren: function clearOrgChildren() {
2760
2760
  this.orgChildren = {};
2761
2761
  },
2762
- getTypeSlot: function getTypeSlot(type) {
2763
- var name = 'type-' + toLine(type);
2762
+ getTypeSlot: function getTypeSlot(ctx) {
2764
2763
  var _fn = function _fn(vm) {
2765
2764
  if (vm) {
2766
- var slot = vm.$scopedSlots[name] || vm.$scopedSlots['type-' + type];
2765
+ var slot = undefined;
2766
+ if (ctx.rule.field) {
2767
+ slot = vm.$scopedSlots['field-' + toLine(ctx.rule.field)] || vm.$scopedSlots['field-' + ctx.rule.field];
2768
+ }
2769
+ if (!slot) {
2770
+ slot = vm.$scopedSlots['type-' + toLine(ctx.type)] || vm.$scopedSlots['type-' + ctx.type];
2771
+ }
2767
2772
  if (slot) {
2768
2773
  return slot;
2769
2774
  }
@@ -2884,12 +2889,16 @@
2884
2889
  vn.data.key = key;
2885
2890
  return vn;
2886
2891
  },
2887
- parseSide: function parseSide(side) {
2888
- return is.Object(side) ? mergeRule({}, side) : side;
2892
+ parseSide: function parseSide(side, ctx) {
2893
+ return is.Object(side) ? mergeRule({
2894
+ props: {
2895
+ formCreateInject: ctx.prop.props.formCreateInject
2896
+ }
2897
+ }, side) : side;
2889
2898
  },
2890
2899
  renderSides: function renderSides(vn, ctx, temp) {
2891
2900
  var prop = ctx[temp ? 'rule' : 'prop'];
2892
- return [this.renderRule(this.parseSide(prop.prefix)), vn, this.renderRule(this.parseSide(prop.suffix))];
2901
+ return [this.renderRule(this.parseSide(prop.prefix, ctx)), vn, this.renderRule(this.parseSide(prop.suffix, ctx))];
2893
2902
  },
2894
2903
  renderSlot: function renderSlot(ctx, slot) {
2895
2904
  return ctx.rule.slot === slot ? this.renderCtx(ctx) : undefined;
@@ -2942,7 +2951,7 @@
2942
2951
  } else if (ctx.parser.loadChildren !== false) {
2943
2952
  children = this.renderChildren(ctx);
2944
2953
  }
2945
- var slot = this.getTypeSlot(ctx.type);
2954
+ var slot = this.getTypeSlot(ctx);
2946
2955
  if (slot) {
2947
2956
  vn = slot({
2948
2957
  rule: rule,
@@ -3759,7 +3768,7 @@
3759
3768
  ctx.updated = true;
3760
3769
  if (is.Function(r.update)) {
3761
3770
  _this6.bus.$once('load-end', function () {
3762
- _this6.refreshUpdate(ctx, r.value);
3771
+ _this6.refreshUpdate(ctx, r.value, 'init');
3763
3772
  });
3764
3773
  }
3765
3774
  _this6.effect(ctx, 'loaded');
@@ -4038,11 +4047,13 @@
4038
4047
  isQuote: function isQuote(ctx, value) {
4039
4048
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
4040
4049
  },
4041
- refreshUpdate: function refreshUpdate(ctx, val) {
4050
+ refreshUpdate: function refreshUpdate(ctx, val, origin) {
4042
4051
  var _this4 = this;
4043
4052
  if (is.Function(ctx.rule.update)) {
4044
4053
  var state = invoke(function () {
4045
- return ctx.rule.update(val, ctx.origin, _this4.api);
4054
+ return ctx.rule.update(val, ctx.origin, _this4.api, {
4055
+ origin: origin || 'change'
4056
+ });
4046
4057
  });
4047
4058
  if (state === undefined) return;
4048
4059
  ctx.rule.hidden = state === true;
@@ -4052,21 +4063,21 @@
4052
4063
  this.refreshRule(ctx, val);
4053
4064
  this.bus.$emit('change-' + ctx.field, val);
4054
4065
  },
4055
- refreshRule: function refreshRule(ctx, val) {
4066
+ refreshRule: function refreshRule(ctx, val, origin) {
4056
4067
  if (this.refreshControl(ctx)) {
4057
4068
  this.$render.clearCacheAll();
4058
4069
  this.loadRule();
4059
4070
  this.vm.$emit('update', this.api);
4060
4071
  this.refresh();
4061
4072
  }
4062
- this.refreshUpdate(ctx, val);
4073
+ this.refreshUpdate(ctx, val, origin);
4063
4074
  },
4064
4075
  appendLink: function appendLink(ctx) {
4065
4076
  var _this5 = this;
4066
4077
  var link = ctx.rule.link;
4067
4078
  is.trueArray(link) && link.forEach(function (field) {
4068
4079
  var fn = function fn() {
4069
- return _this5.refreshRule(ctx, ctx.rule.value);
4080
+ return _this5.refreshRule(ctx, ctx.rule.value, 'link');
4070
4081
  };
4071
4082
  _this5.bus.$on('change-' + field, fn);
4072
4083
  ctx.linkOn.push(function () {
@@ -4696,6 +4707,35 @@
4696
4707
  render: function render(children) {}
4697
4708
  });
4698
4709
 
4710
+ var componentValidate = {
4711
+ name: 'componentValidate',
4712
+ load: function load(attr, rule, api) {
4713
+ var method = attr.getValue();
4714
+ if (!method) {
4715
+ attr.clearProp();
4716
+ api.clearValidateState([rule.field]);
4717
+ } else {
4718
+ attr.getProp().validate = [{
4719
+ validator: function validator() {
4720
+ var ctx = byCtx(rule);
4721
+ if (ctx) {
4722
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4723
+ args[_key] = arguments[_key];
4724
+ }
4725
+ return api.exec.apply(api, [ctx.id, method === true ? 'formCreateValidate' : method].concat(args, [{
4726
+ attr: attr,
4727
+ rule: rule,
4728
+ api: api
4729
+ }]));
4730
+ }
4731
+ }
4732
+ }];
4733
+ }
4734
+ },
4735
+ watch: function watch() {
4736
+ componentValidate.load.apply(componentValidate, arguments);
4737
+ }
4738
+ };
4699
4739
  var fetch$1 = function fetch(fc) {
4700
4740
  function parseOpt(option) {
4701
4741
  if (is.String(option)) {
@@ -4825,7 +4865,8 @@
4825
4865
  }
4826
4866
  var $provider = {
4827
4867
  fetch: fetch$1,
4828
- required: $required
4868
+ required: $required,
4869
+ componentValidate: componentValidate
4829
4870
  };
4830
4871
 
4831
4872
  var name = 'html';
@@ -5414,11 +5455,27 @@
5414
5455
  }
5415
5456
  }
5416
5457
  var manager = {
5417
- validate: function validate(call) {
5418
- this.form().validate(call);
5458
+ validate: function validate() {
5459
+ var form = this.form();
5460
+ if (form) {
5461
+ return form.validate();
5462
+ }
5463
+ return new Promise(function (v) {
5464
+ return v();
5465
+ });
5419
5466
  },
5420
- validateField: function validateField(field, call) {
5421
- this.form().validateField(field, call);
5467
+ validateField: function validateField(field) {
5468
+ var form = this.form();
5469
+ if (form) {
5470
+ return new Promise(function (resolve, reject) {
5471
+ form.validateField(field, function (e) {
5472
+ e ? reject(e) : resolve(null);
5473
+ });
5474
+ });
5475
+ }
5476
+ return new Promise(function (v) {
5477
+ return v();
5478
+ });
5422
5479
  },
5423
5480
  clearValidateState: function clearValidateState(ctx) {
5424
5481
  var fItem = this.vm.$refs[ctx.wrapRef];
@@ -5732,87 +5789,47 @@
5732
5789
  function extendApi(api, h) {
5733
5790
  extend(api, {
5734
5791
  validate: function validate(callback) {
5735
- var flag;
5736
- var forms = api.children;
5737
- var len = forms.length;
5738
- var validate = function validate() {
5739
- h.$manager.validate(function () {
5740
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5741
- args[_key] = arguments[_key];
5742
- }
5743
- if (!args[0] || !flag) {
5744
- flag = args;
5745
- }
5746
- callback && callback.apply(void 0, _toConsumableArray(flag));
5747
- });
5748
- };
5749
- var validFn = function validFn(args) {
5750
- setTimeout(function () {
5751
- if (!args[0]) {
5752
- if (!flag) {
5753
- flag = args;
5754
- }
5755
- }
5756
- if (! --len) {
5757
- validate();
5758
- }
5792
+ return new Promise(function (resolve, reject) {
5793
+ var forms = api.children;
5794
+ var all = [h.$manager.validate()];
5795
+ forms.forEach(function (v) {
5796
+ all.push(v.validate());
5759
5797
  });
5760
- };
5761
- forms.forEach(function (form) {
5762
- form.validate(function () {
5763
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
5764
- args[_key2] = arguments[_key2];
5765
- }
5766
- return validFn(args);
5798
+ Promise.all(all).then(function () {
5799
+ resolve(true);
5800
+ callback && callback(true);
5801
+ })["catch"](function (e) {
5802
+ reject(e);
5803
+ callback && callback(e);
5804
+ h.vm.$emit('validate-fail', e, {
5805
+ api: api
5806
+ });
5767
5807
  });
5768
5808
  });
5769
- if (!len) {
5770
- validate();
5771
- }
5772
5809
  },
5773
5810
  validateField: function validateField(field, callback) {
5774
- var ctx = h.getFieldCtx(field);
5775
- if (!ctx) return;
5776
- var sub = h.subForm[ctx.id];
5777
- var len = 0;
5778
- var flag;
5779
- var validate = function validate() {
5780
- h.$manager.validateField(ctx.id, function () {
5781
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
5782
- args[_key3] = arguments[_key3];
5783
- }
5784
- if (args[0]) {
5785
- flag = args;
5786
- } else if (flag) {
5787
- return callback && callback('子表单验证未通过', flag[1]);
5788
- }
5789
- callback && callback.apply(void 0, _toConsumableArray(flag || args));
5790
- });
5791
- };
5792
- var validFn = function validFn(args) {
5793
- setTimeout(function () {
5794
- if (!args[0]) {
5795
- if (!flag) {
5796
- flag = args;
5797
- }
5798
- }
5799
- if (! --len) {
5800
- validate();
5801
- }
5811
+ return new Promise(function (resolve, reject) {
5812
+ var ctx = h.getFieldCtx(field);
5813
+ if (!ctx) return;
5814
+ var sub = h.subForm[ctx.id];
5815
+ var all = [h.$manager.validateField(ctx.id)];
5816
+ toArray(sub).forEach(function (v) {
5817
+ all.push(v.validate()["catch"](function () {
5818
+ return Promise.reject('子表单验证未通过');
5819
+ }));
5802
5820
  });
5803
- };
5804
- sub && toArray(sub).forEach(function (form) {
5805
- len++;
5806
- form.validate(function () {
5807
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
5808
- args[_key4] = arguments[_key4];
5809
- }
5810
- return validFn(args);
5821
+ Promise.all(all).then(function () {
5822
+ resolve(null);
5823
+ callback && callback(null);
5824
+ })["catch"](function (e) {
5825
+ reject(e);
5826
+ callback && callback(e);
5827
+ h.vm.$emit('validate-field-fail', e, {
5828
+ field: field,
5829
+ api: api
5830
+ });
5811
5831
  });
5812
5832
  });
5813
- if (!len) {
5814
- validate();
5815
- }
5816
5833
  },
5817
5834
  clearValidateState: function clearValidateState(fields) {
5818
5835
  var _this = this;
@@ -5933,7 +5950,7 @@
5933
5950
  function elmFormCreate() {
5934
5951
  return FormCreateFactory({
5935
5952
  ui: "".concat("element-ui"),
5936
- version: "".concat("2.5.28"),
5953
+ version: "".concat("2.5.29"),
5937
5954
  manager: manager,
5938
5955
  extendApi: extendApi,
5939
5956
  install: install,