@form-create/iview 2.5.10 → 2.5.14

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.10
2
+ * @form-create/iview v2.5.14
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
  }
@@ -277,8 +283,12 @@
277
283
  };
278
284
  },
279
285
  methods: {
286
+ options: function options() {
287
+ var opt = this.formCreateInject.options;
288
+ return Array.isArray(opt) ? opt : [];
289
+ },
280
290
  onInput: function onInput(n) {
281
- this.$emit('input', this.formCreateInject.options.filter(function (opt) {
291
+ this.$emit('input', this.options().filter(function (opt) {
282
292
  return n.indexOf(opt.label) !== -1;
283
293
  }).map(function (opt) {
284
294
  return opt.value;
@@ -289,7 +299,7 @@
289
299
  update: function update() {
290
300
  var _this = this;
291
301
 
292
- this.trueValue = this.value ? this.formCreateInject.options.filter(function (opt) {
302
+ this.trueValue = this.value ? this.options().filter(function (opt) {
293
303
  return _this.value.indexOf(opt.value) !== -1;
294
304
  }).map(function (option) {
295
305
  return option.label;
@@ -308,7 +318,7 @@
308
318
  "on": {
309
319
  "input": this.onInput
310
320
  }
311
- }]), [this.formCreateInject.options.map(function (opt, index) {
321
+ }]), [this.options().map(function (opt, index) {
312
322
  var props = _objectSpread2({}, opt);
313
323
 
314
324
  delete props.value;
@@ -655,7 +665,6 @@
655
665
  }]))]);
656
666
  },
657
667
  handleClick: function handleClick(src) {
658
- if (this.disabled) return;
659
668
  return this.onHandle(src);
660
669
  },
661
670
  handleRemove: function handleRemove(src) {
@@ -832,6 +841,12 @@
832
841
  value: {}
833
842
  },
834
843
  watch: {
844
+ 'formCreateInject.options': {
845
+ handler: function handler() {
846
+ this.update();
847
+ },
848
+ deep: true
849
+ },
835
850
  value: function value() {
836
851
  this.update();
837
852
  }
@@ -842,8 +857,12 @@
842
857
  };
843
858
  },
844
859
  methods: {
860
+ options: function options() {
861
+ var opt = this.formCreateInject.options;
862
+ return Array.isArray(opt) ? opt : [];
863
+ },
845
864
  onInput: function onInput(n) {
846
- this.$emit('input', this.formCreateInject.options.filter(function (opt) {
865
+ this.$emit('input', this.options().filter(function (opt) {
847
866
  return opt.label === n;
848
867
  }).reduce(function (initial, opt) {
849
868
  return opt.value;
@@ -852,7 +871,7 @@
852
871
  update: function update() {
853
872
  var _this = this;
854
873
 
855
- this.trueValue = this.formCreateInject.options.filter(function (opt) {
874
+ this.trueValue = this.options().filter(function (opt) {
856
875
  return opt.value === _this.value;
857
876
  }).reduce(function (initial, opt) {
858
877
  return opt.label;
@@ -871,7 +890,7 @@
871
890
  "on": {
872
891
  "input": this.onInput
873
892
  }
874
- }]), [this.formCreateInject.options.map(function (opt, index) {
893
+ }]), [this.options().map(function (opt, index) {
875
894
  var props = _objectSpread2({}, opt);
876
895
 
877
896
  delete props.value;
@@ -917,7 +936,8 @@
917
936
  }
918
937
  },
919
938
  render: function render(h, ctx) {
920
- return h("Select", helper([{}, ctx.data]), [ctx.props.formCreateInject.options.map(function (props, index) {
939
+ var options = ctx.props.formCreateInject.options;
940
+ return h("Select", helper([{}, ctx.data]), [(Array.isArray(options) ? options : []).map(function (props, index) {
921
941
  var slot = props.slot;
922
942
  return h("Option", {
923
943
  "props": _objectSpread2({}, props),
@@ -1088,7 +1108,6 @@
1088
1108
  this.$refs.upload.handleRemove(file);
1089
1109
  },
1090
1110
  handleClick: function handleClick(file) {
1091
- if (this.isDisabled()) return;
1092
1111
  this.onHandle(file);
1093
1112
  },
1094
1113
  makeItem: function makeItem(file, index) {
@@ -1322,7 +1341,8 @@
1322
1341
  return {
1323
1342
  len: 0,
1324
1343
  cacheRule: {},
1325
- cacheValue: {}
1344
+ cacheValue: {},
1345
+ type: undefined
1326
1346
  };
1327
1347
  },
1328
1348
  computed: {
@@ -1494,7 +1514,7 @@
1494
1514
  this.addRule(i, true);
1495
1515
  },
1496
1516
  del: function del(index, key) {
1497
- if (this.disabled || false === this.onBeforeRemove(this.value)) {
1517
+ if (this.disabled || false === this.onBeforeRemove(this.value, index)) {
1498
1518
  return;
1499
1519
  }
1500
1520
 
@@ -1567,6 +1587,7 @@
1567
1587
  }
1568
1588
  },
1569
1589
  created: function created() {
1590
+ this.type = this.formCreateInject.form.$form();
1570
1591
  var d = (this.expand || 0) - this.value.length;
1571
1592
 
1572
1593
  if (d > 0) {
@@ -1583,6 +1604,7 @@
1583
1604
  var h = arguments[0];
1584
1605
  var keys = Object.keys(this.cacheRule);
1585
1606
  var button = this.button;
1607
+ var Type = this.type;
1586
1608
  return keys.length === 0 ? this.$scopedSlots["default"] ? this.$scopedSlots["default"]({
1587
1609
  vm: this,
1588
1610
  add: this.add
@@ -1612,7 +1634,7 @@
1612
1634
  "attrs": {
1613
1635
  "span": button ? 20 : 24
1614
1636
  }
1615
- }, [h("FormItem", [h("FormCreate", helper([{
1637
+ }, [h("FormItem", [h(Type, helper([{
1616
1638
  "key": key
1617
1639
  }, {
1618
1640
  "on": {
@@ -1644,9 +1666,6 @@
1644
1666
  }
1645
1667
  }, [_this9.makeIcon(keys.length, index, key)]) : null]);
1646
1668
  })]);
1647
- },
1648
- beforeMount: function beforeMount() {
1649
- this.$options.components.FormCreate = this.formCreateInject.form.$form();
1650
1669
  }
1651
1670
  };
1652
1671
  }
@@ -1688,7 +1707,8 @@
1688
1707
  data: function data() {
1689
1708
  return {
1690
1709
  cacheRule: {},
1691
- cacheValue: {}
1710
+ cacheValue: {},
1711
+ type: undefined
1692
1712
  };
1693
1713
  },
1694
1714
  watch: {
@@ -1750,13 +1770,15 @@
1750
1770
  },
1751
1771
  created: function created() {
1752
1772
  this.addRule();
1773
+ this.type = this.formCreateInject.form.$form();
1753
1774
  },
1754
1775
  render: function render() {
1755
1776
  var h = arguments[0];
1756
1777
  var _this$cacheRule = this.cacheRule,
1757
1778
  rule = _this$cacheRule.rule,
1758
1779
  options = _this$cacheRule.options;
1759
- return h("FormCreate", helper([{}, {
1780
+ var Type = this.type;
1781
+ return h(Type, helper([{}, {
1760
1782
  "on": {
1761
1783
  'update:value': this.formData,
1762
1784
  'emit-event': this.emitEvent,
@@ -1769,9 +1791,6 @@
1769
1791
  "extendOption": true
1770
1792
  }
1771
1793
  }]));
1772
- },
1773
- beforeMount: function beforeMount() {
1774
- this.$options.components.FormCreate = this.formCreateInject.form.$form();
1775
1794
  }
1776
1795
  };
1777
1796
 
@@ -1896,6 +1915,7 @@
1896
1915
  Object.keys(this.formCreate.prop).forEach(function (k) {
1897
1916
  extend(_this2.$options[k], _this2.formCreate.prop[k]);
1898
1917
  });
1918
+ this.$emit('beforeCreate', this.formCreate.api());
1899
1919
  }
1900
1920
  };
1901
1921
  }
@@ -1971,11 +1991,25 @@
1971
1991
 
1972
1992
  var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'nativeEmit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key'];
1973
1993
  var arrayAttrs = ['validate', 'children', 'control'];
1974
- var normalAttrs = ['effect'];
1994
+ var normalAttrs = ['effect', 'deep'];
1975
1995
  function attrs() {
1976
1996
  return [].concat(keyAttrs, _toConsumableArray(normalMerge$1), _toConsumableArray(toArrayMerge$1), _toConsumableArray(functionalMerge$1), arrayAttrs, normalAttrs);
1977
1997
  }
1978
1998
 
1999
+ function format(type, msg, rule) {
2000
+ return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2001
+ }
2002
+ function tip(msg, rule) {
2003
+ console.warn(format('tip', msg, rule));
2004
+ }
2005
+ function err(msg, rule) {
2006
+ console.error(format('err', msg, rule));
2007
+ }
2008
+ function logError(e) {
2009
+ err(e.toString());
2010
+ console.error(e);
2011
+ }
2012
+
1979
2013
  function deepExtend(origin) {
1980
2014
  var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1981
2015
  var mode = arguments.length > 2 ? arguments[2] : undefined;
@@ -2026,23 +2060,10 @@
2026
2060
  }).value;
2027
2061
  }
2028
2062
 
2029
- function format(type, msg, rule) {
2030
- return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2031
- }
2032
- function tip(msg, rule) {
2033
- console.warn(format('tip', msg, rule));
2034
- }
2035
- function err(msg, rule) {
2036
- console.error(format('err', msg, rule));
2037
- }
2038
- function logError(e) {
2039
- err(e.toString());
2040
- console.error(e);
2041
- }
2042
-
2043
2063
  var PREFIX = '[[FORM-CREATE-PREFIX-';
2044
2064
  var SUFFIX = '-FORM-CREATE-SUFFIX]]';
2045
2065
  var $T = '$FN:';
2066
+ var $TX = '$FNX:';
2046
2067
  var FUNCTION = 'function';
2047
2068
  function toJson(obj, space) {
2048
2069
  return JSON.stringify(deepExtend([], obj, true), function (key, val) {
@@ -2067,7 +2088,7 @@
2067
2088
  }
2068
2089
 
2069
2090
  function parseFn(fn, mode) {
2070
- if (fn && is.String(fn)) {
2091
+ if (fn && is.String(fn) && fn.length > 4) {
2071
2092
  var v = fn.trim();
2072
2093
  var flag = false;
2073
2094
 
@@ -2078,8 +2099,8 @@
2078
2099
  } else if (v.indexOf($T) === 0) {
2079
2100
  v = v.replace($T, '');
2080
2101
  flag = true;
2081
- } else if (v.indexOf('$FNX:') === 0) {
2082
- v = makeFn('function($inject){' + v.replace('$FNX:', '') + '}');
2102
+ } else if (v.indexOf($TX) === 0) {
2103
+ v = makeFn('function($inject){' + v.replace($TX, '') + '}');
2083
2104
  v.__json = fn;
2084
2105
  v.__inject = true;
2085
2106
  return v;
@@ -2092,7 +2113,7 @@
2092
2113
  val.__json = fn;
2093
2114
  return val;
2094
2115
  } catch (e) {
2095
- err("\u89E3\u6790\u5931\u8D25:".concat(v));
2116
+ err("\u89E3\u6790\u5931\u8D25:".concat(v, "\n\nerr: ").concat(e));
2096
2117
  return undefined;
2097
2118
  }
2098
2119
  }
@@ -2115,11 +2136,11 @@
2115
2136
  };
2116
2137
  } //todo 优化位置
2117
2138
 
2118
- function copyRule(rule, mode) {
2119
- return copyRules([rule], mode || false)[0];
2139
+ function copyRule(rule) {
2140
+ return copyRules([rule])[0];
2120
2141
  }
2121
- function copyRules(rules, mode) {
2122
- return deepExtend([], _toConsumableArray(rules), mode || false);
2142
+ function copyRules(rules) {
2143
+ return parseJson(toJson(rules));
2123
2144
  }
2124
2145
  function mergeRule(rule, merge) {
2125
2146
  mergeProps(Array.isArray(merge) ? merge : [merge], rule, {
@@ -2183,7 +2204,7 @@
2183
2204
  to;
2184
2205
  (idx || '').split('.').forEach(function (v) {
2185
2206
  if (to) {
2186
- if (!_data[to]) {
2207
+ if (!_data[to] || _typeof(_data[to]) != 'object') {
2187
2208
  _data[to] = {};
2188
2209
  }
2189
2210
 
@@ -2281,13 +2302,6 @@
2281
2302
  return deepCopy(value);
2282
2303
  }
2283
2304
 
2284
- function byRules(ctxs, origin) {
2285
- return Object.keys(ctxs).reduce(function (initial, key) {
2286
- initial[key] = origin ? ctxs[key].origin : ctxs[key].rule;
2287
- return initial;
2288
- }, {});
2289
- }
2290
-
2291
2305
  function Api(h) {
2292
2306
  function tidyFields(fields) {
2293
2307
  if (is.Undef(fields)) fields = h.fields();else if (!Array.isArray(fields)) fields = [fields];
@@ -2296,10 +2310,10 @@
2296
2310
 
2297
2311
  function props(fields, key, val) {
2298
2312
  tidyFields(fields).forEach(function (field) {
2299
- var ctx = h.getCtx(field);
2300
- if (!ctx) return;
2301
- $set(ctx.rule, key, val);
2302
- h.$render.clearCache(ctx);
2313
+ h.getCtxs(field).forEach(function (ctx) {
2314
+ $set(ctx.rule, key, val);
2315
+ h.$render.clearCache(ctx);
2316
+ });
2303
2317
  });
2304
2318
  }
2305
2319
 
@@ -2314,11 +2328,6 @@
2314
2328
  }
2315
2329
 
2316
2330
  var api = {
2317
- helper: {
2318
- tidyFields: tidyFields,
2319
- props: props
2320
- },
2321
-
2322
2331
  get config() {
2323
2332
  return h.options;
2324
2333
  },
@@ -2345,23 +2354,26 @@
2345
2354
 
2346
2355
  formData: function formData(fields) {
2347
2356
  return tidyFields(fields).reduce(function (initial, id) {
2348
- var ctx = h.fieldCtx[id];
2357
+ var ctx = h.getFieldCtx(id);
2349
2358
  if (!ctx) return initial;
2350
2359
  initial[ctx.field] = copy(ctx.rule.value);
2351
2360
  return initial;
2352
2361
  }, copy(h.appendData));
2353
2362
  },
2354
2363
  getValue: function getValue(field) {
2355
- var ctx = h.fieldCtx[field];
2364
+ var ctx = h.getFieldCtx(field);
2356
2365
  if (!ctx) return;
2357
2366
  return copy(ctx.rule.value);
2358
2367
  },
2359
2368
  coverValue: function coverValue(formData) {
2360
2369
  h.deferSyncValue(function () {
2361
- Object.keys(h.fieldCtx).forEach(function (key) {
2362
- var ctx = h.fieldCtx[key];
2363
- if (!ctx) return h.appendData[key] = formData[key];
2364
- ctx.rule.value = hasProperty(formData, key) ? formData[key] : undefined;
2370
+ api.fields().forEach(function (key) {
2371
+ var ctxs = h.fieldCtx[key];
2372
+ if (!ctxs) return h.appendData[key] = formData[key];
2373
+ var flag = hasProperty(formData, key);
2374
+ ctxs.forEach(function (ctx) {
2375
+ ctx.rule.value = flag ? formData[key] : undefined;
2376
+ });
2365
2377
  });
2366
2378
  });
2367
2379
  },
@@ -2370,17 +2382,22 @@
2370
2382
  if (arguments.length >= 2) formData = _defineProperty({}, field, arguments[1]);
2371
2383
  h.deferSyncValue(function () {
2372
2384
  Object.keys(formData).forEach(function (key) {
2373
- var ctx = h.fieldCtx[key];
2374
- if (!ctx) return h.appendData[key] = formData[key];
2375
- ctx.rule.value = formData[key];
2385
+ var ctxs = h.fieldCtx[key];
2386
+ if (!ctxs) return h.appendData[key] = formData[key];
2387
+ ctxs.forEach(function (ctx) {
2388
+ ctx.rule.value = formData[key];
2389
+ });
2376
2390
  });
2377
2391
  });
2378
2392
  },
2379
2393
  removeField: function removeField(field) {
2380
2394
  var ctx = h.getCtx(field);
2381
- if (!ctx) return;
2382
- ctx.rm();
2383
- return ctx.origin;
2395
+ h.deferSyncValue(function () {
2396
+ h.getCtxs(field).forEach(function (ctx) {
2397
+ ctx.rm();
2398
+ });
2399
+ }, true);
2400
+ return ctx ? ctx.origin : undefined;
2384
2401
  },
2385
2402
  removeRule: function removeRule(rule) {
2386
2403
  var ctx = rule && byCtx(rule);
@@ -2396,10 +2413,8 @@
2396
2413
  return h.fields();
2397
2414
  },
2398
2415
  append: function append(rule, after, child) {
2399
- var fields = Object.keys(h.fieldCtx),
2400
- index = h.sort.length - 1,
2416
+ var index = h.sort.length - 1,
2401
2417
  rules;
2402
- if (rule.field && fields.indexOf(rule.field) > -1) return err("".concat(rule.field, " \u5B57\u6BB5\u5DF2\u5B58\u5728"), rule);
2403
2418
  var ctx = h.getCtx(after);
2404
2419
 
2405
2420
  if (ctx) {
@@ -2415,10 +2430,8 @@
2415
2430
  rules.splice(index + 1, 0, rule);
2416
2431
  },
2417
2432
  prepend: function prepend(rule, after, child) {
2418
- var fields = Object.keys(h.fieldCtx),
2419
- index = 0,
2433
+ var index = 0,
2420
2434
  rules;
2421
- if (rule.field && fields.indexOf(rule.field) > -1) return err("".concat(rule.field, " \u5B57\u6BB5\u5DF2\u5B58\u5728"), rule);
2422
2435
  var ctx = h.getCtx(after);
2423
2436
 
2424
2437
  if (ctx) {
@@ -2452,17 +2465,33 @@
2452
2465
  },
2453
2466
  disabled: function disabled(_disabled, fields) {
2454
2467
  tidyFields(fields).forEach(function (field) {
2455
- var ctx = h.fieldCtx[field];
2456
- if (!ctx) return;
2457
- $set(ctx.rule.props, 'disabled', !!_disabled);
2468
+ h.getCtxs(field).forEach(function (ctx) {
2469
+ $set(ctx.rule.props, 'disabled', !!_disabled);
2470
+ });
2458
2471
  });
2459
2472
  h.refresh();
2460
2473
  },
2474
+ all: function all(origin) {
2475
+ return Object.keys(h.ctxs).map(function (k) {
2476
+ var ctx = h.ctxs[k];
2477
+ return origin ? ctx.origin : ctx.rule;
2478
+ });
2479
+ },
2461
2480
  model: function model(origin) {
2462
- return byRules(h.fieldCtx, origin);
2481
+ return h.fields().reduce(function (initial, key) {
2482
+ var ctx = h.fieldCtx[key][0];
2483
+ initial[key] = origin ? ctx.origin : ctx.rule;
2484
+ return initial;
2485
+ }, {});
2463
2486
  },
2464
2487
  component: function component(origin) {
2465
- return byRules(h.nameCtx, origin);
2488
+ return Object.keys(h.nameCtx).reduce(function (initial, key) {
2489
+ var ctx = h.nameCtx[key].map(function (ctx) {
2490
+ return origin ? ctx.origin : ctx.rule;
2491
+ });
2492
+ initial[key] = ctx.length === 1 ? ctx[0] : ctx;
2493
+ return initial;
2494
+ }, {});
2466
2495
  },
2467
2496
  bind: function bind() {
2468
2497
  return api.form;
@@ -2480,25 +2509,39 @@
2480
2509
  });
2481
2510
  },
2482
2511
  sync: function sync(field) {
2483
- var ctx = is.Object(field) ? byCtx(field) : h.getCtx(field);
2512
+ if (Array.isArray(field)) {
2513
+ field.forEach(function (v) {
2514
+ return api.sync(v);
2515
+ });
2516
+ return;
2517
+ }
2484
2518
 
2485
- if (ctx && !ctx.deleted) {
2486
- var subForm = h.subForm[field];
2519
+ var ctxs = is.Object(field) ? byCtx(field) : h.getCtxs(field);
2487
2520
 
2488
- if (subForm) {
2489
- if (Array.isArray(subForm)) {
2490
- subForm.forEach(function (form) {
2491
- form.refresh();
2492
- });
2493
- } else if (subForm) {
2494
- subForm.refresh();
2495
- }
2496
- } //ctx.updateKey(true);
2521
+ if (!ctxs) {
2522
+ return;
2523
+ }
2497
2524
 
2525
+ ctxs = Array.isArray(ctxs) ? ctxs : [ctxs];
2526
+ ctxs.forEach(function (ctx) {
2527
+ if (!ctx.deleted) {
2528
+ var subForm = h.subForm[ctx.id];
2498
2529
 
2499
- h.$render.clearCache(ctx);
2500
- h.refresh();
2501
- }
2530
+ if (subForm) {
2531
+ if (Array.isArray(subForm)) {
2532
+ subForm.forEach(function (form) {
2533
+ form.refresh();
2534
+ });
2535
+ } else if (subForm) {
2536
+ subForm.refresh();
2537
+ }
2538
+ } //ctx.updateKey(true);
2539
+
2540
+
2541
+ h.$render.clearCache(ctx);
2542
+ }
2543
+ });
2544
+ h.refresh();
2502
2545
  },
2503
2546
  refresh: function refresh() {
2504
2547
  allSubForm().forEach(function (sub) {
@@ -2521,8 +2564,9 @@
2521
2564
  h.changeStatus = false;
2522
2565
  },
2523
2566
  updateRule: function updateRule(id, rule) {
2524
- var r = api.getRule(id);
2525
- r && extend(r, rule);
2567
+ h.getCtxs(id).forEach(function (ctx) {
2568
+ extend(ctx.rule, rule);
2569
+ });
2526
2570
  },
2527
2571
  updateRules: function updateRules(rules) {
2528
2572
  Object.keys(rules).forEach(function (id) {
@@ -2530,8 +2574,9 @@
2530
2574
  });
2531
2575
  },
2532
2576
  mergeRule: function mergeRule$1(id, rule) {
2533
- var ctx = h.getCtx(id);
2534
- ctx && mergeRule(ctx.rule, rule);
2577
+ h.getCtxs(id).forEach(function (ctx) {
2578
+ mergeRule(ctx.rule, rule);
2579
+ });
2535
2580
  },
2536
2581
  mergeRules: function mergeRules(rules) {
2537
2582
  Object.keys(rules).forEach(function (id) {
@@ -2564,13 +2609,12 @@
2564
2609
  api.refresh();
2565
2610
  },
2566
2611
  resetFields: function resetFields(fields) {
2567
- var ctxs = h.fieldCtx;
2568
2612
  tidyFields(fields).forEach(function (field) {
2569
- var ctx = ctxs[field];
2570
- if (!ctx) return;
2571
- h.$render.clearCache(ctx);
2572
- ctx.rule.value = copy(ctx.defaultValue);
2573
- h.refreshControl(ctx);
2613
+ h.getCtxs(field).forEach(function (ctx) {
2614
+ h.$render.clearCache(ctx);
2615
+ ctx.rule.value = copy(ctx.defaultValue);
2616
+ h.refreshControl(ctx);
2617
+ });
2574
2618
  });
2575
2619
  },
2576
2620
  method: function method(id, name) {
@@ -2610,7 +2654,8 @@
2610
2654
  el && el.$emit && el.$emit('close-modal');
2611
2655
  },
2612
2656
  getSubForm: function getSubForm(field) {
2613
- return h.subForm[field];
2657
+ var ctx = h.getCtx(field);
2658
+ return ctx ? h.subForm[ctx.id] : undefined;
2614
2659
  },
2615
2660
  nextTick: function nextTick(fn) {
2616
2661
  h.bus.$once('next-tick', fn);
@@ -2619,13 +2664,26 @@
2619
2664
  nextRefresh: function nextRefresh(fn) {
2620
2665
  h.nextRefresh();
2621
2666
  fn && invoke(fn);
2667
+ },
2668
+ emit: function emit(name) {
2669
+ var _h$vm;
2670
+
2671
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2672
+ args[_key3 - 1] = arguments[_key3];
2673
+ }
2674
+
2675
+ (_h$vm = h.vm).$emit.apply(_h$vm, [name].concat(args));
2676
+ },
2677
+ helper: {
2678
+ tidyFields: tidyFields,
2679
+ props: props
2622
2680
  }
2623
2681
  };
2624
2682
  ['on', 'once', 'off', 'set'].forEach(function (n) {
2625
2683
  api[n] = function () {
2626
- var _h$vm;
2684
+ var _h$vm2;
2627
2685
 
2628
- (_h$vm = h.vm)["$".concat(n)].apply(_h$vm, arguments);
2686
+ (_h$vm2 = h.vm)["$".concat(n)].apply(_h$vm2, arguments);
2629
2687
  };
2630
2688
  });
2631
2689
  api.changeValue = api.changeField = api.setValue;
@@ -2749,7 +2807,7 @@
2749
2807
 
2750
2808
  var vm = rule.vm;
2751
2809
  if (!vm) return new _vue();else if (is.Function(vm)) return invoke(function () {
2752
- return vm(_this3.$handle.getInjectData(rule));
2810
+ return rule.vm(_this3.$handle.getInjectData(rule));
2753
2811
  });else if (!vm._isVue) return new _vue(vm);
2754
2812
  return vm;
2755
2813
  },
@@ -2765,6 +2823,14 @@
2765
2823
  deepSet(ctx.prop, ctx.prop.optionsTo, ctx.prop.options);
2766
2824
  }
2767
2825
  },
2826
+ deepSet: function deepSet$1(ctx) {
2827
+ var deep = ctx.rule.deep;
2828
+ deep && Object.keys(deep).sort(function (a, b) {
2829
+ return a.length < b.length ? -1 : 1;
2830
+ }).forEach(function (str) {
2831
+ deepSet(ctx.prop, str, deep[str]);
2832
+ });
2833
+ },
2768
2834
  setTempProps: function setTempProps(vm, ctx) {
2769
2835
  if (!vm.$props) return;
2770
2836
  var prop = ctx.prop;
@@ -2832,12 +2898,17 @@
2832
2898
  return ctx.rule.slot === slot ? this.renderCtx(ctx) : undefined;
2833
2899
  },
2834
2900
  renderId: function renderId(name, type) {
2835
- var ctx = this.$handle[type === 'field' ? 'nameCtx' : 'fieldCtx'][name];
2836
- return ctx ? this.renderCtx(ctx, ctx.parent) : undefined;
2901
+ var _this5 = this;
2902
+
2903
+ var ctxs = this.$handle[type === 'field' ? 'fieldCtx' : 'nameCtx'][name];
2904
+ return ctxs ? ctxs.map(function (ctx) {
2905
+ return _this5.renderCtx(ctx, ctx.parent);
2906
+ }) : undefined;
2837
2907
  },
2838
2908
  renderCtx: function renderCtx(ctx, parent) {
2839
2909
  if (ctx.type === 'hidden') return;
2840
2910
  var rule = ctx.rule;
2911
+ var preview = this.options.preview || false;
2841
2912
 
2842
2913
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2843
2914
  var vn;
@@ -2859,6 +2930,7 @@
2859
2930
  ctx.initProp();
2860
2931
  this.mergeGlobal(ctx);
2861
2932
  this.$manager.tidyRule(ctx);
2933
+ this.deepSet(ctx);
2862
2934
  this.setOptions(ctx);
2863
2935
  this.ctxProp(ctx);
2864
2936
  var prop = ctx.prop;
@@ -2887,11 +2959,13 @@
2887
2959
  vn = this.vm.$scopedSlots[slot]({
2888
2960
  rule: rule,
2889
2961
  prop: prop,
2962
+ preview: preview,
2890
2963
  children: children,
2964
+ api: this.$handle.api,
2891
2965
  model: prop.model || {}
2892
2966
  });
2893
2967
  } else {
2894
- vn = ctx.parser.render(children, ctx);
2968
+ vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
2895
2969
  }
2896
2970
  }
2897
2971
 
@@ -2918,13 +2992,13 @@
2918
2992
  return this.getCache(ctx);
2919
2993
  },
2920
2994
  display: function display(vn) {
2921
- var _this5 = this;
2995
+ var _this6 = this;
2922
2996
 
2923
2997
  if (Array.isArray(vn)) {
2924
2998
  var data = [];
2925
2999
  vn.forEach(function (v) {
2926
- if (Array.isArray(v)) return _this5.display(v);
2927
- if (_this5.none(v)) data.push(v);
3000
+ if (Array.isArray(v)) return _this6.display(v);
3001
+ if (_this6.none(v)) data.push(v);
2928
3002
  });
2929
3003
  return data;
2930
3004
  } else {
@@ -2953,22 +3027,29 @@
2953
3027
  }, [vn]);
2954
3028
  },
2955
3029
  injectProp: function injectProp(ctx) {
2956
- var _this6 = this;
3030
+ var _this7 = this;
2957
3031
 
2958
3032
  if (!this.vm.ctxInject[ctx.id]) {
2959
- $set(this.vm.ctxInject, ctx.id, {});
3033
+ $set(this.vm.ctxInject, ctx.id, {
3034
+ api: this.$handle.api,
3035
+ form: this.fc.create,
3036
+ subForm: function subForm(_subForm) {
3037
+ _this7.$handle.addSubForm(ctx, _subForm);
3038
+ },
3039
+ options: [],
3040
+ children: [],
3041
+ prop: {},
3042
+ preview: false,
3043
+ field: ctx.field,
3044
+ rule: ctx.rule
3045
+ });
2960
3046
  }
2961
3047
 
2962
- extend(this.vm.ctxInject[ctx.id], {
2963
- api: this.$handle.api,
2964
- form: this.fc.create,
2965
- subForm: function subForm(_subForm) {
2966
- _this6.$handle.addSubForm(ctx, _subForm);
2967
- },
2968
- field: ctx.field,
3048
+ var inject = this.vm.ctxInject[ctx.id];
3049
+ extend(inject, {
3050
+ preview: this.options.preview || false,
2969
3051
  options: ctx.prop.options,
2970
3052
  children: ctx.rule.children,
2971
- rule: ctx.rule,
2972
3053
  prop: function () {
2973
3054
  var temp = _objectSpread2({}, ctx.prop);
2974
3055
 
@@ -2977,10 +3058,10 @@
2977
3058
  return temp;
2978
3059
  }()
2979
3060
  });
2980
- return this.vm.ctxInject[ctx.id];
3061
+ return inject;
2981
3062
  },
2982
3063
  ctxProp: function ctxProp(ctx, custom) {
2983
- var _this7 = this;
3064
+ var _this8 = this;
2984
3065
 
2985
3066
  var ref = ctx.ref,
2986
3067
  key = ctx.key,
@@ -2993,7 +3074,10 @@
2993
3074
  slot: undefined,
2994
3075
  on: {
2995
3076
  'hook:mounted': function hookMounted() {
2996
- _this7.onMounted(ctx);
3077
+ _this8.onMounted(ctx);
3078
+ },
3079
+ 'fc.sub-form': function fcSubForm(subForm) {
3080
+ _this8.$handle.addSubForm(ctx, subForm);
2997
3081
  }
2998
3082
  }
2999
3083
  }];
@@ -3003,9 +3087,9 @@
3003
3087
  model: {
3004
3088
  value: this.$handle.getFormData(ctx),
3005
3089
  callback: function callback(value) {
3006
- _this7.onInput(ctx, value);
3090
+ _this8.onInput(ctx, value);
3007
3091
  },
3008
- expression: "formData.".concat(ctx.field)
3092
+ expression: "formData.".concat(ctx.id)
3009
3093
  }
3010
3094
  });
3011
3095
  }
@@ -3027,13 +3111,13 @@
3027
3111
  this.$handle.onInput(ctx, value);
3028
3112
  },
3029
3113
  renderChildren: function renderChildren(ctx) {
3030
- var _this8 = this;
3114
+ var _this9 = this;
3031
3115
 
3032
3116
  var children = ctx.rule.children,
3033
3117
  orgChildren = this.orgChildren[ctx.id];
3034
3118
 
3035
3119
  var isRm = function isRm(child) {
3036
- return !is.String(child) && child.__fc__ && !_this8.$handle.ctxs[child.__fc__.id];
3120
+ return !is.String(child) && child.__fc__ && !_this9.$handle.ctxs[child.__fc__.id];
3037
3121
  };
3038
3122
 
3039
3123
  if (!is.trueArray(children) && orgChildren) {
@@ -3042,7 +3126,7 @@
3042
3126
  if (!child) return;
3043
3127
 
3044
3128
  if (isRm(child)) {
3045
- _this8.$handle.rmCtx(child.__fc__);
3129
+ _this9.$handle.rmCtx(child.__fc__);
3046
3130
  }
3047
3131
  });
3048
3132
  });
@@ -3055,7 +3139,7 @@
3055
3139
  if (!child) return;
3056
3140
 
3057
3141
  if (children.indexOf(child) === -1 && isRm(child)) {
3058
- _this8.$handle.rmCtx(child.__fc__);
3142
+ _this9.$handle.rmCtx(child.__fc__);
3059
3143
  }
3060
3144
  });
3061
3145
  });
@@ -3064,14 +3148,14 @@
3064
3148
  if (is.String(child)) return child;
3065
3149
 
3066
3150
  if (child.__fc__) {
3067
- return _this8.renderCtx(child.__fc__, ctx);
3151
+ return _this9.renderCtx(child.__fc__, ctx);
3068
3152
  }
3069
3153
 
3070
- if (!_this8.$handle.isRepeatRule(child.__origin__ || child) && child.type) {
3071
- _this8.vm.$nextTick(function () {
3072
- _this8.$handle.loadChildren(children, ctx);
3154
+ if (child.type) {
3155
+ _this9.vm.$nextTick(function () {
3156
+ _this9.$handle.loadChildren(children, ctx);
3073
3157
 
3074
- _this8.$handle.refresh();
3158
+ _this9.$handle.refresh();
3075
3159
  });
3076
3160
  }
3077
3161
  });
@@ -3083,7 +3167,7 @@
3083
3167
  return this.vNode.make(lower(ctx.originType), prop, children);
3084
3168
  },
3085
3169
  renderRule: function renderRule(rule, children, origin) {
3086
- var _this9 = this;
3170
+ var _this10 = this;
3087
3171
 
3088
3172
  if (!rule) return undefined;
3089
3173
  if (is.String(rule)) return rule;
@@ -3106,7 +3190,7 @@
3106
3190
 
3107
3191
  if (is.trueArray(rule.children)) {
3108
3192
  data.push(rule.children.map(function (v) {
3109
- return _this9.renderRule(v);
3193
+ return _this10.renderRule(v);
3110
3194
  }));
3111
3195
  }
3112
3196
 
@@ -3140,7 +3224,6 @@
3140
3224
  function useInject(Handler) {
3141
3225
  extend(Handler.prototype, {
3142
3226
  parseInjectEvent: function parseInjectEvent(rule, on) {
3143
- if (rule.inject === false) return;
3144
3227
  var inject = rule.inject || this.options.injectEvent;
3145
3228
  return this.parseEventLst(rule, on, inject);
3146
3229
  },
@@ -3157,13 +3240,16 @@
3157
3240
  return data;
3158
3241
  },
3159
3242
  parseEvent: function parseEvent(rule, fn, inject, deep) {
3160
- if (is.Function(fn) && (!is.Undef(inject) || fn.__inject)) {
3243
+ if (is.Function(fn) && (inject !== false && !is.Undef(inject) || fn.__inject)) {
3161
3244
  return this.inject(rule, fn, inject);
3162
3245
  } else if (!deep && Array.isArray(fn) && fn[0] && (is.String(fn[0]) || is.Function(fn[0]))) {
3163
3246
  return this.parseEventLst(rule, fn, inject, true);
3164
3247
  } else if (is.String(fn)) {
3165
3248
  var val = parseFn(fn);
3166
- return is.String(val) ? val : this.parseEvent(rule, val, inject, true);
3249
+
3250
+ if (val && fn !== val) {
3251
+ return val.__inject ? this.parseEvent(rule, val, inject, true) : val;
3252
+ }
3167
3253
  }
3168
3254
  },
3169
3255
  parseEmit: function parseEmit(ctx, on) {
@@ -3226,6 +3312,7 @@
3226
3312
  option = _this$vm$$options$pro.option,
3227
3313
  rule = _this$vm$$options$pro.rule;
3228
3314
  return {
3315
+ api: this.api,
3229
3316
  $f: this.api,
3230
3317
  rule: rule,
3231
3318
  self: self.__origin__,
@@ -3483,7 +3570,7 @@
3483
3570
  extend(_this2, {
3484
3571
  root: []
3485
3572
  });
3486
- });
3573
+ }, _this2.input);
3487
3574
  });
3488
3575
  },
3489
3576
  update: function update(handle, init) {
@@ -3541,7 +3628,7 @@
3541
3628
  loadFn: function loadFn(item, rule) {
3542
3629
  var _this3 = this;
3543
3630
 
3544
- ['on', 'props', 'nativeOn'].forEach(function (k) {
3631
+ ['on', 'props', 'nativeOn', 'deep'].forEach(function (k) {
3545
3632
  item[k] && _this3.parseInjectEvent(rule, item[k]);
3546
3633
  });
3547
3634
  },
@@ -3568,9 +3655,6 @@
3568
3655
  }, {})
3569
3656
  }], ctx.computed);
3570
3657
  },
3571
- isRepeatRule: function isRepeatRule(rule) {
3572
- return this.repeatRule.indexOf(rule) > -1;
3573
- },
3574
3658
  loadRule: function loadRule() {
3575
3659
  var _this5 = this;
3576
3660
 
@@ -3654,7 +3738,7 @@
3654
3738
  var rule = getRule(_rule);
3655
3739
 
3656
3740
  var isRepeat = function isRepeat() {
3657
- return !!(rule.field && _this6.fieldCtx[rule.field] && _this6.fieldCtx[rule.field] !== _rule.__fc__);
3741
+ return !!(rule.field && _this6.fieldCtx[rule.field] && _this6.fieldCtx[rule.field][0] !== _rule.__fc__);
3658
3742
  };
3659
3743
 
3660
3744
  _this6.ruleEffect(rule, 'init', {
@@ -3662,11 +3746,7 @@
3662
3746
  });
3663
3747
 
3664
3748
  if (isRepeat()) {
3665
- _this6.repeatRule.push(_rule);
3666
-
3667
3749
  _this6.vm.$emit('repeat-field', _rule, _this6.api);
3668
-
3669
- return err("".concat(rule.field, " \u5B57\u6BB5\u5DF2\u5B58\u5728"), _rule);
3670
3750
  }
3671
3751
 
3672
3752
  var ctx;
@@ -3772,14 +3852,17 @@
3772
3852
  return val === control.value;
3773
3853
  };
3774
3854
 
3855
+ if (!is.trueArray(control.rule)) return "continue";
3856
+
3775
3857
  var data = _objectSpread2(_objectSpread2({}, control), {}, {
3776
3858
  valid: invoke(function () {
3777
3859
  return handleFn(ctx.rule.value, api);
3778
3860
  }),
3779
- ctrl: findCtrl(ctx, control.rule)
3861
+ ctrl: findCtrl(ctx, control.rule),
3862
+ isHidden: is.String(control.rule[0])
3780
3863
  });
3781
3864
 
3782
- if (data.valid && data.ctrl || !data.valid && !data.ctrl) return "continue";
3865
+ if (data.valid && data.ctrl || !data.valid && !data.ctrl && !data.isHidden) return "continue";
3783
3866
  validate.push(data);
3784
3867
  };
3785
3868
 
@@ -3791,53 +3874,56 @@
3791
3874
 
3792
3875
  if (!validate.length) return false;
3793
3876
  var flag = false;
3794
- validate.reverse().forEach(function (_ref) {
3795
- var valid = _ref.valid,
3796
- rule = _ref.rule,
3797
- prepend = _ref.prepend,
3798
- append = _ref.append,
3799
- child = _ref.child,
3800
- ctrl = _ref.ctrl;
3801
-
3802
- if (is.String(rule[0])) {
3803
- valid ? ctx.ctrlRule.push({
3804
- __ctrl: true,
3805
- children: rule,
3806
- valid: valid
3807
- }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3808
-
3809
- _this7.vm.$nextTick(function () {
3810
- _this7.api.hidden(!valid, rule);
3811
- });
3877
+ this.deferSyncValue(function () {
3878
+ validate.reverse().forEach(function (_ref) {
3879
+ var isHidden = _ref.isHidden,
3880
+ valid = _ref.valid,
3881
+ rule = _ref.rule,
3882
+ prepend = _ref.prepend,
3883
+ append = _ref.append,
3884
+ child = _ref.child,
3885
+ ctrl = _ref.ctrl;
3886
+
3887
+ if (isHidden) {
3888
+ valid ? ctx.ctrlRule.push({
3889
+ __ctrl: true,
3890
+ children: rule,
3891
+ valid: valid
3892
+ }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3893
+
3894
+ _this7.vm.$nextTick(function () {
3895
+ _this7.api.hidden(!valid, rule);
3896
+ });
3812
3897
 
3813
- return;
3814
- }
3898
+ return;
3899
+ }
3815
3900
 
3816
- if (valid) {
3817
- flag = true;
3818
- var ruleCon = {
3819
- type: 'fcFragment',
3820
- "native": true,
3821
- __ctrl: true,
3822
- children: rule
3823
- };
3824
- ctx.ctrlRule.push(ruleCon);
3825
-
3826
- _this7.bus.$once('load-start', function () {
3827
- // this.cycleLoad = true;
3828
- if (prepend) {
3829
- api.prepend(ruleCon, prepend, child);
3830
- } else if (append || child) {
3831
- api.append(ruleCon, append || ctx.id, child);
3832
- } else {
3833
- ctx.root.splice(ctx.root.indexOf(ctx.origin) + 1, 0, ruleCon);
3834
- }
3835
- });
3836
- } else {
3837
- ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3838
- var ctrlCtx = byCtx(ctrl);
3839
- ctrlCtx && ctrlCtx.rm();
3840
- }
3901
+ if (valid) {
3902
+ flag = true;
3903
+ var ruleCon = {
3904
+ type: 'fcFragment',
3905
+ "native": true,
3906
+ __ctrl: true,
3907
+ children: rule
3908
+ };
3909
+ ctx.ctrlRule.push(ruleCon);
3910
+
3911
+ _this7.bus.$once('load-start', function () {
3912
+ // this.cycleLoad = true;
3913
+ if (prepend) {
3914
+ api.prepend(ruleCon, prepend, child);
3915
+ } else if (append || child) {
3916
+ api.append(ruleCon, append || ctx.id, child);
3917
+ } else {
3918
+ ctx.root.splice(ctx.root.indexOf(ctx.origin) + 1, 0, ruleCon);
3919
+ }
3920
+ });
3921
+ } else {
3922
+ ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3923
+ var ctrlCtx = byCtx(ctrl);
3924
+ ctrlCtx && ctrlCtx.rm();
3925
+ }
3926
+ });
3841
3927
  });
3842
3928
  this.vm.$emit('control', ctx.origin, this.api);
3843
3929
  this.effect(ctx, 'control');
@@ -3873,6 +3959,7 @@
3873
3959
  this.refresh();
3874
3960
  this.bus.$off('next-tick', this.nextReload);
3875
3961
  this.bus.$once('next-tick', this.nextReload);
3962
+ this.vm.$emit('update', this.api);
3876
3963
  },
3877
3964
  //todo 组件生成全部通过 alias
3878
3965
  refresh: function refresh() {
@@ -3908,7 +3995,7 @@
3908
3995
  function useInput(Handler) {
3909
3996
  extend(Handler.prototype, {
3910
3997
  getValue: function getValue(ctx) {
3911
- if (!hasProperty(ctx, 'cacheValue')) {
3998
+ if (is.Undef(ctx.cacheValue)) {
3912
3999
  ctx.cacheValue = ctx.parser.toValue(this.getFormData(ctx), ctx);
3913
4000
  }
3914
4001
 
@@ -3934,18 +4021,19 @@
3934
4021
  }
3935
4022
  },
3936
4023
  setFormData: function setFormData(ctx, value) {
3937
- $set(this.formData, ctx.field, value);
4024
+ $set(this.formData, ctx.id, value);
3938
4025
  },
3939
4026
  getFormData: function getFormData(ctx) {
3940
- return this.formData[ctx.field];
4027
+ return this.formData[ctx.id];
3941
4028
  },
3942
4029
  validate: function validate() {
3943
4030
  var _this = this;
3944
4031
 
3945
4032
  toEmpty(this.vm.validate);
3946
- Object.keys(this.fieldCtx).forEach(function (id) {
3947
- var ctx = _this.fieldCtx[id];
3948
- _this.vm.validate[ctx.field] = toArray(ctx.rule.validate);
4033
+ this.fields().forEach(function (id) {
4034
+ _this.fieldCtx[id].forEach(function (ctx) {
4035
+ _this.vm.validate[ctx.id] = toArray(ctx.rule.validate);
4036
+ });
3949
4037
  });
3950
4038
  return this.vm.validate;
3951
4039
  },
@@ -3953,8 +4041,8 @@
3953
4041
  var _this2 = this;
3954
4042
 
3955
4043
  toEmpty(this.form);
3956
- Object.defineProperties(this.form, Object.keys(this.formData).reduce(function (initial, field) {
3957
- var ctx = _this2.getCtx(field);
4044
+ Object.defineProperties(this.form, this.fields().reduce(function (initial, field) {
4045
+ var ctx = _this2.getFieldCtx(field);
3958
4046
 
3959
4047
  var handle = _this2.valueHandle(ctx);
3960
4048
 
@@ -3998,14 +4086,18 @@
3998
4086
  },
3999
4087
  addSubForm: function addSubForm(ctx, subForm) {
4000
4088
  if (ctx.input) {
4001
- this.subForm[ctx.field] = subForm;
4089
+ this.subForm[ctx.id] = subForm;
4002
4090
  }
4003
4091
  },
4004
- deferSyncValue: function deferSyncValue(fn) {
4092
+ deferSyncValue: function deferSyncValue(fn, sync) {
4005
4093
  if (!this.deferSyncFn) {
4006
4094
  this.deferSyncFn = fn;
4007
4095
  }
4008
4096
 
4097
+ if (!this.deferSyncFn.sync) {
4098
+ this.deferSyncFn.sync = sync;
4099
+ }
4100
+
4009
4101
  invoke(fn);
4010
4102
 
4011
4103
  if (this.deferSyncFn === fn) {
@@ -4032,11 +4124,9 @@
4032
4124
  refreshUpdate: function refreshUpdate(ctx, val) {
4033
4125
  var _this4 = this;
4034
4126
 
4035
- var fn = ctx.rule.update;
4036
-
4037
- if (is.Function(fn)) {
4127
+ if (is.Function(ctx.rule.update)) {
4038
4128
  var state = invoke(function () {
4039
- return fn(val, ctx.origin, _this4.api);
4129
+ return ctx.rule.update(val, ctx.origin, _this4.api);
4040
4130
  });
4041
4131
  if (state === undefined) return;
4042
4132
  ctx.rule.hidden = state === true;
@@ -4050,6 +4140,7 @@
4050
4140
  if (this.refreshControl(ctx)) {
4051
4141
  this.$render.clearCacheAll();
4052
4142
  this.loadRule();
4143
+ this.vm.$emit('update', this.api);
4053
4144
  this.refresh();
4054
4145
  }
4055
4146
 
@@ -4072,7 +4163,7 @@
4072
4163
  });
4073
4164
  },
4074
4165
  fields: function fields() {
4075
- return Object.keys(this.formData);
4166
+ return Object.keys(this.fieldCtx);
4076
4167
  }
4077
4168
  });
4078
4169
  }
@@ -4083,49 +4174,6 @@
4083
4174
  });
4084
4175
  }
4085
4176
 
4086
- function useHelper(rules) {
4087
- if (!Array.isArray(rules) || rules.findField) return;
4088
- Object.defineProperties(rules, {
4089
- findField: enumerable(findField),
4090
- findName: enumerable(findName),
4091
- setValue: enumerable(setValue)
4092
- });
4093
- }
4094
-
4095
- function find(field, name, origin) {
4096
- if (!this.length) return;
4097
- var children = [];
4098
-
4099
- for (var i = 0; i < this.length; i++) {
4100
- if (!is.Object(this[i])) continue;
4101
- var rule = getRule(this[i]);
4102
- if (rule[name] === field) return origin ? rule : this[i];
4103
- if (is.trueArray(rule.children)) children = children.concat(rule.children);
4104
- is.trueArray(rule.control) && rule.control.forEach(function (r) {
4105
- children = children.concat(r.rule);
4106
- });
4107
- }
4108
-
4109
- return find.call(children, field, name, origin);
4110
- }
4111
-
4112
- function findField(field) {
4113
- return find.call(this, field, 'field');
4114
- }
4115
-
4116
- function findName(field) {
4117
- return find.call(this, field, 'name');
4118
- }
4119
-
4120
- function setValue(formData) {
4121
- var _this = this;
4122
-
4123
- Object.keys(formData).forEach(function (field) {
4124
- var rule = find.call(_this, field, 'field', true);
4125
- if (rule) rule.value = formData[field];
4126
- });
4127
- }
4128
-
4129
4177
  var BaseParser = {
4130
4178
  init: function init(ctx) {},
4131
4179
  toFormValue: function toFormValue(value, ctx) {
@@ -4138,13 +4186,46 @@
4138
4186
  render: function render(children, ctx) {
4139
4187
  return ctx.$render.defaultRender(ctx, children);
4140
4188
  },
4189
+ preview: function preview(children, ctx) {
4190
+ return ctx.$render.defaultRender(ctx, children);
4191
+ },
4141
4192
  mergeProp: function mergeProp(ctx) {}
4142
4193
  };
4143
4194
 
4144
4195
  function useContext(Handler) {
4145
4196
  extend(Handler.prototype, {
4146
4197
  getCtx: function getCtx(id) {
4147
- return this.fieldCtx[id] || this.nameCtx[id] || this.ctxs[id];
4198
+ return this.getFieldCtx(id) || this.getNameCtx(id)[0] || this.ctxs[id];
4199
+ },
4200
+ getCtxs: function getCtxs(id) {
4201
+ return this.fieldCtx[id] || this.nameCtx[id] || (this.ctxs[id] ? [this.ctxs[id]] : []);
4202
+ },
4203
+ setIdCtx: function setIdCtx(ctx, key, type) {
4204
+ var field = "".concat(type, "Ctx");
4205
+
4206
+ if (!this[field][key]) {
4207
+ this[field][key] = [ctx];
4208
+ } else {
4209
+ this[field][key].push(ctx);
4210
+ }
4211
+ },
4212
+ rmIdCtx: function rmIdCtx(ctx, key, type) {
4213
+ var field = "".concat(type, "Ctx");
4214
+ var lst = this[field][key];
4215
+ if (!lst) return false;
4216
+ var flag = lst.splice(lst.indexOf(ctx) >>> 0, 1).length > 0;
4217
+
4218
+ if (!lst.length) {
4219
+ delete this[field][key];
4220
+ }
4221
+
4222
+ return flag;
4223
+ },
4224
+ getFieldCtx: function getFieldCtx(field) {
4225
+ return (this.fieldCtx[field] || [])[0];
4226
+ },
4227
+ getNameCtx: function getNameCtx(name) {
4228
+ return this.nameCtx[name] || [];
4148
4229
  },
4149
4230
  setCtx: function setCtx(ctx) {
4150
4231
  var id = ctx.id,
@@ -4152,9 +4233,9 @@
4152
4233
  name = ctx.name,
4153
4234
  rule = ctx.rule;
4154
4235
  this.ctxs[id] = ctx;
4155
- if (name) $set(this.nameCtx, name, ctx);
4236
+ name && this.setIdCtx(ctx, name, 'name');
4156
4237
  if (!ctx.input) return;
4157
- this.fieldCtx[field] = ctx;
4238
+ this.setIdCtx(ctx, field, 'field');
4158
4239
  this.setFormData(ctx, ctx.parser.toFormValue(rule.value, ctx));
4159
4240
 
4160
4241
  if (this.isMounted && !this.reloading) {
@@ -4213,7 +4294,7 @@
4213
4294
  if (key === 'link') {
4214
4295
  ctx.link();
4215
4296
  return;
4216
- } else if (['props', 'on', 'nativeOn'].indexOf(key) > -1) {
4297
+ } else if (['props', 'on', 'nativeOn', 'deep'].indexOf(key) > -1) {
4217
4298
  _this.parseInjectEvent(ctx.rule, n || {});
4218
4299
 
4219
4300
  if (key === 'props' && ctx.input) {
@@ -4234,6 +4315,8 @@
4234
4315
  }
4235
4316
 
4236
4317
  _flag && _this.loadChildren(n, ctx);
4318
+
4319
+ _this.vm.$emit('update', _this.api);
4237
4320
  });
4238
4321
  }
4239
4322
 
@@ -4260,6 +4343,7 @@
4260
4343
  if (ctx.deleted) return;
4261
4344
  var id = ctx.id,
4262
4345
  field = ctx.field,
4346
+ input = ctx.input,
4263
4347
  name = ctx.name;
4264
4348
 
4265
4349
  if (ctx.input) {
@@ -4273,40 +4357,26 @@
4273
4357
  $del(this.$render.tempList, id);
4274
4358
  $del(this.$render.orgChildren, id);
4275
4359
  $del(this.vm.ctxInject, id);
4360
+ $del(this.formData, id);
4361
+ $del(this.subForm, id);
4276
4362
  $del(ctx, 'cacheValue');
4277
- var f = this.fieldCtx[field];
4278
- var flag = false;
4279
-
4280
- if (field && (!f || f === ctx)) {
4281
- $del(this.formData, field);
4282
- $del(this.form, field);
4283
- $del(this.fieldCtx, field);
4284
- $del(this.subForm, field);
4285
- flag = true;
4286
- }
4287
-
4288
- if (name && this.nameCtx[name] === ctx) {
4289
- $del(this.nameCtx, name);
4290
- }
4291
-
4292
- if (!this.reloading) {
4293
- if (ctx.parser.loadChildren !== false) {
4294
- this.deferSyncValue(function () {
4363
+ input && this.rmIdCtx(ctx, field, 'field');
4364
+ name && this.rmIdCtx(ctx, name, 'name');
4365
+ this.deferSyncValue(function () {
4366
+ if (!_this3.reloading) {
4367
+ if (ctx.parser.loadChildren !== false) {
4295
4368
  if (is.trueArray(ctx.rule.children)) {
4296
4369
  ctx.rule.children.forEach(function (h) {
4297
4370
  return h.__fc__ && _this3.rmCtx(h.__fc__);
4298
4371
  });
4299
4372
  }
4373
+ }
4300
4374
 
4301
- _this3.syncValue();
4302
- });
4303
- }
4304
-
4305
- if (ctx.root === this.rules) {
4306
- this.vm._renderRule();
4375
+ if (ctx.root === _this3.rules) {
4376
+ _this3.vm._renderRule();
4377
+ }
4307
4378
  }
4308
- }
4309
-
4379
+ }, input);
4310
4380
  var index = this.sort.indexOf(id);
4311
4381
 
4312
4382
  if (index > -1) {
@@ -4316,7 +4386,7 @@
4316
4386
  this.$render.clearCache(ctx);
4317
4387
  ctx["delete"]();
4318
4388
  this.effect(ctx, 'deleted');
4319
- flag && this.vm.$emit('removeField', field, ctx.rule, this.api);
4389
+ input && !this.fieldCtx[field] && this.vm.$emit('removeField', field, ctx.rule, this.api);
4320
4390
  ctx.rule.__ctrl || this.vm.$emit('removeRule', ctx.rule, this.api);
4321
4391
  return ctx;
4322
4392
  }
@@ -4521,14 +4591,12 @@
4521
4591
  extend(Handler.prototype, {
4522
4592
  initData: function initData(rules) {
4523
4593
  extend(this, {
4524
- fieldCtx: {},
4525
4594
  ctxs: {},
4595
+ fieldCtx: {},
4526
4596
  nameCtx: {},
4527
4597
  sort: [],
4528
- rules: rules,
4529
- repeatRule: []
4598
+ rules: rules
4530
4599
  });
4531
- useHelper(rules);
4532
4600
  },
4533
4601
  init: function init() {
4534
4602
  this.appendData = _objectSpread2(_objectSpread2(_objectSpread2({}, this.fc.options.formData || {}), this.vm.value || {}), this.appendData);
@@ -4784,6 +4852,11 @@
4784
4852
 
4785
4853
  function run(inject, rule, api) {
4786
4854
  var option = inject.value;
4855
+
4856
+ if (is.Function(option)) {
4857
+ option = option(rule, api);
4858
+ }
4859
+
4787
4860
  option = parseOpt(option);
4788
4861
 
4789
4862
  if (!option || !option.action) {
@@ -4894,9 +4967,7 @@
4894
4967
 
4895
4968
 
4896
4969
  function FormCreateFactory(config) {
4897
- var _fragment = _vue.extend(fragment);
4898
-
4899
- var components = _defineProperty({}, fragment.name, _fragment);
4970
+ var components = _defineProperty({}, fragment.name, fragment);
4900
4971
 
4901
4972
  var parsers = {};
4902
4973
  var directives = {};
@@ -4961,6 +5032,10 @@
4961
5032
 
4962
5033
  function $form() {
4963
5034
  return _vue.extend($FormCreate(FormCreate));
5035
+ }
5036
+
5037
+ function $vnode() {
5038
+ return _vue.extend(fragment);
4964
5039
  } //todo 检查回调函数作用域
4965
5040
 
4966
5041
 
@@ -5082,6 +5157,7 @@
5082
5157
  },
5083
5158
  created: function created() {
5084
5159
  this.$handle.init();
5160
+ this.vm.$emit('created', this.api());
5085
5161
  },
5086
5162
  api: function api() {
5087
5163
  return this.$handle.api;
@@ -5103,7 +5179,7 @@
5103
5179
  component: component,
5104
5180
  directive: directive,
5105
5181
  register: register,
5106
- fragment: _fragment,
5182
+ $vnode: $vnode,
5107
5183
  parser: parser,
5108
5184
  use: use,
5109
5185
  factory: factory,
@@ -5157,7 +5233,7 @@
5157
5233
  useAttr($formCreate);
5158
5234
  Vue.prototype.$formCreate = $formCreate;
5159
5235
  Vue.component('FormCreate', $form());
5160
- Vue.component('FcFragment', _fragment);
5236
+ Vue.component('FcFragment', $vnode());
5161
5237
  }
5162
5238
  });
5163
5239
  }
@@ -5530,7 +5606,7 @@
5530
5606
  props: _objectSpread2(_objectSpread2({
5531
5607
  labelWidth: labelWidth
5532
5608
  }, rule.wrap || {}), {}, {
5533
- prop: ctx.field,
5609
+ prop: ctx.id,
5534
5610
  rules: rule.validate
5535
5611
  }),
5536
5612
  "class": rule.className,
@@ -5546,34 +5622,12 @@
5546
5622
  return !(!title.title && !title["native"] || isFalse(title.show));
5547
5623
  },
5548
5624
  makeInfo: function makeInfo(rule, uni) {
5549
- var _this = this;
5550
5625
 
5551
5626
  var titleProp = rule.title;
5552
5627
  var infoProp = rule.info;
5553
5628
  var children = [titleProp.title];
5554
5629
 
5555
- var titleFn = function titleFn(pop) {
5556
- return _this.$r(mergeProps([titleProp, {
5557
- props: titleProp,
5558
- slot: titleProp.slot || (pop ? 'default' : 'label'),
5559
- key: "".concat(uni, "tit"),
5560
- type: titleProp.type || 'span'
5561
- }]), children);
5562
- };
5563
-
5564
- if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"])) {
5565
- if (infoProp.icon !== false) {
5566
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
5567
- type: 'icon',
5568
- props: {
5569
- type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon,
5570
- size: 16
5571
- },
5572
- style: 'margin-top: -1px',
5573
- key: "".concat(uni, "i")
5574
- }));
5575
- }
5576
-
5630
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5577
5631
  var prop = {
5578
5632
  type: infoProp.type || 'poptip',
5579
5633
  props: _objectSpread2({}, infoProp),
@@ -5586,10 +5640,23 @@
5586
5640
  prop.props[field] = infoProp.info;
5587
5641
  }
5588
5642
 
5589
- return this.$r(mergeProps([infoProp, prop]), [titleFn(true)]);
5643
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), [this.$r({
5644
+ type: 'icon',
5645
+ props: {
5646
+ type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon,
5647
+ size: 16
5648
+ },
5649
+ style: 'margin-top: -1px',
5650
+ key: "".concat(uni, "i")
5651
+ })]));
5590
5652
  }
5591
5653
 
5592
- return titleFn();
5654
+ return this.$r(mergeProps([titleProp, {
5655
+ props: titleProp,
5656
+ slot: titleProp.slot || 'label',
5657
+ key: "".concat(uni, "tit"),
5658
+ type: titleProp.type || 'span'
5659
+ }]), children);
5593
5660
  },
5594
5661
  makeCol: function makeCol(rule, uni, children) {
5595
5662
  var col = rule.col;
@@ -5841,13 +5908,14 @@
5841
5908
  }
5842
5909
  },
5843
5910
  validateField: function validateField(field, callback) {
5844
- if (!h.fieldCtx[field]) return;
5845
- var sub = h.subForm[field];
5911
+ var ctx = h.getFieldCtx(field);
5912
+ if (!ctx) return;
5913
+ var sub = h.subForm[ctx.id];
5846
5914
  var len = 0;
5847
5915
  var flag;
5848
5916
 
5849
5917
  var validate = function validate() {
5850
- h.$manager.validateField(field, function () {
5918
+ h.$manager.validateField(ctx.id, function () {
5851
5919
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
5852
5920
  args[_key3] = arguments[_key3];
5853
5921
  }
@@ -5897,23 +5965,25 @@
5897
5965
  var clearSub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
5898
5966
  api.helper.tidyFields(fields).forEach(function (field) {
5899
5967
  if (clearSub) _this.clearSubValidateState(field);
5900
- var ctx = h.fieldCtx[field];
5901
- if (!ctx) return;
5902
- h.$manager.clearValidateState(ctx);
5968
+ h.getCtxs(field).forEach(function (ctx) {
5969
+ h.$manager.clearValidateState(ctx);
5970
+ });
5903
5971
  });
5904
5972
  },
5905
5973
  clearSubValidateState: function clearSubValidateState(fields) {
5906
5974
  api.helper.tidyFields(fields).forEach(function (field) {
5907
- var subForm = h.subForm[field];
5908
- if (!subForm) return;
5975
+ h.getCtxs(field).forEach(function (ctx) {
5976
+ var subForm = h.subForm[ctx.id];
5977
+ if (!subForm) return;
5909
5978
 
5910
- if (Array.isArray(subForm)) {
5911
- subForm.forEach(function (form) {
5912
- form.clearValidateState();
5913
- });
5914
- } else if (subForm) {
5915
- subForm.clearValidateState();
5916
- }
5979
+ if (Array.isArray(subForm)) {
5980
+ subForm.forEach(function (form) {
5981
+ form.clearValidateState();
5982
+ });
5983
+ } else if (subForm) {
5984
+ subForm.clearValidateState();
5985
+ }
5986
+ });
5917
5987
  });
5918
5988
  },
5919
5989
  btn: {
@@ -6016,7 +6086,7 @@
6016
6086
  function ivuFormCreate() {
6017
6087
  return FormCreateFactory({
6018
6088
  ui: "".concat("iview"),
6019
- version: "".concat("2.5.10"),
6089
+ version: "".concat("2.5.14"),
6020
6090
  manager: manager,
6021
6091
  install: install,
6022
6092
  extendApi: extendApi,