@form-create/element-ui 2.5.12 → 2.5.16

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.12
2
+ * @form-create/element-ui v2.5.16
3
3
  * (c) 2018-2021 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -268,6 +268,12 @@
268
268
  type: String
269
269
  },
270
270
  watch: {
271
+ 'formCreateInject.options': {
272
+ handler: function handler() {
273
+ this.update();
274
+ },
275
+ deep: true
276
+ },
271
277
  value: function value() {
272
278
  this.update();
273
279
  }
@@ -277,15 +283,13 @@
277
283
  trueValue: []
278
284
  };
279
285
  },
280
- computed: {
286
+ methods: {
281
287
  options: function options() {
282
288
  var opt = this.formCreateInject.options;
283
289
  return Array.isArray(opt) ? opt : [];
284
- }
285
- },
286
- methods: {
290
+ },
287
291
  onInput: function onInput(n) {
288
- this.$emit('input', this.options.filter(function (opt) {
292
+ this.$emit('input', this.options().filter(function (opt) {
289
293
  return n.indexOf(opt.label) !== -1;
290
294
  }).map(function (opt) {
291
295
  return opt.value;
@@ -296,7 +300,7 @@
296
300
  update: function update() {
297
301
  var _this = this;
298
302
 
299
- this.trueValue = this.value ? this.options.filter(function (opt) {
303
+ this.trueValue = this.value ? this.options().filter(function (opt) {
300
304
  return _this.value.indexOf(opt.value) !== -1;
301
305
  }).map(function (option) {
302
306
  return option.label;
@@ -317,7 +321,7 @@
317
321
  "on": {
318
322
  "input": this.onInput
319
323
  }
320
- }]), [this.options.map(function (opt, index) {
324
+ }]), [this.options().map(function (opt, index) {
321
325
  var props = _objectSpread2({}, opt);
322
326
 
323
327
  var Type = _this2.type === 'button' ? 'ElCheckboxButton' : 'ElCheckbox';
@@ -861,6 +865,12 @@
861
865
  type: String
862
866
  },
863
867
  watch: {
868
+ 'formCreateInject.options': {
869
+ handler: function handler() {
870
+ this.update();
871
+ },
872
+ deep: true
873
+ },
864
874
  value: function value() {
865
875
  this.update();
866
876
  }
@@ -870,15 +880,13 @@
870
880
  trueValue: []
871
881
  };
872
882
  },
873
- computed: {
883
+ methods: {
874
884
  options: function options() {
875
885
  var opt = this.formCreateInject.options;
876
886
  return Array.isArray(opt) ? opt : [];
877
- }
878
- },
879
- methods: {
887
+ },
880
888
  onInput: function onInput(n) {
881
- this.$emit('input', this.options.filter(function (opt) {
889
+ this.$emit('input', this.options().filter(function (opt) {
882
890
  return opt.label === n;
883
891
  }).reduce(function (initial, opt) {
884
892
  return opt.value;
@@ -887,7 +895,7 @@
887
895
  update: function update() {
888
896
  var _this = this;
889
897
 
890
- this.trueValue = this.options.filter(function (opt) {
898
+ this.trueValue = this.options().filter(function (opt) {
891
899
  return opt.value === _this.value;
892
900
  }).reduce(function (initial, opt) {
893
901
  return opt.label;
@@ -908,7 +916,7 @@
908
916
  "on": {
909
917
  "input": this.onInput
910
918
  }
911
- }]), [this.options.map(function (opt, index) {
919
+ }]), [this.options().map(function (opt, index) {
912
920
  var props = _objectSpread2({}, opt);
913
921
 
914
922
  var Type = _this2.type === 'button' ? 'ElRadioButton' : 'ElRadio';
@@ -1105,7 +1113,8 @@
1105
1113
  return {
1106
1114
  uploadList: [],
1107
1115
  previewVisible: false,
1108
- previewImage: ''
1116
+ previewImage: '',
1117
+ cacheFiles: []
1109
1118
  };
1110
1119
  },
1111
1120
  created: function created() {
@@ -1256,7 +1265,11 @@
1256
1265
  }).filter(function (url) {
1257
1266
  return url !== undefined;
1258
1267
  });
1259
- this.$emit('input', this.limit === 1 ? files[0] || '' : files);
1268
+
1269
+ if (this.cacheFiles.length !== files.length) {
1270
+ this.cacheFiles = _toConsumableArray(files);
1271
+ this.$emit('input', this.limit === 1 ? files[0] || '' : files);
1272
+ }
1260
1273
  },
1261
1274
  handleCancel: function handleCancel() {
1262
1275
  this.previewVisible = false;
@@ -1921,6 +1934,7 @@
1921
1934
  Object.keys(this.formCreate.prop).forEach(function (k) {
1922
1935
  extend(_this2.$options[k], _this2.formCreate.prop[k]);
1923
1936
  });
1937
+ this.$emit('beforeCreate', this.formCreate.api());
1924
1938
  }
1925
1939
  };
1926
1940
  }
@@ -2001,6 +2015,20 @@
2001
2015
  return [].concat(keyAttrs, _toConsumableArray(normalMerge$1), _toConsumableArray(toArrayMerge$1), _toConsumableArray(functionalMerge$1), arrayAttrs, normalAttrs);
2002
2016
  }
2003
2017
 
2018
+ function format(type, msg, rule) {
2019
+ return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2020
+ }
2021
+ function tip(msg, rule) {
2022
+ console.warn(format('tip', msg, rule));
2023
+ }
2024
+ function err(msg, rule) {
2025
+ console.error(format('err', msg, rule));
2026
+ }
2027
+ function logError(e) {
2028
+ err(e.toString());
2029
+ console.error(e);
2030
+ }
2031
+
2004
2032
  function deepExtend(origin) {
2005
2033
  var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2006
2034
  var mode = arguments.length > 2 ? arguments[2] : undefined;
@@ -2029,14 +2057,18 @@
2029
2057
  }
2030
2058
 
2031
2059
  origin[key] = deepExtend(origin[key], clone, mode);
2032
- } else if (is.Undef(clone)) {
2033
- $set(origin, key, clone);
2034
- } else if (clone.__json !== undefined) {
2035
- $set(origin, key, clone.__json);
2036
- } else if (clone.__origin !== undefined) {
2037
- $set(origin, key, clone.__origin);
2038
2060
  } else {
2039
2061
  $set(origin, key, clone);
2062
+
2063
+ if (!is.Undef(clone)) {
2064
+ if (clone.__json !== undefined) {
2065
+ origin[key].__json = clone.__json;
2066
+ }
2067
+
2068
+ if (clone.__origin !== undefined) {
2069
+ origin[key].__origin = clone.__origin;
2070
+ }
2071
+ }
2040
2072
  }
2041
2073
  }
2042
2074
  }
@@ -2051,20 +2083,6 @@
2051
2083
  }).value;
2052
2084
  }
2053
2085
 
2054
- function format(type, msg, rule) {
2055
- return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2056
- }
2057
- function tip(msg, rule) {
2058
- console.warn(format('tip', msg, rule));
2059
- }
2060
- function err(msg, rule) {
2061
- console.error(format('err', msg, rule));
2062
- }
2063
- function logError(e) {
2064
- err(e.toString());
2065
- console.error(e);
2066
- }
2067
-
2068
2086
  var PREFIX = '[[FORM-CREATE-PREFIX-';
2069
2087
  var SUFFIX = '-FORM-CREATE-SUFFIX]]';
2070
2088
  var $T = '$FN:';
@@ -2141,8 +2159,8 @@
2141
2159
  };
2142
2160
  } //todo 优化位置
2143
2161
 
2144
- function copyRule(rule, mode) {
2145
- return copyRules([rule], mode || false)[0];
2162
+ function copyRule(rule) {
2163
+ return copyRules([rule])[0];
2146
2164
  }
2147
2165
  function copyRules(rules, mode) {
2148
2166
  return deepExtend([], _toConsumableArray(rules), mode || false);
@@ -2333,11 +2351,6 @@
2333
2351
  }
2334
2352
 
2335
2353
  var api = {
2336
- helper: {
2337
- tidyFields: tidyFields,
2338
- props: props
2339
- },
2340
-
2341
2354
  get config() {
2342
2355
  return h.options;
2343
2356
  },
@@ -2481,6 +2494,12 @@
2481
2494
  });
2482
2495
  h.refresh();
2483
2496
  },
2497
+ all: function all(origin) {
2498
+ return Object.keys(h.ctxs).map(function (k) {
2499
+ var ctx = h.ctxs[k];
2500
+ return origin ? ctx.origin : ctx.rule;
2501
+ });
2502
+ },
2484
2503
  model: function model(origin) {
2485
2504
  return h.fields().reduce(function (initial, key) {
2486
2505
  var ctx = h.fieldCtx[key][0];
@@ -2668,13 +2687,26 @@
2668
2687
  nextRefresh: function nextRefresh(fn) {
2669
2688
  h.nextRefresh();
2670
2689
  fn && invoke(fn);
2690
+ },
2691
+ emit: function emit(name) {
2692
+ var _h$vm;
2693
+
2694
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2695
+ args[_key3 - 1] = arguments[_key3];
2696
+ }
2697
+
2698
+ (_h$vm = h.vm).$emit.apply(_h$vm, [name].concat(args));
2699
+ },
2700
+ helper: {
2701
+ tidyFields: tidyFields,
2702
+ props: props
2671
2703
  }
2672
2704
  };
2673
2705
  ['on', 'once', 'off', 'set'].forEach(function (n) {
2674
2706
  api[n] = function () {
2675
- var _h$vm;
2707
+ var _h$vm2;
2676
2708
 
2677
- (_h$vm = h.vm)["$".concat(n)].apply(_h$vm, arguments);
2709
+ (_h$vm2 = h.vm)["$".concat(n)].apply(_h$vm2, arguments);
2678
2710
  };
2679
2711
  });
2680
2712
  api.changeValue = api.changeField = api.setValue;
@@ -2899,6 +2931,7 @@
2899
2931
  renderCtx: function renderCtx(ctx, parent) {
2900
2932
  if (ctx.type === 'hidden') return;
2901
2933
  var rule = ctx.rule;
2934
+ var preview = this.options.preview || false;
2902
2935
 
2903
2936
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2904
2937
  var vn;
@@ -2949,12 +2982,13 @@
2949
2982
  vn = this.vm.$scopedSlots[slot]({
2950
2983
  rule: rule,
2951
2984
  prop: prop,
2985
+ preview: preview,
2952
2986
  children: children,
2953
2987
  api: this.$handle.api,
2954
2988
  model: prop.model || {}
2955
2989
  });
2956
2990
  } else {
2957
- vn = ctx.parser.render(children, ctx);
2991
+ vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
2958
2992
  }
2959
2993
  }
2960
2994
 
@@ -3019,20 +3053,26 @@
3019
3053
  var _this7 = this;
3020
3054
 
3021
3055
  if (!this.vm.ctxInject[ctx.id]) {
3022
- $set(this.vm.ctxInject, ctx.id, {});
3056
+ $set(this.vm.ctxInject, ctx.id, {
3057
+ api: this.$handle.api,
3058
+ form: this.fc.create,
3059
+ subForm: function subForm(_subForm) {
3060
+ _this7.$handle.addSubForm(ctx, _subForm);
3061
+ },
3062
+ options: [],
3063
+ children: [],
3064
+ prop: {},
3065
+ preview: false,
3066
+ field: ctx.field,
3067
+ rule: ctx.rule
3068
+ });
3023
3069
  }
3024
3070
 
3025
3071
  var inject = this.vm.ctxInject[ctx.id];
3026
3072
  extend(inject, {
3027
- api: this.$handle.api,
3028
- form: this.fc.create,
3029
- subForm: function subForm(_subForm) {
3030
- _this7.$handle.addSubForm(ctx, _subForm);
3031
- },
3032
- field: ctx.field,
3073
+ preview: this.options.preview || false,
3033
3074
  options: ctx.prop.options,
3034
3075
  children: ctx.rule.children,
3035
- rule: ctx.rule,
3036
3076
  prop: function () {
3037
3077
  var temp = _objectSpread2({}, ctx.prop);
3038
3078
 
@@ -3942,6 +3982,7 @@
3942
3982
  this.refresh();
3943
3983
  this.bus.$off('next-tick', this.nextReload);
3944
3984
  this.bus.$once('next-tick', this.nextReload);
3985
+ this.vm.$emit('update', this.api);
3945
3986
  },
3946
3987
  //todo 组件生成全部通过 alias
3947
3988
  refresh: function refresh() {
@@ -3977,7 +4018,7 @@
3977
4018
  function useInput(Handler) {
3978
4019
  extend(Handler.prototype, {
3979
4020
  getValue: function getValue(ctx) {
3980
- if (!hasProperty(ctx, 'cacheValue')) {
4021
+ if (is.Undef(ctx.cacheValue)) {
3981
4022
  ctx.cacheValue = ctx.parser.toValue(this.getFormData(ctx), ctx);
3982
4023
  }
3983
4024
 
@@ -4098,7 +4139,7 @@
4098
4139
  this.vm._updateValue(_objectSpread2({}, this.form));
4099
4140
  },
4100
4141
  isChange: function isChange(ctx, value) {
4101
- return JSON.stringify(ctx.rule.value) !== JSON.stringify(value);
4142
+ return JSON.stringify(ctx.rule.value, strFn) !== JSON.stringify(value, strFn);
4102
4143
  },
4103
4144
  isQuote: function isQuote(ctx, value) {
4104
4145
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
@@ -4122,6 +4163,7 @@
4122
4163
  if (this.refreshControl(ctx)) {
4123
4164
  this.$render.clearCacheAll();
4124
4165
  this.loadRule();
4166
+ this.vm.$emit('update', this.api);
4125
4167
  this.refresh();
4126
4168
  }
4127
4169
 
@@ -4149,6 +4191,10 @@
4149
4191
  });
4150
4192
  }
4151
4193
 
4194
+ function strFn(key, val) {
4195
+ return typeof val === 'function' ? '' + val : val;
4196
+ }
4197
+
4152
4198
  function toEmpty(obj) {
4153
4199
  Object.keys(obj).forEach(function (k) {
4154
4200
  return delete obj[k];
@@ -4167,6 +4213,9 @@
4167
4213
  render: function render(children, ctx) {
4168
4214
  return ctx.$render.defaultRender(ctx, children);
4169
4215
  },
4216
+ preview: function preview(children, ctx) {
4217
+ return ctx.$render.defaultRender(ctx, children);
4218
+ },
4170
4219
  mergeProp: function mergeProp(ctx) {}
4171
4220
  };
4172
4221
 
@@ -4293,6 +4342,8 @@
4293
4342
  }
4294
4343
 
4295
4344
  _flag && _this.loadChildren(n, ctx);
4345
+
4346
+ _this.vm.$emit('update', _this.api);
4296
4347
  });
4297
4348
  }
4298
4349
 
@@ -4828,6 +4879,11 @@
4828
4879
 
4829
4880
  function run(inject, rule, api) {
4830
4881
  var option = inject.value;
4882
+
4883
+ if (is.Function(option)) {
4884
+ option = option(rule, api);
4885
+ }
4886
+
4831
4887
  option = parseOpt(option);
4832
4888
 
4833
4889
  if (!option || !option.action) {
@@ -5128,6 +5184,7 @@
5128
5184
  },
5129
5185
  created: function created() {
5130
5186
  this.$handle.init();
5187
+ this.vm.$emit('created', this.api());
5131
5188
  },
5132
5189
  api: function api() {
5133
5190
  return this.$handle.api;
@@ -5158,6 +5215,7 @@
5158
5215
  copyRules: copyRules,
5159
5216
  fetch: fetch,
5160
5217
  $form: $form,
5218
+ parseFn: parseFn,
5161
5219
  parseJson: parseJson,
5162
5220
  toJson: toJson,
5163
5221
  init: function init(rules) {
@@ -5571,32 +5629,13 @@
5571
5629
  return !(!title.title && !title["native"] || isFalse(title.show));
5572
5630
  },
5573
5631
  makeInfo: function makeInfo(rule, uni) {
5574
- var _this = this;
5575
-
5576
5632
  var titleProp = rule.title;
5577
5633
  var infoProp = rule.info;
5578
5634
  var isTip = isTooltip(infoProp);
5579
5635
  var form = this.options.form;
5580
5636
  var children = [(titleProp.title || '') + (form.labelSuffix || form['label-suffix'] || '')];
5581
5637
 
5582
- var titleFn = function titleFn(pop) {
5583
- return _this.$r(mergeProps([titleProp, {
5584
- props: titleProp,
5585
- slot: titleProp.slot || (pop ? isTip ? 'default' : 'reference' : 'label'),
5586
- key: "".concat(uni, "tit"),
5587
- type: titleProp.type || 'span'
5588
- }]), children);
5589
- };
5590
-
5591
- if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"])) {
5592
- if (infoProp.icon !== false) {
5593
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
5594
- type: 'i',
5595
- "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5596
- key: "".concat(uni, "i")
5597
- }));
5598
- }
5599
-
5638
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5600
5639
  var prop = {
5601
5640
  type: infoProp.type || 'popover',
5602
5641
  props: _objectSpread2({}, infoProp),
@@ -5609,10 +5648,20 @@
5609
5648
  prop.props[field] = infoProp.info;
5610
5649
  }
5611
5650
 
5612
- return this.$r(mergeProps([infoProp, prop]), [titleFn(true)]);
5651
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), [this.$r({
5652
+ type: 'i',
5653
+ slot: isTip ? 'default' : 'reference',
5654
+ "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5655
+ key: "".concat(uni, "i")
5656
+ })]));
5613
5657
  }
5614
5658
 
5615
- return titleFn();
5659
+ return this.$r(mergeProps([titleProp, {
5660
+ props: titleProp,
5661
+ slot: titleProp.slot || 'label',
5662
+ key: "".concat(uni, "tit"),
5663
+ type: titleProp.type || 'span'
5664
+ }]), children);
5616
5665
  },
5617
5666
  makeCol: function makeCol(rule, uni, children) {
5618
5667
  var col = rule.col;
@@ -5662,7 +5711,7 @@
5662
5711
  }, [item]);
5663
5712
  },
5664
5713
  makeResetBtn: function makeResetBtn() {
5665
- var _this2 = this;
5714
+ var _this = this;
5666
5715
 
5667
5716
  var resetBtn = this.options.resetBtn;
5668
5717
  return this.$r({
@@ -5673,7 +5722,7 @@
5673
5722
  },
5674
5723
  on: {
5675
5724
  click: function click() {
5676
- var fApi = _this2.$handle.api;
5725
+ var fApi = _this.$handle.api;
5677
5726
  resetBtn.click ? resetBtn.click(fApi) : fApi.resetFields();
5678
5727
  }
5679
5728
  },
@@ -5681,7 +5730,7 @@
5681
5730
  }, [resetBtn.innerText]);
5682
5731
  },
5683
5732
  makeSubmitBtn: function makeSubmitBtn() {
5684
- var _this3 = this;
5733
+ var _this2 = this;
5685
5734
 
5686
5735
  var submitBtn = this.options.submitBtn;
5687
5736
  return this.$r({
@@ -5692,7 +5741,7 @@
5692
5741
  },
5693
5742
  on: {
5694
5743
  click: function click() {
5695
- var fApi = _this3.$handle.api;
5744
+ var fApi = _this2.$handle.api;
5696
5745
  submitBtn.click ? submitBtn.click(fApi) : fApi.submit();
5697
5746
  }
5698
5747
  },
@@ -6023,7 +6072,7 @@
6023
6072
  function elmFormCreate() {
6024
6073
  return FormCreateFactory({
6025
6074
  ui: "".concat("element-ui"),
6026
- version: "".concat("2.5.12"),
6075
+ version: "".concat("2.5.16"),
6027
6076
  manager: manager,
6028
6077
  extendApi: extendApi,
6029
6078
  install: install,