@form-create/element-ui 2.5.32 → 2.5.33

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.32
2
+ * @form-create/element-ui v2.5.33
3
3
  * (c) 2018-2023 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -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) {
@@ -4776,6 +4792,52 @@
4776
4792
  render: function render(children) {}
4777
4793
  });
4778
4794
 
4795
+ var loadData = function loadData(fc) {
4796
+ var loadData = {
4797
+ name: 'loadData',
4798
+ _fn: [],
4799
+ created: function created(inject, rule, api) {
4800
+ this.deleted(inject);
4801
+ var attrs = toArray(inject.getValue());
4802
+ var events = [];
4803
+ attrs.forEach(function (attr) {
4804
+ if (attr) {
4805
+ var on = function on() {
4806
+ if (attr.watch !== false) {
4807
+ fc.bus.$off('p.loadData.' + attr.attr, on);
4808
+ fc.bus.$once('p.loadData.' + attr.attr, on);
4809
+ }
4810
+ var value = undefined;
4811
+ if (attr.attr) {
4812
+ value = fc.loadData[attr.attr] || attr["default"];
4813
+ if (attr.copy) {
4814
+ value = deepCopy(value);
4815
+ }
4816
+ }
4817
+ deepSet(inject.getProp(), attr.to || 'options', value);
4818
+ api.sync(rule);
4819
+ };
4820
+ events.push(function () {
4821
+ return fc.bus.$off('p.loadData.' + attr.attr, on);
4822
+ });
4823
+ on();
4824
+ }
4825
+ });
4826
+ this._fn[inject.id] = events;
4827
+ },
4828
+ deleted: function deleted(inject) {
4829
+ if (this._fn[inject.id]) {
4830
+ this._fn[inject.id].forEach(function (un) {
4831
+ un();
4832
+ });
4833
+ delete this._fn[inject.id];
4834
+ }
4835
+ inject.clearProp();
4836
+ }
4837
+ };
4838
+ loadData.watch = loadData.created;
4839
+ return loadData;
4840
+ };
4779
4841
  var componentValidate = {
4780
4842
  name: 'componentValidate',
4781
4843
  load: function load(attr, rule, api) {
@@ -4817,12 +4879,21 @@
4817
4879
  }
4818
4880
  function run(inject, rule, api) {
4819
4881
  var option = inject.value;
4882
+ var set = function set(val) {
4883
+ if (val === undefined) {
4884
+ inject.clearProp();
4885
+ api.sync(rule);
4886
+ } else {
4887
+ deepSet(inject.getProp(), option.to || 'options', val);
4888
+ }
4889
+ };
4820
4890
  if (is.Function(option)) {
4821
4891
  option = option(rule, api);
4822
4892
  }
4823
4893
  option = parseOpt(option);
4824
4894
  if (!option || !option.action) {
4825
- return false;
4895
+ set(undefined);
4896
+ return;
4826
4897
  }
4827
4898
  if (!option.to) {
4828
4899
  option.to = 'options';
@@ -4835,61 +4906,66 @@
4835
4906
  return true;
4836
4907
  }
4837
4908
  };
4838
- var set = function set(val) {
4839
- if (val === undefined) {
4840
- inject.clearProp();
4909
+ var config = _objectSpread2(_objectSpread2({
4910
+ headers: {}
4911
+ }, option), {}, {
4912
+ onSuccess: function onSuccess(body, flag) {
4913
+ if (check()) return;
4914
+ var fn = function fn(v) {
4915
+ return flag ? v : v.data;
4916
+ };
4917
+ if (is.Function(option.parse)) {
4918
+ fn = option.parse;
4919
+ } else if (option.parse && is.String(option.parse)) {
4920
+ fn = function fn(v) {
4921
+ option.parse.split('.').forEach(function (k) {
4922
+ if (v) {
4923
+ v = v[k];
4924
+ }
4925
+ });
4926
+ return v;
4927
+ };
4928
+ }
4929
+ set(fn(body, rule, api));
4841
4930
  api.sync(rule);
4842
- } else {
4843
- deepSet(inject.getProp(), option.to, val);
4931
+ },
4932
+ onError: function onError(e) {
4933
+ set(undefined);
4934
+ if (check()) return;
4935
+ (_onError || function (e) {
4936
+ return err(e.message || 'fetch fail ' + option.action);
4937
+ })(e, rule, api);
4844
4938
  }
4845
- };
4939
+ });
4940
+ fc.options.beforeFetch && invoke(function () {
4941
+ return fc.options.beforeFetch(config, {
4942
+ rule: rule,
4943
+ api: api
4944
+ });
4945
+ });
4946
+ if (is.Function(option.action)) {
4947
+ option.action(rule, api).then(function (val) {
4948
+ config.onSuccess(val, true);
4949
+ })["catch"](function (e) {
4950
+ config.onError(e);
4951
+ });
4952
+ return;
4953
+ }
4846
4954
  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
- }), {
4955
+ return fc.create.fetch(config, {
4876
4956
  inject: inject,
4877
4957
  rule: rule,
4878
4958
  api: api
4879
4959
  });
4880
4960
  });
4881
- return true;
4882
4961
  }
4883
4962
  return {
4884
4963
  name: 'fetch',
4885
4964
  loaded: function loaded() {
4886
4965
  run.apply(void 0, arguments);
4887
4966
  },
4888
- watch: function watch(inject, rule, api) {
4889
- if (!run(inject, rule, api)) {
4890
- inject.clearProp();
4891
- api.sync(rule);
4892
- }
4967
+ watch: function watch() {
4968
+ run.apply(void 0, arguments);
4893
4969
  }
4894
4970
  };
4895
4971
  };
