@form-create/iview 2.5.28 → 2.5.31

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/iview v2.5.28
2
+ * @form-create/iview v2.5.31
3
3
  * (c) 2018-2023 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -292,12 +292,12 @@
292
292
  }));
293
293
  },
294
294
  update: function update() {
295
- var _this = this;
296
- this.trueValue = this.value ? this.options().filter(function (opt) {
297
- return _this.value.indexOf(opt.value) !== -1;
295
+ var checked = Array.isArray(this.value) ? this.value : [this.value];
296
+ this.trueValue = this.options().filter(function (opt) {
297
+ return checked.indexOf(opt.value) !== -1;
298
298
  }).map(function (option) {
299
299
  return option.label;
300
- }) : [];
300
+ });
301
301
  }
302
302
  },
303
303
  created: function created() {
@@ -1207,7 +1207,7 @@
1207
1207
  }).filter(function (url) {
1208
1208
  return url !== undefined;
1209
1209
  });
1210
- if (this.cacheFiles.length !== files.length) {
1210
+ if (this.cacheFiles.length !== files.length || !files.length) {
1211
1211
  this.cacheFiles = _toConsumableArray(files);
1212
1212
  this.$emit('input', this.maxLength === 1 ? files[0] || '' : files);
1213
1213
  }
@@ -2090,7 +2090,7 @@
2090
2090
  }, space);
2091
2091
  }
2092
2092
  function makeFn(fn) {
2093
- return eval('(' + FUNCTION + '(){return ' + fn + ' })()');
2093
+ return new Function('return ' + fn)();
2094
2094
  }
