@form-create/iview 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/iview v2.5.12
2
+ * @form-create/iview 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.
@@ -267,6 +267,12 @@
267
267
  }
268
268
  },
269
269
  watch: {
270
+ 'formCreateInject.options': {
271
+ handler: function handler() {
272
+ this.update();
273
+ },
274
+ deep: true
275
+ },
270
276
  value: function value() {
271
277
  this.update();
272
278
  }
@@ -276,15 +282,13 @@
276
282
  trueValue: []
277
283
  };
278
284
  },
279
- computed: {
285
+ methods: {
280
286
  options: function options() {
281
287
  var opt = this.formCreateInject.options;
282
288
  return Array.isArray(opt) ? opt : [];
283
- }
284
- },
285
- methods: {
289
+ },
286
290
  onInput: function onInput(n) {
287
- this.$emit('input', this.options.filter(function (opt) {
291
+ this.$emit('input', this.options().filter(function (opt) {
288
292
  return n.indexOf(opt.label) !== -1;
289
293
  }).map(function (opt) {
290
294
  return opt.value;
@@ -295,7 +299,7 @@
295
299
  update: function update() {
296
300
  var _this = this;
297
301
 
298
- this.trueValue = this.value ? this.options.filter(function (opt) {
302
+ this.trueValue = this.value ? this.options().filter(function (opt) {
299
303
  return _this.value.indexOf(opt.value) !== -1;
300
304
  }).map(function (option) {
301
305
  return option.label;
@@ -314,7 +318,7 @@
314
318
  "on": {
315
319
  "input": this.onInput
316
320
  }
317
- }]), [this.options.map(function (opt, index) {
321
+ }]), [this.options().map(function (opt, index) {
318
322
  var props = _objectSpread2({}, opt);
319
323
 
320
324
  delete props.value;
@@ -837,6 +841,12 @@
837
841
  value: {}
838
842
  },
839
843
  watch: {
844
+ 'formCreateInject.options': {
845
+ handler: function handler() {
846
+ this.update();
847
+ },
848
+ deep: true
849
+ },
840
850
  value: function value() {
841
851
  this.update();
842
852
  }
@@ -846,15 +856,13 @@
846
856
  trueValue: []
847
857
  };
848
858
  },
849
- computed: {
859
+ methods: {
850
860
  options: function options() {
851
861
  var opt = this.formCreateInject.options;
852
862
  return Array.isArray(opt) ? opt : [];
853
- }
854
- },
855
- methods: {
863
+ },
856
864
  onInput: function onInput(n) {
857
- this.$emit('input', this.options.filter(function (opt) {
865
+ this.$emit('input', this.options().filter(function (opt) {
858
866
  return opt.label === n;
859
867
  }).reduce(function (initial, opt) {
860
868
  return opt.value;
@@ -863,7 +871,7 @@
863
871
  update: function update() {
864
872
  var _this = this;
865
873
 
866
- this.trueValue = this.options.filter(function (opt) {
874
+ this.trueValue = this.options().filter(function (opt) {
867
875
  return opt.value === _this.value;
868
876
  }).reduce(function (initial, opt) {
869
877
  return opt.label;
@@ -882,7 +890,7 @@
882
890
  "on": {
883
891
  "input": this.onInput
884
892
  }
885
- }]), [this.options.map(function (opt, index) {
893
+ }]), [this.options().map(function (opt, index) {
886
894
  var props = _objectSpread2({}, opt);
887
895
 
888
896
  delete props.value;
@@ -1068,7 +1076,8 @@
1068
1076
  return {
1069
1077
  uploadList: [],
1070
1078
  previewVisible: false,
1071
- previewImage: ''
1079
+ previewImage: '',
1080
+ cacheFiles: []
1072
1081
  };
1073
1082
  },
1074
1083
  created: function created() {
@@ -1215,7 +1224,11 @@
1215
1224
  }).filter(function (url) {
1216
1225
  return url !== undefined;
1217
1226
  });
1218
- this.$emit('input', this.maxLength === 1 ? files[0] || '' : files);
1227
+
1228
+ if (this.cacheFiles.length !== files.length) {
1229
+ this.cacheFiles = _toConsumableArray(files);
1230
+ this.$emit('input', this.maxLength === 1 ? files[0] || '' : files);
1231
+ }
1219
1232
  },
1220
1233
  handleCancel: function handleCancel() {
1221
1234
  this.previewVisible = false;
@@ -1907,6 +1920,7 @@
1907
1920
  Object.keys(this.formCreate.prop).forEach(function (k) {
1908
1921
  extend(_this2.$options[k], _this2.formCreate.prop[k]);
1909
1922
  });
1923
+ this.$emit('beforeCreate', this.formCreate.api());
1910
1924
  }
1911
1925
  };
1912
1926
  }
@@ -1987,6 +2001,20 @@
1987
2001
  return [].concat(keyAttrs, _toConsumableArray(normalMerge$1), _toConsumableArray(toArrayMerge$1), _toConsumableArray(functionalMerge$1), arrayAttrs, normalAttrs);
1988
2002
  }
1989
2003
 
2004
+ function format(type, msg, rule) {
2005
+ return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2006
+ }
2007
+ function tip(msg, rule) {
2008
+ console.warn(format('tip', msg, rule));
2009
+ }
2010
+ function err(msg, rule) {
2011
+ console.error(format('err', msg, rule));
2012
+ }
2013
+ function logError(e) {
2014
+ err(e.toString());
2015
+ console.error(e);
2016
+ }
2017
+
1990
2018
  function deepExtend(origin) {
1991
2019
  var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1992
2020
  var mode = arguments.length > 2 ? arguments[2] : undefined;
@@ -2015,14 +2043,18 @@
2015
2043
  }
2016
2044
 
2017
2045
  origin[key] = deepExtend(origin[key], clone, mode);
2018
- } else if (is.Undef(clone)) {
2019
- $set(origin, key, clone);
2020
- } else if (clone.__json !== undefined) {
2021
- $set(origin, key, clone.__json);
2022
- } else if (clone.__origin !== undefined) {
2023
- $set(origin, key, clone.__origin);
2024
2046
  } else {
2025
2047
  $set(origin, key, clone);
2048
+
2049
+ if (!is.Undef(clone)) {
2050
+ if (clone.__json !== undefined) {
2051
+ origin[key].__json = clone.__json;
2052
+ }
2053
+
2054
+ if (clone.__origin !== undefined) {
2055
+ origin[key].__origin = clone.__origin;
2056
+ }
2057
+ }
2026
2058
  }
2027
2059
  }
2028
2060
  }
@@ -2037,20 +2069,6 @@
2037
2069
  }).value;
2038
2070
  }
2039
2071
 
2040
- function format(type, msg, rule) {
2041
- return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2042
- }
2043
- function tip(msg, rule) {
2044
- console.warn(format('tip', msg, rule));
2045
- }
2046
- function err(msg, rule) {
2047
- console.error(format('err', msg, rule));
2048
- }
2049
- function logError(e) {
2050
- err(e.toString());
2051
- console.error(e);
2052
- }
2053
-
2054
2072
  var PREFIX = '[[FORM-CREATE-PREFIX-';
2055
2073
  var SUFFIX = '-FORM-CREATE-SUFFIX]]';
2056
2074
  var $T = '$FN:';
@@ -2127,8 +2145,8 @@
2127
2145
  };
2128
2146
  } //todo 优化位置
2129
2147
 
2130
- function copyRule(rule, mode) {
2131
- return copyRules([rule], mode || false)[0];
2148
+ function copyRule(rule) {
2149
+ return copyRules([rule])[0];
2132
2150
  }
2133
2151
  function copyRules(rules, mode) {
2134
2152
  return deepExtend([], _toConsumableArray(rules), mode || false);
@@ -2319,11 +2337,6 @@
2319
2337
  }
2320
2338
 
2321
2339
  var api = {
2322
- helper: {
2323
- tidyFields: tidyFields,
2324
- props: props
2325
- },
2326
-
2327
2340
  get config() {
2328
2341
  return h.options;
2329
2342
  },
@@ -2467,6 +2480,12 @@
2467
2480
  });
2468
2481
  h.refresh();
2469
2482
  },
2483
+ all: function all(origin) {
2484
+ return Object.keys(h.ctxs).map(function (k) {
2485
+ var ctx = h.ctxs[k];
2486
+ return origin ? ctx.origin : ctx.rule;
2487
+ });
2488
+ },
2470
2489
  model: function model(origin) {
2471
2490
  return h.fields().reduce(function (initial, key) {
2472
2491
  var ctx = h.fieldCtx[key][0];
@@ -2654,13 +2673,26 @@
2654
2673
  nextRefresh: function nextRefresh(fn) {
2655
2674
  h.nextRefresh();
2656
2675
  fn && invoke(fn);
2676
+ },
2677
+ emit: function emit(name) {
2678
+ var _h$vm;
2679
+
2680
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2681
+ args[_key3 - 1] = arguments[_key3];
2682
+ }
2683
+
2684
+ (_h$vm = h.vm).$emit.apply(_h$vm, [name].concat(args));
2685
+ },
2686
+ helper: {
2687
+ tidyFields: tidyFields,
2688
+ props: props
2657
2689
  }
2658
2690
  };
2659
2691
  ['on', 'once', 'off', 'set'].forEach(function (n) {
2660
2692
  api[n] = function () {
2661
- var _h$vm;
2693
+ var _h$vm2;
2662
2694
 
2663
- (_h$vm = h.vm)["$".concat(n)].apply(_h$vm, arguments);
2695
+ (_h$vm2 = h.vm)["$".concat(n)].apply(_h$vm2, arguments);
2664
2696
  };
2665
2697
  });
2666
2698
  api.changeValue = api.changeField = api.setValue;
@@ -2885,6 +2917,7 @@
2885
2917
  renderCtx: function renderCtx(ctx, parent) {
2886
2918
  if (ctx.type === 'hidden') return;
2887
2919
  var rule = ctx.rule;
2920
+ var preview = this.options.preview || false;
2888
2921
 
2889
2922
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2890
2923
  var vn;
@@ -2935,12 +2968,13 @@
2935
2968
  vn = this.vm.$scopedSlots[slot]({
2936
2969
  rule: rule,
2937
2970
  prop: prop,
2971
+ preview: preview,
2938
2972
  children: children,
2939
2973
  api: this.$handle.api,
2940
2974
  model: prop.model || {}
2941
2975
  });
2942
2976
  } else {
2943
- vn = ctx.parser.render(children, ctx);
2977
+ vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
2944
2978
  }
2945
2979
  }
2946
2980
 
@@ -3005,20 +3039,26 @@
3005
3039
  var _this7 = this;
3006
3040
 
3007
3041
  if (!this.vm.ctxInject[ctx.id]) {
3008
- $set(this.vm.ctxInject, ctx.id, {});
3042
+ $set(this.vm.ctxInject, ctx.id, {
3043
+ api: this.$handle.api,
3044
+ form: this.fc.create,
3045
+ subForm: function subForm(_subForm) {
3046
+ _this7.$handle.addSubForm(ctx, _subForm);
3047
+ },
3048
+ options: [],
3049
+ children: [],
3050
+ prop: {},
3051
+ preview: false,
3052
+ field: ctx.field,
3053
+ rule: ctx.rule
3054
+ });
3009
3055
  }
3010
3056
 
3011
3057
  var inject = this.vm.ctxInject[ctx.id];
3012
3058
  extend(inject, {
3013
- api: this.$handle.api,
3014
- form: this.fc.create,
3015
- subForm: function subForm(_subForm) {
3016
- _this7.$handle.addSubForm(ctx, _subForm);
3017
- },
3018
- field: ctx.field,
3059
+ preview: this.options.preview || false,
3019
3060
  options: ctx.prop.options,
3020
3061
  children: ctx.rule.children,
3021
- rule: ctx.rule,
3022
3062
  prop: function () {
3023
3063
  var temp = _objectSpread2({}, ctx.prop);
3024
3064
 
@@ -3928,6 +3968,7 @@
3928
3968
  this.refresh();
3929
3969
  this.bus.$off('next-tick', this.nextReload);
3930
3970
  this.bus.$once('next-tick', this.nextReload);
3971
+ this.vm.$emit('update', this.api);
3931
3972
  },
3932
3973
  //todo 组件生成全部通过 alias
3933
3974
  refresh: function refresh() {
@@ -3963,7 +4004,7 @@
3963
4004
  function useInput(Handler) {
3964
4005
  extend(Handler.prototype, {
3965
4006
  getValue: function getValue(ctx) {
3966
- if (!hasProperty(ctx, 'cacheValue')) {
4007
+ if (is.Undef(ctx.cacheValue)) {
3967
4008
  ctx.cacheValue = ctx.parser.toValue(this.getFormData(ctx), ctx);
3968
4009
  }
3969
4010
 
@@ -4084,7 +4125,7 @@
4084
4125
  this.vm._updateValue(_objectSpread2({}, this.form));
4085
4126
  },
4086
4127
  isChange: function isChange(ctx, value) {
4087
- return JSON.stringify(ctx.rule.value) !== JSON.stringify(value);
4128
+ return JSON.stringify(ctx.rule.value, strFn) !== JSON.stringify(value, strFn);
4088
4129
  },
4089
4130
  isQuote: function isQuote(ctx, value) {
4090
4131
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
@@ -4108,6 +4149,7 @@
4108
4149
  if (this.refreshControl(ctx)) {
4109
4150
  this.$render.clearCacheAll();
4110
4151
  this.loadRule();
4152
+ this.vm.$emit('update', this.api);
4111
4153
  this.refresh();
4112
4154
  }
4113
4155
 
@@ -4135,6 +4177,10 @@
4135
4177
  });
4136
4178
  }
4137
4179
 
4180
+ function strFn(key, val) {
4181
+ return typeof val === 'function' ? '' + val : val;
4182
+ }
4183
+
4138
4184
  function toEmpty(obj) {
4139
4185
  Object.keys(obj).forEach(function (k) {
4140
4186
  return delete obj[k];
@@ -4153,6 +4199,9 @@
4153
4199
  render: function render(children, ctx) {
4154
4200
  return ctx.$render.defaultRender(ctx, children);
4155
4201
  },
4202
+ preview: function preview(children, ctx) {
4203
+ return ctx.$render.defaultRender(ctx, children);
4204
+ },
4156
4205
  mergeProp: function mergeProp(ctx) {}
4157
4206
  };
4158
4207
 
@@ -4279,6 +4328,8 @@
4279
4328
  }
4280
4329
 
4281
4330
  _flag && _this.loadChildren(n, ctx);
4331
+
4332
+ _this.vm.$emit('update', _this.api);
4282
4333
  });
4283
4334
  }
4284
4335
 
@@ -4814,6 +4865,11 @@
4814
4865
 
4815
4866
  function run(inject, rule, api) {
4816
4867
  var option = inject.value;
4868
+
4869
+ if (is.Function(option)) {
4870
+ option = option(rule, api);
4871
+ }
4872
+
4817
4873
  option = parseOpt(option);
4818
4874
 
4819
4875
  if (!option || !option.action) {
@@ -5114,6 +5170,7 @@
5114
5170
  },
5115
5171
  created: function created() {
5116
5172
  this.$handle.init();
5173
+ this.vm.$emit('created', this.api());
5117
5174
  },
5118
5175
  api: function api() {
5119
5176
  return this.$handle.api;
@@ -5144,6 +5201,7 @@
5144
5201
  copyRules: copyRules,
5145
5202
  fetch: fetch,
5146
5203
  $form: $form,
5204
+ parseFn: parseFn,
5147
5205
  parseJson: parseJson,
5148
5206
  toJson: toJson,
5149
5207
  init: function init(rules) {
@@ -5578,34 +5636,12 @@
5578
5636
  return !(!title.title && !title["native"] || isFalse(title.show));
5579
5637
  },
5580
5638
  makeInfo: function makeInfo(rule, uni) {
5581
- var _this = this;
5582
5639
 
5583
5640
  var titleProp = rule.title;
5584
5641
  var infoProp = rule.info;
5585
5642
  var children = [titleProp.title];
5586
5643
 
5587
- var titleFn = function titleFn(pop) {
5588
- return _this.$r(mergeProps([titleProp, {
5589
- props: titleProp,
5590
- slot: titleProp.slot || (pop ? 'default' : 'label'),
5591
- key: "".concat(uni, "tit"),
5592
- type: titleProp.type || 'span'
5593
- }]), children);
5594
- };
5595
-
5596
- if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"])) {
5597
- if (infoProp.icon !== false) {
5598
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
5599
- type: 'icon',
5600
- props: {
5601
- type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon,
5602
- size: 16
5603
- },
5604
- style: 'margin-top: -1px',
5605
- key: "".concat(uni, "i")
5606
- }));
5607
- }
5608
-
5644
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5609
5645
  var prop = {
5610
5646
  type: infoProp.type || 'poptip',
5611
5647
  props: _objectSpread2({}, infoProp),
@@ -5618,10 +5654,23 @@
5618
5654
  prop.props[field] = infoProp.info;
5619
5655
  }
5620
5656
 
5621
- return this.$r(mergeProps([infoProp, prop]), [titleFn(true)]);
5657
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), [this.$r({
5658
+ type: 'icon',
5659
+ props: {
5660
+ type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon,
5661
+ size: 16
5662
+ },
5663
+ style: 'margin-top: -1px',
5664
+ key: "".concat(uni, "i")
5665
+ })]));
5622
5666
  }
5623
5667
 
5624
- return titleFn();
5668
+ return this.$r(mergeProps([titleProp, {
5669
+ props: titleProp,
5670
+ slot: titleProp.slot || 'label',
5671
+ key: "".concat(uni, "tit"),
5672
+ type: titleProp.type || 'span'
5673
+ }]), children);
5625
5674
  },
5626
5675
  makeCol: function makeCol(rule, uni, children) {
5627
5676
  var col = rule.col;
@@ -6051,7 +6100,7 @@
6051
6100
  function ivuFormCreate() {
6052
6101
  return FormCreateFactory({
6053
6102
  ui: "".concat("iview"),
6054
- version: "".concat("2.5.12"),
6103
+ version: "".concat("2.5.16"),
6055
6104
  manager: manager,
6056
6105
  install: install,
6057
6106
  extendApi: extendApi,