@@ -4943,6 +5019,7 @@
4943
5019
  }
4944
5020
  var $provider = {
4945
5021
  fetch: fetch$1,
5022
+ loadData: loadData,
4946
5023
  required: $required,
4947
5024
  componentValidate: componentValidate
4948
5025
  };
@@ -5025,13 +5102,18 @@
5025
5102
  var globalConfig = {
5026
5103
  global: {}
5027
5104
  };
5028
- var data = {};
5105
+ var loadData = {};
5029
5106
  var CreateNode = CreateNodeFactory();
5030
5107
  exportAttrs(config.attrs || {});
5031
5108
  function getApi(name) {
5032
5109
  var val = instance[name];
5033
- if (Array.isArray(val)) return _toConsumableArray(val);
5034
- return val;
5110
+ if (Array.isArray(val)) {
5111
+ return val.map(function (v) {
5112
+ return v.api();
5113
+ });
5114
+ } else if (val) {
5115
+ return val.api();
5116
+ }
5035
5117
  }
5036
5118
  function directive() {
5037
5119
  var data = nameProp.apply(void 0, arguments);
@@ -5073,6 +5155,22 @@
5073
5155
  components[name] = component;
5074
5156
  if (component.formCreateParser) parser(name, component.formCreateParser);
5075
5157
  }
5158
+ function _emitData(id) {
5159
+ Object.keys(instance).forEach(function (v) {
5160
+ var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
5161
+ apis.forEach(function (that) {
5162
+ that.bus.$emit('p.loadData.' + id);
5163
+ });
5164
+ });
5165
+ }
5166
+ function setData(id, data) {
5167
+ loadData[id] = data;
5168
+ _emitData(id);
5169
+ }
5170
+ function removeData(id) {
5171
+ delete loadData[id];
5172
+ _emitData(id);
5173
+ }
5076
5174
  function $form() {
5077
5175
  return _vue.extend($FormCreate(FormCreate));
5078
5176
  }
@@ -5099,7 +5197,7 @@
5099
5197
  directives: directives,
5100
5198
  providers: providers,
5101
5199
  maker: maker,
5102
- data: data
5200
+ loadData: loadData
5103
5201
  };
5104
5202
  } else {
5105
5203
  delete _config.inherit;
@@ -5115,12 +5213,13 @@
5115
5213
  parsers: parsers,
5116
5214
  providers: providers,
5117
5215
  rules: Array.isArray(rules) ? rules : [],
5118
- name: vm.$options.propsData.name,
5216
+ name: vm.$options.propsData.name || uniqueId(),
5119
5217
  inFor: vm.$options.propsData.inFor,
5120
5218
  prop: {
5121
5219
  components: components,
5122
5220
  directives: directives
5123
5221
  },
5222
+ loadData: loadData,
5124
5223
  CreateNode: CreateNode,
5125
5224
  bus: new _vue(),
5126
5225
  unwatch: null,
@@ -5134,9 +5233,9 @@
5134
5233
  if (this.name) {
5135
5234
  if (this.inFor) {
5136
5235
  if (!instance[this.name]) instance[this.name] = [];
5137
- instance[this.name].push(this.api());
5236
+ instance[this.name].push(this);
5138
5237
  } else {
5139
- instance[this.name] = this.api();
5238
+ instance[this.name] = this;
5140
5239
  }
5141
5240
  }
5142
5241
  }
@@ -5171,8 +5270,11 @@
5171
5270
  h.reloadRule([]);
5172
5271
  if (_this2.name) {
5173
5272
  if (_this2.inFor) {
5174
- var idx = instance[_this2.name].indexOf(_this2.api());
5273
+ var idx = instance[_this2.name].indexOf(_this2);
5175
5274
  instance[_this2.name].splice(idx, 1);
5275
+ if (!instance[_this2.name].length) {
5276
+ delete instance[_this2.name];
5277
+ }
5176
5278
  } else {
5177
5279
  delete instance[_this2.name];
5178
5280
  }
@@ -5232,7 +5334,8 @@
5232
5334
  extend(formCreate, {
5233
5335
  version: config.version,
5234
5336
  ui: config.ui,
5235
- data: data,
5337
+ setData: setData,
5338
+ removeData: removeData,
5236
5339
  maker: maker,
5237
5340
  component: component,
5238
5341
  directive: directive,
@@ -5305,7 +5408,7 @@
5305
5408
  inherit.directives && extend(directives, inherit.directives);
5306
5409
  inherit.providers && extend(providers, inherit.providers);
5307
5410
  inherit.maker && extend(maker, inherit.maker);
5308
- inherit.data && extend(data, inherit.data);
5411
+ inherit.loadData && extend(loadData, inherit.loadData);
5309
5412
  }
5310
5413
  return create;
5311
5414
  }
@@ -6036,7 +6139,7 @@
6036
6139
  function elmFormCreate() {
6037
6140
  return FormCreateFactory({
6038
6141
  ui: "".concat("element-ui"),
6039
- version: "".concat("2.5.32"),
6142
+ version: "".concat("2.5.33"),
6040
6143
  manager: manager,
6041
6144
  extendApi: extendApi,
6042
6145
  install: install,