@form-create/view-design 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/view-design v2.5.32
3
- * (c) 2018-2023 xaboy
2
+ * @form-create/view-design 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
  */
@@ -937,10 +937,7 @@
937
937
  }
938
938
  },
939
939
  render: function render(h, ctx) {
940
- var options = ctx.props.formCreateInject.options;
941
- return h("Select", helper([{}, ctx.data, {
942
- "ref": "el"
943
- }]), [(Array.isArray(options) ? options : []).map(function (props, index) {
940
+ var makeOption = function makeOption(props, index) {
944
941
  var slot = props.slot;
945
942
  return h("Option", helper([{}, {
946
943
  "props": props
@@ -949,6 +946,22 @@
949
946
  }]), [slot ? h("template", {
950
947
  "slot": props.slotName || 'default'
951
948
  }, [is.Function(slot) ? props.slot(h) : slot]) : null]);
949
+ };
950
+ var makeOptionGroup = function makeOptionGroup(props, index) {
951
+ return h("OptionGroup", {
952
+ "attrs": {
953
+ "label": props.label
954
+ },
955
+ "key": '' + index + '-' + props.label
956
+ }, [is.trueArray(props.options) && props.options.map(function (v, index) {
957
+ return makeOption(v, index);
958
+ })]);
959
+ };
960
+ var options = ctx.props.formCreateInject.options;
961
+ return h("Select", helper([{}, ctx.data, {
962
+ "ref": "el"
963
+ }]), [(Array.isArray(options) ? options : []).map(function (props, index) {
964
+ return hasProperty(props || '', 'options') ? makeOptionGroup(props, index) : makeOption(props, index);
952
965
  }), ctx.children]);
953
966
  },
954
967
  mounted: function mounted() {
@@ -1496,9 +1509,6 @@
1496
1509
  n.forEach(function (val, i) {
1497
1510
  _this2.setValue(keys[i], n[i]);
1498
1511
  });
1499
- if (o.length && !n.length) {
1500
- this.input([]);
1501
- }
1502
1512
  }
1503
1513
  }
1504
1514
  },
@@ -1540,7 +1550,7 @@
1540
1550
  return;
1541
1551
  }
1542
1552
  this.cache(key, value);
1543
- $f.coverValue(value || {});
1553
+ $f && $f.coverValue(value || {});
1544
1554
  },
1545
1555
  addRule: function addRule(i, emit) {
1546
1556
  var _this4 = this;
@@ -3572,7 +3582,8 @@
3572
3582
  vm: handle.vm,
3573
3583
  trueType: handle.getType(this.originType),
3574
3584
  vNode: handle.$render.vNode,
3575
- updated: false
3585
+ updated: false,
3586
+ cacheValue: this.rule.value
3576
3587
  });
3577
3588
  !init && this.unwatch();
3578
3589
  this.watchTo();
@@ -3815,6 +3826,7 @@
3815
3826
  ctx.root = rules;
3816
3827
  _this6.setCtx(ctx);
3817
3828
  !isCopy && !isInit && _this6.effect(ctx, 'load');
3829
+ _this6.effect(ctx, 'created');
3818
3830
  ctx.parser.loadChildren === false || loadChildren(ctx.rule.children, ctx);
3819
3831
  if (!parent) {
3820
3832
  var _preIndex = preIndex(index);
@@ -4500,6 +4512,7 @@
4500
4512
  data.mergeProp = function (prop) {
4501
4513
  return mergeRule(data.getProp(), [prop]);
4502
4514
  };
4515
+ data.id = ctx.id;
4503
4516
  }
4504
4517
  _this4.bus.$emit("p:".concat(attr, ":").concat(_type, ":").concat(p.input ? 1 : 0), event, [data, rule, _this4.api]);
4505
4518
  });
@@ -4513,9 +4526,12 @@
4513
4526
  }
4514
4527
  function getComponent(p) {
4515
4528
  var c = p.components;
4516
- if (Array.isArray(c)) return unique(c.filter(function (v) {
4517
- return v !== '*';
4518
- }));else if (is.String(c)) return [c];else return false;
4529
+ if (Array.isArray(c)) {
4530
+ var arr = unique(c.filter(function (v) {
4531
+ return v !== '*';
4532
+ }));
4533
+ return arr.length ? arr : false;
4534
+ } else if (is.String(c)) return [c];else return false;
4519
4535
  }
