@form-create/element-ui 2.5.32 → 2.5.34

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,6 +1,6 @@
1
1
  /*!
2
- * @form-create/element-ui v2.5.32
3
- * (c) 2018-2023 xaboy
2
+ * @form-create/element-ui v2.5.34
3
+ * (c) 2018-2024 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
6
6
  */
@@ -947,10 +947,7 @@
947
947
  }
948
948
  },
949
949
  render: function render(h, ctx) {
950
- var options = ctx.props.formCreateInject.options;
951
- return h("ElSelect", helper([{}, ctx.data, {
952
- "ref": "el"
953
- }]), [(Array.isArray(options) ? options : []).map(function (props, index) {
950
+ var makeOption = function makeOption(props, index) {
954
951
  var slot = props.slot;
955
952
  return h("ElOption", helper([{}, {
956
953
  "props": props
@@ -959,6 +956,22 @@
959
956
  }]), [slot ? h("template", {
960
957
  "slot": props.slotName || 'default'
961
958
  }, [is.Function(slot) ? props.slot(h) : slot]) : null]);
959
+ };
960
+ var makeOptionGroup = function makeOptionGroup(props, index) {
961
+ return h("ElOptionGroup", {
962
+ "attrs": {
963
+ "label": props.label
964
+ },
965
+ "key": '' + index + '-' + props.label
966
+ }, [is.trueArray(props.options) && props.options.map(function (v, index) {
967
+ return makeOption(v, index);
968
+ })]);
969
+ };
970
+ var options = ctx.props.formCreateInject.options;
971
+ return h("ElSelect", helper([{}, ctx.data, {
972
+ "ref": "el"
973
+ }]), [(Array.isArray(options) ? options : []).map(function (props, index) {
974
+ return hasProperty(props || '', 'options') ? makeOptionGroup(props, index) : makeOption(props, index);
962
975
  }), ctx.children]);
963
976
  },
964
977
  mounted: function mounted() {
@@ -1504,9 +1517,6 @@
1504
1517
  n.forEach(function (val, i) {
1505
1518
  _this2.setValue(keys[i], n[i]);
1506
1519
  });
1507
- if (o.length && !n.length) {
1508
- this.input([]);
1509
- }
1510
1520
  }
1511
1521
  }
1512
1522
  },
@@ -1548,7 +1558,7 @@
1548
1558
  return;
1549
1559
  }
1550
1560
  this.cache(key, value);
1551
- $f.coverValue(value || {});
1561
+ $f && $f.coverValue(value || {});
1552
1562
  },
1553
1563
  addRule: function addRule(i, emit) {
1554
1564
  var _this4 = this;
@@ -3580,7 +3590,8 @@
3580
3590
  vm: handle.vm,
3581
3591
  trueType: handle.getType(this.originType),
3582
3592
  vNode: handle.$render.vNode,
3583
- updated: false
3593
+ updated: false,
3594
+ cacheValue: this.rule.value
3584
3595
  });
3585
3596
  !init && this.unwatch();
3586
3597
  this.watchTo();
@@ -3823,6 +3834,7 @@
3823
3834
  ctx.root = rules;
3824
3835
  _this6.setCtx(ctx);
3825
3836
  !isCopy && !isInit && _this6.effect(ctx, 'load');
3837
+ _this6.effect(ctx, 'created');
3826
3838
  ctx.parser.loadChildren === false || loadChildren(ctx.rule.children, ctx);
3827
3839
  if (!parent) {
3828
3840
  var _preIndex = preIndex(index);
@@ -4508,6 +4520,7 @@
4508
4520
  data.mergeProp = function (prop) {
4509
4521
  return mergeRule(data.getProp(), [prop]);
4510
4522
  };
4523
+ data.id = ctx.id;
4511
4524
  }
4512
4525
  _this4.bus.$emit("p:".concat(attr, ":").concat(_type, ":").concat(p.input ? 1 : 0), event, [data, rule, _this4.api]);