2095
2095
  function parseFn(fn, mode) {
2096
2096
  if (fn && is.String(fn) && fn.length > 4) {
@@ -2766,11 +2766,16 @@
2766
2766
  clearOrgChildren: function clearOrgChildren() {
2767
2767
  this.orgChildren = {};
2768
2768
  },
2769
- getTypeSlot: function getTypeSlot(type) {
2770
- var name = 'type-' + toLine(type);
2769
+ getTypeSlot: function getTypeSlot(ctx) {
2771
2770
  var _fn = function _fn(vm) {
2772
2771
  if (vm) {
2773
- var slot = vm.$scopedSlots[name] || vm.$scopedSlots['type-' + type];
2772
+ var slot = undefined;
2773
+ if (ctx.rule.field) {
2774
+ slot = vm.$scopedSlots['field-' + toLine(ctx.rule.field)] || vm.$scopedSlots['field-' + ctx.rule.field];
2775
+ }
2776
+ if (!slot) {
2777
+ slot = vm.$scopedSlots['type-' + toLine(ctx.type)] || vm.$scopedSlots['type-' + ctx.type];
2778
+ }
2774
2779
  if (slot) {
2775
2780
  return slot;
2776
2781
  }
@@ -2891,12 +2896,16 @@
2891
2896
  vn.data.key = key;
2892
2897
  return vn;
2893
2898
  },
2894
- parseSide: function parseSide(side) {
2895
- return is.Object(side) ? mergeRule({}, side) : side;
2899
+ parseSide: function parseSide(side, ctx) {
2900
+ return is.Object(side) ? mergeRule({
2901
+ props: {
2902
+ formCreateInject: ctx.prop.props.formCreateInject
2903
+ }
2904
+ }, side) : side;
2896
2905
  },
2897
2906
  renderSides: function renderSides(vn, ctx, temp) {
2898
2907
  var prop = ctx[temp ? 'rule' : 'prop'];
2899
- return [this.renderRule(this.parseSide(prop.prefix)), vn, this.renderRule(this.parseSide(prop.suffix))];
2908
+ return [this.renderRule(this.parseSide(prop.prefix, ctx)), vn, this.renderRule(this.parseSide(prop.suffix, ctx))];
2900
2909
  },
2901
2910
  renderSlot: function renderSlot(ctx, slot) {
2902
2911
  return ctx.rule.slot === slot ? this.renderCtx(ctx) : undefined;
@@ -2949,7 +2958,7 @@
2949
2958
  } else if (ctx.parser.loadChildren !== false) {
2950
2959
  children = this.renderChildren(ctx);
2951
2960
  }
2952
- var slot = this.getTypeSlot(ctx.type);
2961
+ var slot = this.getTypeSlot(ctx);
2953
2962
  if (slot) {
2954
2963
  vn = slot({
2955
2964
  rule: rule,
@@ -3766,7 +3775,7 @@
3766
3775
  ctx.updated = true;
3767
3776
  if (is.Function(r.update)) {
3768
3777
  _this6.bus.$once('load-end', function () {
3769
- _this6.refreshUpdate(ctx, r.value);
3778
+ _this6.refreshUpdate(ctx, r.value, 'init');
3770
3779
  });
3771
3780
  }
3772
3781
  _this6.effect(ctx, 'loaded');
@@ -4045,11 +4054,13 @@
4045
4054
  isQuote: function isQuote(ctx, value) {
4046
4055
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
4047
4056
  },
4048
- refreshUpdate: function refreshUpdate(ctx, val) {
4057
+ refreshUpdate: function refreshUpdate(ctx, val, origin) {
4049
4058
  var _this4 = this;
4050
4059
  if (is.Function(ctx.rule.update)) {
4051
4060
  var state = invoke(function () {
4052
- return ctx.rule.update(val, ctx.origin, _this4.api);
4061
+ return ctx.rule.update(val, ctx.origin, _this4.api, {
4062
+ origin: origin || 'change'
4063
+ });
4053
4064
  });
4054
4065
  if (state === undefined) return;
4055
4066
  ctx.rule.hidden = state === true;
@@ -4059,21 +4070,21 @@
4059
4070
  this.refreshRule(ctx, val);
4060
4071
  this.bus.$emit('change-' + ctx.field, val);
4061
4072
  },
4062
- refreshRule: function refreshRule(ctx, val) {
4073
+ refreshRule: function refreshRule(ctx, val, origin) {
4063
4074
  if (this.refreshControl(ctx)) {
4064
4075
  this.$render.clearCacheAll();
4065
4076
  this.loadRule();
4066
4077
  this.vm.$emit('update', this.api);
4067
4078
  this.refresh();
4068
4079
  }
4069
- this.refreshUpdate(ctx, val);
4080
+ this.refreshUpdate(ctx, val, origin);
4070
4081
  },
4071
4082
  appendLink: function appendLink(ctx) {
4072
4083
  var _this5 = this;
4073
4084
  var link = ctx.rule.link;
4074
4085
  is.trueArray(link) && link.forEach(function (field) {
4075
4086
  var fn = function fn() {
4076
- return _this5.refreshRule(ctx, ctx.rule.value);
4087
+ return _this5.refreshRule(ctx, ctx.rule.value, 'link');
4077
4088
  };
4078
4089
  _this5.bus.$on('change-' + field, fn);
4079
4090
  ctx.linkOn.push(function () {
@@ -4703,6 +4714,35 @@
4703
4714
  render: function render(children) {}
4704
4715
  });
4705
4716
 
4717
+ var componentValidate = {
4718
+ name: 'componentValidate',
4719
+ load: function load(attr, rule, api) {
4720
+ var method = attr.getValue();
4721
+ if (!method) {
4722
+ attr.clearProp();
4723
+ api.clearValidateState([rule.field]);
4724
+ } else {
4725
+ attr.getProp().validate = [{
4726
+ validator: function validator() {
4727
+ var ctx = byCtx(rule);
4728
+ if (ctx) {
4729
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4730
+ args[_key] = arguments[_key];
4731
+ }
4732
+ return api.exec.apply(api, [ctx.id, method === true ? 'formCreateValidate' : method].concat(args, [{
4733
+ attr: attr,
4734
+ rule: rule,
4735
+ api: api
4736
+ }]));
4737
+ }
4738
+ }
4739
+ }];
4740
+ }
4741
+ },
4742
+ watch: function watch() {
4743
+ componentValidate.load.apply(componentValidate, arguments);
4744
+ }
4745
+ };
4706
4746
  var fetch$1 = function fetch(fc) {
4707
4747
  function parseOpt(option) {
4708
4748
  if (is.String(option)) {
@@ -4832,7 +4872,8 @@
4832
4872
  }
4833
4873
  var $provider = {
4834
4874
  fetch: fetch$1,
4835
- required: $required
4875
+ required: $required,
4876
+ componentValidate: componentValidate
4836
4877
  };
4837
4878
 
4838
4879
  var name = 'html';
@@ -5446,11 +5487,31 @@
5446
5487
  }
5447
5488
  }
5448
5489
  var manager = {
5449
- validate: function validate(call) {
5450
- this.form().validate(call);
5490
+ validate: function validate() {
5491
+ var form = this.form();
5492
+ if (form) {
5493
+ return new Promise(function (resolve, reject) {
5494
+ form.validate().then(function (flag) {
5495
+ flag ? resolve(true) : reject(false);
5496
+ });
5497
+ });
5498
+ }
5499
+ return new Promise(function (v) {
5500
+ return v();
5501
+ });
5451
5502
  },
5452
- validateField: function validateField(field, call) {
5453
- this.form().validateField(field, call);
5503
+ validateField: function validateField(field) {
5504
+ var form = this.form();
5505
+ if (form) {
5506
+ return new Promise(function (resolve, reject) {
5507
+ form.validateField(field, function (e) {
5508
+ e ? reject(e) : resolve(null);
5509
+ });
5510
+ });
5511
+ }
5512
+ return new Promise(function (v) {
5513
+ return v();
5514
+ });
5454
5515
  },
5455
5516
  clearValidateState: function clearValidateState(ctx) {
5456
5517
  var fItem = this.vm.$refs[ctx.wrapRef];
@@ -5778,87 +5839,47 @@
5778
5839
  function extendApi(api, h) {
5779
5840
  extend(api, {
5780
5841
  validate: function validate(callback) {
5781
- var flag;
5782
- var forms = api.children;
5783
- var len = forms.length;
5784
- var validate = function validate() {
5785
- h.$manager.validate(function () {
5786
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5787
- args[_key] = arguments[_key];
5788
- }
5789
- if (!args[0] || !flag) {
5790
- flag = args;
5791
- }
5792
- callback && callback.apply(void 0, _toConsumableArray(flag));
5842
+ return new Promise(function (resolve, reject) {
5843
+ var forms = api.children;
5844
+ var all = [h.$manager.validate()];
5845
+ forms.forEach(function (v) {
5846
+ all.push(v.validate());
5793
5847
  });
5794
- };
5795
- var validFn = function validFn(args) {
5796
- setTimeout(function () {
5797
- if (!args[0]) {
5798
- if (!flag) {
5799
- flag = args;
5800
- }
5801
- }
5802
- if (! --len) {
5803
- validate();
5804
- }
5805
- });
5806
- };
5807
- forms.forEach(function (form) {
5808
- form.validate(function () {
5809
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
5810
- args[_key2] = arguments[_key2];
5811
- }
5812
- return validFn(args);
5848
+ Promise.all(all).then(function () {
5849
+ resolve(true);
5850
+ callback && callback(true);
5851
+ })["catch"](function (e) {
5852
+ reject(e);
5853
+ callback && callback(e);
5854
+ h.vm.$emit('validate-fail', e, {
5855
+ api: api
5856
+ });
5813
5857
  });
5814
5858
  });
5815
- if (!len) {
5816
- validate();
5817
- }
5818
5859
  },
5819
5860
  validateField: function validateField(field, callback) {
5820
- var ctx = h.getFieldCtx(field);
5821
- if (!ctx) return;
5822
- var sub = h.subForm[ctx.id];
5823
- var len = 0;
5824
- var flag;
5825
- var validate = function validate() {
5826
- h.$manager.validateField(ctx.id, function () {
5827
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
5828
- args[_key3] = arguments[_key3];
5829
- }
5830
- if (args[0]) {
5831
- flag = args;
5832
- } else if (flag) {
5833
- return callback && callback('子表单验证未通过');
5834
- }
5835
- callback && callback.apply(void 0, _toConsumableArray(flag || args));
5836
- });
5837
- };
5838
- var validFn = function validFn(args) {
5839
- setTimeout(function () {
5840
- if (!args[0]) {
5841
- if (!flag) {
5842
- flag = args;
5843
- }
5844
- }
5845
- if (! --len) {
5846
- validate();
5847
- }
5861
+ return new Promise(function (resolve, reject) {
5862
+ var ctx = h.getFieldCtx(field);
5863
+ if (!ctx) return;
5864
+ var sub = h.subForm[ctx.id];
5865
+ var all = [h.$manager.validateField(ctx.id)];
5866
+ toArray(sub).forEach(function (v) {
5867
+ all.push(v.validate()["catch"](function () {
5868
+ return Promise.reject('子表单验证未通过');
5869
+ }));
5848
5870
  });
5849
- };
5850
- sub && toArray(sub).forEach(function (form) {
5851
- len++;
5852
- form.validate(function () {
5853
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
5854
- args[_key4] = arguments[_key4];
5855
- }
5856
- return validFn(args);
5871
+ Promise.all(all).then(function () {
5872
+ resolve(null);
5873
+ callback && callback(null);
5874
+ })["catch"](function (e) {
5875
+ reject(e);
5876
+ callback && callback(e);
5877
+ h.vm.$emit('validate-field-fail', e, {
5878
+ field: field,
5879
+ api: api
5880
+ });
5857
5881
  });
5858
5882
  });
5859
- if (!len) {
5860
- validate();
5861
- }
5862
5883
  },
5863
5884
  clearValidateState: function clearValidateState(fields) {
5864
5885
  var _this = this;
@@ -5979,7 +6000,7 @@
5979
6000
  function ivuFormCreate() {
5980
6001
  return FormCreateFactory({
5981
6002
  ui: "".concat("iview"),
5982
- version: "".concat("2.5.28"),
6003
+ version: "".concat("2.5.31"),
5983
6004
  manager: manager,
5984
6005
  install: install,
5985
6006
  extendApi: extendApi,