4520
4536
 
4521
4537
  function Handler(fc) {
@@ -4747,6 +4763,19 @@
4747
4763
  form: function form() {
4748
4764
  return this.vm.$refs[this.ref];
4749
4765
  },
4766
+ getSlot: function getSlot(name) {
4767
+ var _fn = function _fn(vm) {
4768
+ if (vm) {
4769
+ var slot = vm.$scopedSlots[name];
4770
+ if (slot) {
4771
+ return slot;
4772
+ }
4773
+ return _fn(vm.$pfc);
4774
+ }
4775
+ return undefined;
4776
+ };
4777
+ return _fn(this.vm);
4778
+ },
4750
4779
  mergeOptions: function mergeOptions(args, opt) {
4751
4780
  var _this2 = this;
4752
4781
  return mergeProps(args.map(function (v) {
@@ -4768,6 +4797,52 @@
4768
4797
  render: function render(children) {}
4769
4798
  });
4770
4799
 
4800
+ var loadData = function loadData(fc) {
4801
+ var loadData = {
4802
+ name: 'loadData',
4803
+ _fn: [],
4804
+ created: function created(inject, rule, api) {
4805
+ this.deleted(inject);
4806
+ var attrs = toArray(inject.getValue());
4807
+ var events = [];
4808
+ attrs.forEach(function (attr) {
4809
+ if (attr) {
4810
+ var on = function on() {
4811
+ if (attr.watch !== false) {
4812
+ fc.bus.$off('p.loadData.' + attr.attr, on);
4813
+ fc.bus.$once('p.loadData.' + attr.attr, on);
4814
+ }
4815
+ var value = undefined;
4816
+ if (attr.attr) {
4817
+ value = fc.loadData[attr.attr] || attr["default"];
4818
+ if (attr.copy) {
4819
+ value = deepCopy(value);
4820
+ }
4821
+ }
4822
+ deepSet(inject.getProp(), attr.to || 'options', value);
4823
+ api.sync(rule);
4824
+ };
4825
+ events.push(function () {
4826
+ return fc.bus.$off('p.loadData.' + attr.attr, on);
4827
+ });
4828
+ on();
4829
+ }
4830
+ });
4831
+ this._fn[inject.id] = events;
4832
+ },
4833
+ deleted: function deleted(inject) {
4834
+ if (this._fn[inject.id]) {
4835
+ this._fn[inject.id].forEach(function (un) {
4836
+ un();
4837
+ });
4838
+ delete this._fn[inject.id];
4839
+ }
4840
+ inject.clearProp();
4841
+ }
4842
+ };
4843
+ loadData.watch = loadData.created;
4844
+ return loadData;
4845
+ };
4771
4846
  var componentValidate = {
4772
4847
  name: 'componentValidate',
4773
4848
  load: function load(attr, rule, api) {
@@ -4809,12 +4884,21 @@
4809
4884
  }
4810
4885
  function run(inject, rule, api) {
4811
4886
  var option = inject.value;
4887
+ var set = function set(val) {
4888
+ if (val === undefined) {
4889
+ inject.clearProp();
4890
+ api.sync(rule);
4891
+ } else {
4892
+ deepSet(inject.getProp(), option.to || 'options', val);
4893
+ }
4894
+ };
4812
4895
  if (is.Function(option)) {
4813
4896
  option = option(rule, api);
4814
4897
  }
4815
4898
  option = parseOpt(option);
4816
4899
  if (!option || !option.action) {
4817
- return false;
4900
+ set(undefined);
4901
+ return;
4818
4902
  }
4819
4903
  if (!option.to) {
4820
4904
  option.to = 'options';
@@ -4827,61 +4911,66 @@
4827
4911
  return true;
4828
4912
  }
4829
4913
  };
4830
- var set = function set(val) {
4831
- if (val === undefined) {
4832
- inject.clearProp();
4914
+ var config = _objectSpread2(_objectSpread2({
4915
+ headers: {}
4916
+ }, option), {}, {
4917
+ onSuccess: function onSuccess(body, flag) {
4918
+ if (check()) return;
4919
+ var fn = function fn(v) {
4920
+ return flag ? v : v.data;
4921
+ };
4922
+ if (is.Function(option.parse)) {
4923
+ fn = option.parse;
4924
+ } else if (option.parse && is.String(option.parse)) {
4925
+ fn = function fn(v) {
4926
+ option.parse.split('.').forEach(function (k) {
4927
+ if (v) {
4928
+ v = v[k];
4929
+ }
4930
+ });
4931
+ return v;
4932
+ };
4933
+ }
4934
+ set(fn(body, rule, api));
4833
4935
  api.sync(rule);
4834
- } else {
4835
- deepSet(inject.getProp(), option.to, val);
4936
+ },
4937
+ onError: function onError(e) {
4938
+ set(undefined);
4939
+ if (check()) return;
4940
+ (_onError || function (e) {
4941
+ return err(e.message || 'fetch fail ' + option.action);
4942
+ })(e, rule, api);
4836
4943
  }
4837
- };
4944
+ });
4945
+ fc.options.beforeFetch && invoke(function () {
4946
+ return fc.options.beforeFetch(config, {
4947
+ rule: rule,
4948
+ api: api
4949
+ });
4950
+ });
4951
+ if (is.Function(option.action)) {
4952
+ option.action(rule, api).then(function (val) {
4953
+ config.onSuccess(val, true);
4954
+ })["catch"](function (e) {
4955
+ config.onError(e);
4956
+ });
4957
+ return;
4958
+ }
4838
4959
  invoke(function () {
4839
- return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4840
- onSuccess: function onSuccess(body) {
4841
- if (check()) return;
4842
- var fn = function fn(v) {
4843
- return v.data;
4844
- };
4845
- if (is.Function(option.parse)) {
4846
- fn = option.parse;
4847
- } else if (option.parse && is.String(option.parse)) {
4848
- fn = function fn(v) {
4849
- option.parse.split('.').forEach(function (k) {
4850
- if (v) {
4851
- v = v[k];
4852
- }
4853
- });
4854
- return v;
4855
- };
4856
- }
4857
- set(fn(body, rule, api));
4858
- api.sync(rule);
4859
- },
4860
- onError: function onError(e) {
4861
- set(undefined);
4862
- if (check()) return;
4863
- (_onError || function (e) {
4864
- return err(e.message || 'fetch fail ' + option.action);
4865
- })(e, rule, api);
4866
- }
4867
- }), {
4960
+ return fc.create.fetch(config, {
4868
4961
  inject: inject,
4869
4962
  rule: rule,
4870
4963
  api: api
4871
4964
  });
4872
4965
  });
4873
- return true;
4874
4966
  }
4875
4967
  return {
4876
4968
  name: 'fetch',
4877
4969
  loaded: function loaded() {
4878
4970
  run.apply(void 0, arguments);
4879
4971
  },
4880
- watch: function watch(inject, rule, api) {
4881
- if (!run(inject, rule, api)) {
4882
- inject.clearProp();
4883
- api.sync(rule);
4884
- }
4972
+ watch: function watch() {
4973
+ run.apply(void 0, arguments);
4885
4974
  }
4886
4975
  };
4887
4976
  };
@@ -4935,6 +5024,7 @@
4935
5024
  }
4936
5025
  var $provider = {
4937
5026
  fetch: fetch$1,
5027
+ loadData: loadData,
4938
5028
  required: $required,
4939
5029
  componentValidate: componentValidate
4940
5030
  };
@@ -5017,13 +5107,18 @@
5017
5107
  var globalConfig = {
5018
5108
  global: {}
5019
5109
  };
5020
- var data = {};
5110
+ var loadData = {};
5021
5111
  var CreateNode = CreateNodeFactory();
5022
5112
  exportAttrs(config.attrs || {});
5023
5113
  function getApi(name) {
5024
5114
  var val = instance[name];
5025
- if (Array.isArray(val)) return _toConsumableArray(val);
5026
- return val;
5115
+ if (Array.isArray(val)) {
5116
+ return val.map(function (v) {
5117
+ return v.api();
5118
+ });
5119
+ } else if (val) {
5120
+ return val.api();
5121
+ }
5027
5122
  }
5028
5123
  function directive() {
5029
5124
  var data = nameProp.apply(void 0, arguments);
@@ -5065,6 +5160,22 @@
5065
5160
  components[name] = component;
5066
5161
  if (component.formCreateParser) parser(name, component.formCreateParser);
5067
5162
  }
5163
+ function _emitData(id) {
5164
+ Object.keys(instance).forEach(function (v) {
5165
+ var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
5166
+ apis.forEach(function (that) {
5167
+ that.bus.$emit('p.loadData.' + id);
5168
+ });
5169
+ });
5170
+ }
5171
+ function setData(id, data) {
5172
+ loadData[id] = data;
5173
+ _emitData(id);
5174
+ }
5175
+ function removeData(id) {
5176
+ delete loadData[id];
5177
+ _emitData(id);
5178
+ }
5068
5179
  function $form() {
5069
5180
  return _vue.extend($FormCreate(FormCreate));
5070
5181
  }
@@ -5091,7 +5202,7 @@
5091
5202
  directives: directives,
5092
5203
  providers: providers,
5093
5204
  maker: maker,
5094
- data: data
5205
+ loadData: loadData
5095
5206
  };
5096
5207
  } else {
5097
5208
  delete _config.inherit;
@@ -5107,12 +5218,13 @@
5107
5218
  parsers: parsers,
5108
5219
  providers: providers,
5109
5220
  rules: Array.isArray(rules) ? rules : [],
5110
- name: vm.$options.propsData.name,
5221
+ name: vm.$options.propsData.name || uniqueId(),
5111
5222
  inFor: vm.$options.propsData.inFor,
5112
5223
  prop: {
5113
5224
  components: components,
5114
5225
  directives: directives
5115
5226
  },
5227
+ loadData: loadData,
5116
5228
  CreateNode: CreateNode,
5117
5229
  bus: new _vue(),
5118
5230
  unwatch: null,
@@ -5126,9 +5238,9 @@
5126
5238
  if (this.name) {
5127
5239
  if (this.inFor) {
5128
5240
  if (!instance[this.name]) instance[this.name] = [];
5129
- instance[this.name].push(this.api());
5241
+ instance[this.name].push(this);
5130
5242
  } else {
5131
- instance[this.name] = this.api();
5243
+ instance[this.name] = this;
5132
5244
  }
5133
5245
  }
5134
5246
  }