4513
4526
  });
@@ -4521,9 +4534,12 @@
4521
4534
  }
4522
4535
  function getComponent(p) {
4523
4536
  var c = p.components;
4524
- if (Array.isArray(c)) return unique(c.filter(function (v) {
4525
- return v !== '*';
4526
- }));else if (is.String(c)) return [c];else return false;
4537
+ if (Array.isArray(c)) {
4538
+ var arr = unique(c.filter(function (v) {
4539
+ return v !== '*';
4540
+ }));
4541
+ return arr.length ? arr : false;
4542
+ } else if (is.String(c)) return [c];else return false;
4527
4543
  }
4528
4544
 
4529
4545
  function Handler(fc) {
@@ -4755,6 +4771,19 @@
4755
4771
  form: function form() {
4756
4772
  return this.vm.$refs[this.ref];
4757
4773
  },
4774
+ getSlot: function getSlot(name) {
4775
+ var _fn = function _fn(vm) {
4776
+ if (vm) {
4777
+ var slot = vm.$scopedSlots[name];
4778
+ if (slot) {
4779
+ return slot;
4780
+ }
4781
+ return _fn(vm.$pfc);
4782
+ }
4783
+ return undefined;
4784
+ };
4785
+ return _fn(this.vm);
4786
+ },
4758
4787
  mergeOptions: function mergeOptions(args, opt) {
4759
4788
  var _this2 = this;
4760
4789
  return mergeProps(args.map(function (v) {
@@ -4776,6 +4805,52 @@
4776
4805
  render: function render(children) {}
4777
4806
  });
4778
4807
 
4808
+ var loadData = function loadData(fc) {
4809
+ var loadData = {
4810
+ name: 'loadData',
4811
+ _fn: [],
4812
+ created: function created(inject, rule, api) {
4813
+ this.deleted(inject);
4814
+ var attrs = toArray(inject.getValue());
4815
+ var events = [];
4816
+ attrs.forEach(function (attr) {
4817
+ if (attr) {
4818
+ var on = function on() {
4819
+ if (attr.watch !== false) {
4820
+ fc.bus.$off('p.loadData.' + attr.attr, on);
4821
+ fc.bus.$once('p.loadData.' + attr.attr, on);
4822
+ }
4823
+ var value = undefined;
4824
+ if (attr.attr) {
4825
+ value = fc.loadData[attr.attr] || attr["default"];
4826
+ if (attr.copy) {
4827
+ value = deepCopy(value);
4828
+ }
4829
+ }
4830
+ deepSet(inject.getProp(), attr.to || 'options', value);
4831
+ api.sync(rule);
4832
+ };
4833
+ events.push(function () {
4834
+ return fc.bus.$off('p.loadData.' + attr.attr, on);
4835
+ });
4836
+ on();
4837
+ }
4838
+ });
4839
+ this._fn[inject.id] = events;
4840
+ },
4841
+ deleted: function deleted(inject) {
4842
+ if (this._fn[inject.id]) {
4843
+ this._fn[inject.id].forEach(function (un) {
4844
+ un();
4845
+ });
4846
+ delete this._fn[inject.id];
4847
+ }
4848
+ inject.clearProp();
4849
+ }
4850
+ };
4851
+ loadData.watch = loadData.created;
4852
+ return loadData;
4853
+ };
4779
4854
  var componentValidate = {
4780
4855
  name: 'componentValidate',
4781
4856
  load: function load(attr, rule, api) {
@@ -4817,12 +4892,21 @@
4817
4892
  }
4818
4893
  function run(inject, rule, api) {
4819
4894
  var option = inject.value;
4895
+ var set = function set(val) {
4896
+ if (val === undefined) {
4897
+ inject.clearProp();
4898
+ api.sync(rule);
4899
+ } else {
4900
+ deepSet(inject.getProp(), option.to || 'options', val);
4901
+ }
4902
+ };
4820
4903
  if (is.Function(option)) {
4821
4904
  option = option(rule, api);
4822
4905
  }
4823
4906
  option = parseOpt(option);
4824
4907
  if (!option || !option.action) {
4825
- return false;
4908
+ set(undefined);
4909
+ return;
4826
4910
  }
4827
4911
  if (!option.to) {
4828
4912
  option.to = 'options';
@@ -4835,61 +4919,66 @@
4835
4919
  return true;
4836
4920
  }
4837
4921
  };
4838
- var set = function set(val) {
4839
- if (val === undefined) {
4840
- inject.clearProp();
4922
+ var config = _objectSpread2(_objectSpread2({
4923
+ headers: {}
4924
+ }, option), {}, {
4925
+ onSuccess: function onSuccess(body, flag) {
4926
+ if (check()) return;
4927
+ var fn = function fn(v) {
4928
+ return flag ? v : v.data;
4929
+ };
4930
+ if (is.Function(option.parse)) {
4931
+ fn = option.parse;
4932
+ } else if (option.parse && is.String(option.parse)) {
4933
+ fn = function fn(v) {
4934
+ option.parse.split('.').forEach(function (k) {
4935
+ if (v) {
4936
+ v = v[k];
4937
+ }
4938
+ });
4939
+ return v;
4940
+ };
4941
+ }
4942
+ set(fn(body, rule, api));
4841
4943
  api.sync(rule);
4842
- } else {
4843
- deepSet(inject.getProp(), option.to, val);
4944
+ },
4945
+ onError: function onError(e) {
4946
+ set(undefined);
4947
+ if (check()) return;
4948
+ (_onError || function (e) {
4949
+ return err(e.message || 'fetch fail ' + option.action);
4950
+ })(e, rule, api);
4844
4951
  }
4845
- };
4952
+ });
4953
+ fc.options.beforeFetch && invoke(function () {
4954
+ return fc.options.beforeFetch(config, {
4955
+ rule: rule,
4956
+ api: api
4957
+ });
4958
+ });
4959
+ if (is.Function(option.action)) {
4960
+ option.action(rule, api).then(function (val) {
4961
+ config.onSuccess(val, true);
4962
+ })["catch"](function (e) {
4963
+ config.onError(e);
4964
+ });
4965
+ return;
4966
+ }
4846
4967
  invoke(function () {
4847
- return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4848
- onSuccess: function onSuccess(body) {
4849
- if (check()) return;
4850
- var fn = function fn(v) {
4851
- return v.data;
4852
- };
4853
- if (is.Function(option.parse)) {
4854
- fn = option.parse;
4855
- } else if (option.parse && is.String(option.parse)) {
4856
- fn = function fn(v) {
4857
- option.parse.split('.').forEach(function (k) {
4858
- if (v) {
4859
- v = v[k];
4860
- }
4861
- });
4862
- return v;
4863
- };
4864
- }
4865
- set(fn(body, rule, api));
4866
- api.sync(rule);
4867
- },
4868
- onError: function onError(e) {
4869
- set(undefined);
4870
- if (check()) return;
4871
- (_onError || function (e) {
4872
- return err(e.message || 'fetch fail ' + option.action);
4873
- })(e, rule, api);
4874
- }
4875
- }), {
4968
+ return fc.create.fetch(config, {
4876
4969
  inject: inject,
4877
4970
  rule: rule,
4878
4971
  api: api
4879
4972
  });
4880
4973
  });
4881
- return true;
4882
4974
  }
4883
4975
  return {
4884
4976
  name: 'fetch',
4885
4977
  loaded: function loaded() {
4886
4978
  run.apply(void 0, arguments);
4887
4979
  },
4888
- watch: function watch(inject, rule, api) {
4889
- if (!run(inject, rule, api)) {
4890
- inject.clearProp();
4891
- api.sync(rule);
4892
- }
4980
+ watch: function watch() {
4981
+ run.apply(void 0, arguments);
4893
4982
  }
4894
4983
  };
4895
4984
  };
@@ -4943,6 +5032,7 @@
4943
5032
  }
4944
5033
  var $provider = {
4945
5034
  fetch: fetch$1,
5035
+ loadData: loadData,
4946
5036
  required: $required,
4947
5037
  componentValidate: componentValidate
4948
5038
  };
@@ -5025,13 +5115,18 @@
5025
5115
  var globalConfig = {
5026
5116
  global: {}
5027
5117
  };
5028
- var data = {};
5118
+ var loadData = {};
5029
5119
  var CreateNode = CreateNodeFactory();
5030
5120
  exportAttrs(config.attrs || {});
5031
5121
  function getApi(name) {
5032
5122
  var val = instance[name];
5033
- if (Array.isArray(val)) return _toConsumableArray(val);
5034
- return val;
5123
+ if (Array.isArray(val)) {
5124
+ return val.map(function (v) {
5125
+ return v.api();
5126
+ });
5127
+ } else if (val) {
5128
+ return val.api();
5129
+ }
5035
5130
  }
5036
5131
  function directive() {
5037
5132
  var data = nameProp.apply(void 0, arguments);
@@ -5073,6 +5168,22 @@
5073
5168
  components[name] = component;
5074
5169
  if (component.formCreateParser) parser(name, component.formCreateParser);
5075
5170
  }
5171
+ function _emitData(id) {
5172
+ Object.keys(instance).forEach(function (v) {
5173
+ var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
5174
+ apis.forEach(function (that) {
5175
+ that.bus.$emit('p.loadData.' + id);
5176
+ });
5177
+ });
5178
+ }
5179
+ function setData(id, data) {
5180
+ loadData[id] = data;
5181
+ _emitData(id);
5182
+ }
5183
+ function removeData(id) {
5184
+ delete loadData[id];
5185
+ _emitData(id);
5186
+ }
5076
5187
  function $form() {
5077
5188
  return _vue.extend($FormCreate(FormCreate));
5078
5189
  }
@@ -5099,7 +5210,7 @@
5099
5210
  directives: directives,
5100
5211
  providers: providers,
5101
5212
  maker: maker,
5102
- data: data
5213
+ loadData: loadData
5103
5214
  };
5104
5215
  } else {
5105
5216
  delete _config.inherit;
@@ -5115,12 +5226,13 @@
5115
5226
  parsers: parsers,
5116
5227
  providers: providers,
5117
5228
  rules: Array.isArray(rules) ? rules : [],
5118
- name: vm.$options.propsData.name,
5229
+ name: vm.$options.propsData.name || uniqueId(),
5119
5230
  inFor: vm.$options.propsData.inFor,
5120
5231
  prop: {
5121
5232
  components: components,
5122
5233
  directives: directives
5123
5234
  },
5235
+ loadData: loadData,
5124
5236
  CreateNode: CreateNode,
5125
5237
  bus: new _vue(),
5126
5238
  unwatch: null,
@@ -5134,9 +5246,9 @@
5134
5246
  if (this.name) {
5135
5247
  if (this.inFor) {
5136
5248
  if (!instance[this.name]) instance[this.name] = [];
5137
- instance[this.name].push(this.api());
5249
+ instance[this.name].push(this);
5138
5250
  } else {
5139
- instance[this.name] = this.api();
5251
+ instance[this.name] = this;
5140
5252
  }
5141
5253
  }
5142
5254
  }