@@ -5163,8 +5275,11 @@
5163
5275
  h.reloadRule([]);
5164
5276
  if (_this2.name) {
5165
5277
  if (_this2.inFor) {
5166
- var idx = instance[_this2.name].indexOf(_this2.api());
5278
+ var idx = instance[_this2.name].indexOf(_this2);
5167
5279
  instance[_this2.name].splice(idx, 1);
5280
+ if (!instance[_this2.name].length) {
5281
+ delete instance[_this2.name];
5282
+ }
5168
5283
  } else {
5169
5284
  delete instance[_this2.name];
5170
5285
  }
@@ -5224,7 +5339,8 @@
5224
5339
  extend(formCreate, {
5225
5340
  version: config.version,
5226
5341
  ui: config.ui,
5227
- data: data,
5342
+ setData: setData,
5343
+ removeData: removeData,
5228
5344
  maker: maker,
5229
5345
  component: component,
5230
5346
  directive: directive,
@@ -5297,7 +5413,7 @@
5297
5413
  inherit.directives && extend(directives, inherit.directives);
5298
5414
  inherit.providers && extend(providers, inherit.providers);
5299
5415
  inherit.maker && extend(maker, inherit.maker);
5300
- inherit.data && extend(data, inherit.data);
5416
+ inherit.loadData && extend(loadData, inherit.loadData);
5301
5417
  }
5302
5418
  return create;
5303
5419
  }
@@ -5584,7 +5700,7 @@
5584
5700
  }