@@ -5171,8 +5283,11 @@
5171
5283
  h.reloadRule([]);
5172
5284
  if (_this2.name) {
5173
5285
  if (_this2.inFor) {
5174
- var idx = instance[_this2.name].indexOf(_this2.api());
5286
+ var idx = instance[_this2.name].indexOf(_this2);
5175
5287
  instance[_this2.name].splice(idx, 1);
5288
+ if (!instance[_this2.name].length) {
5289
+ delete instance[_this2.name];
5290
+ }
5176
5291
  } else {
5177
5292
  delete instance[_this2.name];
5178
5293
  }
@@ -5232,7 +5347,8 @@
5232
5347
  extend(formCreate, {
5233
5348
  version: config.version,
5234
5349
  ui: config.ui,
5235
- data: data,
5350
+ setData: setData,
5351
+ removeData: removeData,
5236
5352
  maker: maker,
5237
5353
  component: component,
5238
5354
  directive: directive,
@@ -5305,7 +5421,7 @@
5305
5421
  inherit.directives && extend(directives, inherit.directives);
5306
5422
  inherit.providers && extend(providers, inherit.providers);
5307
5423
  inherit.maker && extend(maker, inherit.maker);
5308
- inherit.data && extend(data, inherit.data);
5424
+ inherit.loadData && extend(loadData, inherit.loadData);
5309
5425
  }
5310
5426
  return create;
5311
5427
  }
@@ -5563,7 +5679,7 @@
5563
5679
  }