5585
5701
  },
5586
5702
  tidyOptions: function tidyOptions(options) {
5587
- ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col'].forEach(function (name) {
5703
+ ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col', 'title'].forEach(function (name) {
5588
5704
  tidyBool(options, name);
5589
5705
  });
5590
5706
  return options;
@@ -5599,7 +5715,8 @@
5599
5715
  ctx.prop = mergeProps([{
5600
5716
  info: this.options.info || {},
5601
5717
  wrap: this.options.wrap || {},
5602
- col: this.options.col || {}
5718
+ col: this.options.col || {},
5719
+ title: this.options.title || {}
5603
5720
  }, ctx.prop], {
5604
5721
  info: info(),
5605
5722
  title: {},
@@ -5673,7 +5790,7 @@
5673
5790
  key: "".concat(uni, "fi"),
5674
5791
  ref: ctx.wrapRef,
5675
5792
  type: 'formItem'
5676
- }]), [children, isTitle ? this.makeInfo(rule, uni) : null]);
5793
+ }]), [children, isTitle ? this.makeInfo(rule, uni, ctx) : null]);
5677
5794
  return inline === true || isFalse(_col) || isFalse(col.show) ? item : this.makeCol(rule, uni, [item]);
5678
5795
  },
5679
5796
  isTitle: function isTitle(rule) {
@@ -5681,10 +5798,15 @@
5681
5798
  var title = rule.title;
5682
5799
  return !(!title.title && !title["native"] || isFalse(title.show));
5683
5800
  },