5564
5680
  },
5565
5681
  tidyOptions: function tidyOptions(options) {
5566
- ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col'].forEach(function (name) {
5682
+ ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col', 'title'].forEach(function (name) {
5567
5683
  tidyBool(options, name);
5568
5684
  });
5569
5685
  return options;
@@ -5583,7 +5699,8 @@
5583
5699
  }, {}),
5584
5700
  info: this.options.info || {},
5585
5701
  wrap: this.options.wrap || {},
5586
- col: this.options.col || {}
5702
+ col: this.options.col || {},
5703
+ title: this.options.title || {}
5587
5704
  }, ctx.prop], {
5588
5705
  info: {
5589
5706
  trigger: 'hover',
@@ -5656,7 +5773,7 @@
5656
5773
  key: "".concat(uni, "fi"),
5657
5774
  ref: ctx.wrapRef,
5658
5775
  type: 'formItem'
5659
- }]), [children, isTitle ? this.makeInfo(rule, uni) : null]);
5776
+ }]), [children, isTitle ? this.makeInfo(rule, uni, ctx) : null]);
5660
5777
  return inline === true || isFalse(_col) || isFalse(col.show) ? item : this.makeCol(rule, uni, [item]);
5661
5778
  },
5662
5779
  isTitle: function isTitle(rule) {
@@ -5664,12 +5781,17 @@
5664
5781
  var title = rule.title;
5665
5782
  return !(!title.title && !title["native"] || isFalse(title.show));
5666
5783
  },
5667
- makeInfo: function makeInfo(rule, uni) {
5784
+ makeInfo: function makeInfo(rule, uni, ctx) {
5668
5785
  var titleProp = rule.title;
5669
5786
  var infoProp = rule.info;
5670
5787
  var isTip = isTooltip(infoProp);
5671
5788
  var form = this.options.form;
5672
- var children = [(titleProp.title || '') + (form.labelSuffix || form['label-suffix'] || '')];
5789
+ var titleSlot = this.getSlot('title');
5790
+ var children = [titleSlot ? titleSlot({
5791
+ title: titleProp.title || '',
5792
+ rule: ctx.rule,
5793
+ options: this.options
5794
+ }) : (titleProp.title || '') + (form.labelSuffix || form['label-suffix'] || '')];
5673
5795
  if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5674
5796
  var prop = {
5675
5797
  type: infoProp.type || 'popover',
@@ -6036,7 +6158,7 @@
6036
6158
  function elmFormCreate() {
6037
6159
  return FormCreateFactory({
6038
6160
  ui: "".concat("element-ui"),
6039
- version: "".concat("2.5.32"),
6161
+ version: "".concat("2.5.34"),
6040
6162
  manager: manager,
6041
6163
  extendApi: extendApi,
6042
6164
  install: install,