5684
- makeInfo: function makeInfo(rule, uni) {
5801
+ makeInfo: function makeInfo(rule, uni, ctx) {
5685
5802
  var titleProp = rule.title;
5686
5803
  var infoProp = rule.info;
5687
- var children = [titleProp.title];
5804
+ var titleSlot = this.getSlot('title');
5805
+ var children = [titleSlot ? titleSlot({
5806
+ title: titleProp.title || '',
5807
+ rule: ctx.rule,
5808
+ options: this.options
5809
+ }) : titleProp.title];
5688
5810
  if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5689
5811
  var prop = {
5690
5812
  type: infoProp.type || 'poptip',
@@ -5757,7 +5879,7 @@
5757
5879
  }, [item]);
5758
5880
  },
5759
5881
  makeResetBtn: function makeResetBtn() {
5760
- var _this2 = this;
5882
+ var _this = this;
5761
5883
  var resetBtn = this.options.resetBtn;
5762
5884
  this.setSize(resetBtn);
5763
5885
  return this.$r({
@@ -5769,7 +5891,7 @@
5769
5891
  },
5770
5892
  on: {
5771
5893
  click: function click() {
5772
- var fApi = _this2.$handle.api;
5894
+ var fApi = _this.$handle.api;
5773
5895
  resetBtn.click ? resetBtn.click(fApi) : fApi.resetFields();
5774
5896
  }
5775
5897
  },
@@ -5777,7 +5899,7 @@
5777
5899
  }, [resetBtn.innerText]);
5778
5900
  },
5779
5901
  makeSubmitBtn: function makeSubmitBtn() {
5780
- var _this3 = this;
5902
+ var _this2 = this;
5781
5903
  var submitBtn = this.options.submitBtn;
5782
5904
  this.setSize(submitBtn);
5783
5905
  return this.$r({
@@ -5788,7 +5910,7 @@
5788
5910
  },
5789
5911
  on: {
5790
5912
  click: function click() {
5791
- var fApi = _this3.$handle.api;
5913
+ var fApi = _this2.$handle.api;
5792
5914
  submitBtn.click ? submitBtn.click(fApi) : fApi.submit();
5793
5915
  }
5794
5916
  },
@@ -6071,7 +6193,7 @@
6071
6193
  function ivuFormCreate() {
6072
6194
  return FormCreateFactory({
6073
6195
  ui: "".concat("view-design"),
6074
- version: "".concat("2.5.32"),
6196
+ version: "".concat("2.5.34"),
6075
6197
  manager: manager,
6076
6198
  install: install,
6077
6199
  extendApi: extendApi,