@form-create/element-ui 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/element-ui v2.5.10
2
+ * @form-create/element-ui 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.
@@ -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
  }
@@ -278,8 +284,12 @@
278
284
  };
279
285
  },
280
286
  methods: {
287
+ options: function options() {
288
+ var opt = this.formCreateInject.options;
289
+ return Array.isArray(opt) ? opt : [];
290
+ },
281
291
  onInput: function onInput(n) {
282
- this.$emit('input', this.formCreateInject.options.filter(function (opt) {
292
+ this.$emit('input', this.options().filter(function (opt) {
283
293
  return n.indexOf(opt.label) !== -1;
284
294
  }).map(function (opt) {
285
295
  return opt.value;
@@ -290,7 +300,7 @@
290
300
  update: function update() {
291
301
  var _this = this;
292
302
 
293
- this.trueValue = this.value ? this.formCreateInject.options.filter(function (opt) {
303
+ this.trueValue = this.value ? this.options().filter(function (opt) {
294
304
  return _this.value.indexOf(opt.value) !== -1;
295
305
  }).map(function (option) {
296
306
  return option.label;
@@ -311,7 +321,7 @@
311
321
  "on": {
312
322
  "input": this.onInput
313
323
  }
314
- }]), [this.formCreateInject.options.map(function (opt, index) {
324
+ }]), [this.options().map(function (opt, index) {
315
325
  var props = _objectSpread2({}, opt);
316
326
 
317
327
  var Type = _this2.type === 'button' ? 'ElCheckboxButton' : 'ElCheckbox';
@@ -677,10 +687,6 @@
677
687
  })]);
678
688
  },
679
689
  handleClick: function handleClick(src) {
680
- if (this.disabled) {
681
- return;
682
- }
683
-
684
690
  return this.onHandle(src);
685
691
  },
686
692
  handleRemove: function handleRemove(src) {
@@ -859,6 +865,12 @@
859
865
  type: String
860
866
  },
861
867
  watch: {
868
+ 'formCreateInject.options': {
869
+ handler: function handler() {
870
+ this.update();
871
+ },
872
+ deep: true
873
+ },
862
874
  value: function value() {
863
875
  this.update();
864
876
  }
@@ -869,8 +881,12 @@
869
881
  };
870
882
  },
871
883
  methods: {
884
+ options: function options() {
885
+ var opt = this.formCreateInject.options;
886
+ return Array.isArray(opt) ? opt : [];
887
+ },
872
888
  onInput: function onInput(n) {
873
- this.$emit('input', this.formCreateInject.options.filter(function (opt) {
889
+ this.$emit('input', this.options().filter(function (opt) {
874
890
  return opt.label === n;
875
891
  }).reduce(function (initial, opt) {
876
892
  return opt.value;
@@ -879,7 +895,7 @@
879
895
  update: function update() {
880
896
  var _this = this;
881
897
 
882
- this.trueValue = this.formCreateInject.options.filter(function (opt) {
898
+ this.trueValue = this.options().filter(function (opt) {
883
899
  return opt.value === _this.value;
884
900
  }).reduce(function (initial, opt) {
885
901
  return opt.label;
@@ -900,7 +916,7 @@
900
916
  "on": {
901
917
  "input": this.onInput
902
918
  }
903
- }]), [this.formCreateInject.options.map(function (opt, index) {
919
+ }]), [this.options().map(function (opt, index) {
904
920
  var props = _objectSpread2({}, opt);
905
921
 
906
922
  var Type = _this2.type === 'button' ? 'ElRadioButton' : 'ElRadio';
@@ -947,7 +963,8 @@
947
963
  }
948
964
  },
949
965
  render: function render(h, ctx) {
950
- return h("ElSelect", helper([{}, ctx.data]), [ctx.props.formCreateInject.options.map(function (props, index) {
966
+ var options = ctx.props.formCreateInject.options;
967
+ return h("ElSelect", helper([{}, ctx.data]), [(Array.isArray(options) ? options : []).map(function (props, index) {
951
968
  var slot = props.slot;
952
969
  return h("ElOption", {
953
970
  "props": _objectSpread2({}, props),
@@ -1136,10 +1153,6 @@
1136
1153
  this.$refs.upload.handleRemove(file);
1137
1154
  },
1138
1155
  handleClick: function handleClick(file) {
1139
- if (this.isDisabled()) {
1140
- return;
1141
- }
1142
-
1143
1156
  this.onHandle(file);
1144
1157
  },
1145
1158
  makeItem: function makeItem(file, index) {
@@ -1358,7 +1371,8 @@
1358
1371
  return {
1359
1372
  len: 0,
1360
1373
  cacheRule: {},
1361
- cacheValue: {}
1374
+ cacheValue: {},
1375
+ type: undefined
1362
1376
  };
1363
1377
  },
1364
1378
  computed: {
@@ -1530,7 +1544,7 @@
1530
1544
  this.addRule(i, true);
1531
1545
  },
1532
1546
  del: function del(index, key) {
1533
- if (this.disabled || false === this.onBeforeRemove(this.value)) {
1547
+ if (this.disabled || false === this.onBeforeRemove(this.value, index)) {
1534
1548
  return;
1535
1549
  }
1536
1550
 
@@ -1599,6 +1613,7 @@
1599
1613
  }
1600
1614
  },
1601
1615
  created: function created() {
1616
+ this.type = this.formCreateInject.form.$form();
1602
1617
  var d = (this.expand || 0) - this.value.length;
1603
1618
 
1604
1619
  if (d > 0) {
@@ -1615,6 +1630,7 @@
1615
1630
  var h = arguments[0];
1616
1631
  var keys = Object.keys(this.cacheRule);
1617
1632
  var button = this.button;
1633
+ var Type = this.type;
1618
1634
  return keys.length === 0 ? this.$scopedSlots["default"] ? this.$scopedSlots["default"]({
1619
1635
  vm: this,
1620
1636
  add: this.add
@@ -1642,7 +1658,7 @@
1642
1658
  "attrs": {
1643
1659
  "span": button ? 20 : 24
1644
1660
  }
1645
- }, [h("ElFormItem", [h("FormCreate", helper([{
1661
+ }, [h("ElFormItem", [h(Type, helper([{
1646
1662
  "key": key
1647
1663
  }, {
1648
1664
  "on": {
@@ -1674,9 +1690,6 @@
1674
1690
  }
1675
1691
  }, [_this9.makeIcon(keys.length, index, key)]) : null]);
1676
1692
  })]);
1677
- },
1678
- beforeMount: function beforeMount() {
1679
- this.$options.components.FormCreate = this.formCreateInject.form.$form();
1680
1693
  }
1681
1694
  };
1682
1695
 
@@ -1708,7 +1721,8 @@
1708
1721
  data: function data() {
1709
1722
  return {
1710
1723
  cacheRule: {},
1711
- cacheValue: {}
1724
+ cacheValue: {},
1725
+ type: undefined
1712
1726
  };
1713
1727
  },
1714
1728
  watch: {
@@ -1770,13 +1784,15 @@
1770
1784
  },
1771
1785
  created: function created() {
1772
1786
  this.addRule();
1787
+ this.type = this.formCreateInject.form.$form();
1773
1788
  },
1774
1789
  render: function render() {
1775
1790
  var h = arguments[0];
1776
1791
  var _this$cacheRule = this.cacheRule,
1777
1792
  rule = _this$cacheRule.rule,
1778
1793
  options = _this$cacheRule.options;
1779
- return h("FormCreate", helper([{}, {
1794
+ var Type = this.type;
1795
+ return h(Type, helper([{}, {
1780
1796
  "on": {
1781
1797
  'update:value': this.formData,
1782
1798
  'emit-event': this.emitEvent,
@@ -1789,9 +1805,6 @@
1789
1805
  "extendOption": true
1790
1806
  }
1791
1807
  }]));
1792
- },
1793
- beforeMount: function beforeMount() {
1794
- this.$options.components.FormCreate = this.formCreateInject.form.$form();
1795
1808
  }
1796
1809
  };
1797
1810
 
@@ -1916,6 +1929,7 @@
1916
1929
  Object.keys(this.formCreate.prop).forEach(function (k) {
1917
1930
  extend(_this2.$options[k], _this2.formCreate.prop[k]);
1918
1931
  });
1932
+ this.$emit('beforeCreate', this.formCreate.api());
1919
1933
  }
1920
1934
  };
1921
1935
  }
@@ -1991,11 +2005,25 @@
1991
2005
 
1992
2006
  var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'nativeEmit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key'];
1993
2007
  var arrayAttrs = ['validate', 'children', 'control'];
1994
- var normalAttrs = ['effect'];
2008
+ var normalAttrs = ['effect', 'deep'];
1995
2009
  function attrs() {
1996
2010
  return [].concat(keyAttrs, _toConsumableArray(normalMerge$1), _toConsumableArray(toArrayMerge$1), _toConsumableArray(functionalMerge$1), arrayAttrs, normalAttrs);
1997
2011
  }
1998
2012
 
2013
+ function format(type, msg, rule) {
2014
+ return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2015
+ }
2016
+ function tip(msg, rule) {
2017
+ console.warn(format('tip', msg, rule));
2018
+ }
2019
+ function err(msg, rule) {
2020
+ console.error(format('err', msg, rule));
2021
+ }
2022
+ function logError(e) {
2023
+ err(e.toString());
2024
+ console.error(e);
2025
+ }
2026
+
1999
2027
  function deepExtend(origin) {
2000
2028
  var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2001
2029
  var mode = arguments.length > 2 ? arguments[2] : undefined;
@@ -2046,23 +2074,10 @@
2046
2074
  }).value;
2047
2075
  }
2048
2076
 
2049
- function format(type, msg, rule) {
2050
- return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2051
- }
2052
- function tip(msg, rule) {
2053
- console.warn(format('tip', msg, rule));
2054
- }
2055
- function err(msg, rule) {
2056
- console.error(format('err', msg, rule));
2057
- }
2058
- function logError(e) {
2059
- err(e.toString());
2060
- console.error(e);
2061
- }
2062
-
2063
2077
  var PREFIX = '[[FORM-CREATE-PREFIX-';
2064
2078
  var SUFFIX = '-FORM-CREATE-SUFFIX]]';
2065
2079
  var $T = '$FN:';
2080
+ var $TX = '$FNX:';
2066
2081
  var FUNCTION = 'function';
2067
2082
  function toJson(obj, space) {
2068
2083
  return JSON.stringify(deepExtend([], obj, true), function (key, val) {
@@ -2087,7 +2102,7 @@
2087
2102
  }
2088
2103
 
2089
2104
  function parseFn(fn, mode) {
2090
- if (fn && is.String(fn)) {
2105
+ if (fn && is.String(fn) && fn.length > 4) {
2091
2106
  var v = fn.trim();
2092
2107
  var flag = false;
2093
2108
 
@@ -2098,8 +2113,8 @@
2098
2113
  } else if (v.indexOf($T) === 0) {
2099
2114
  v = v.replace($T, '');
2100
2115
  flag = true;
2101
- } else if (v.indexOf('$FNX:') === 0) {
2102
- v = makeFn('function($inject){' + v.replace('$FNX:', '') + '}');
2116
+ } else if (v.indexOf($TX) === 0) {
2117
+ v = makeFn('function($inject){' + v.replace($TX, '') + '}');
2103
2118
  v.__json = fn;
2104
2119
  v.__inject = true;
2105
2120
  return v;
@@ -2112,7 +2127,7 @@
2112
2127
  val.__json = fn;
2113
2128
  return val;
2114
2129
  } catch (e) {
2115
- err("\u89E3\u6790\u5931\u8D25:".concat(v));
2130
+ err("\u89E3\u6790\u5931\u8D25:".concat(v, "\n\nerr: ").concat(e));
2116
2131
  return undefined;
2117
2132
  }
2118
2133
  }
@@ -2135,11 +2150,11 @@
2135
2150
  };
2136
2151
  } //todo 优化位置
2137
2152
 
2138
- function copyRule(rule, mode) {
2139
- return copyRules([rule], mode || false)[0];
2153
+ function copyRule(rule) {
2154
+ return copyRules([rule])[0];
2140
2155
  }
2141
- function copyRules(rules, mode) {
2142
- return deepExtend([], _toConsumableArray(rules), mode || false);
2156
+ function copyRules(rules) {
2157
+ return parseJson(toJson(rules));
2143
2158
  }
2144
2159
  function mergeRule(rule, merge) {
2145
2160
  mergeProps(Array.isArray(merge) ? merge : [merge], rule, {
@@ -2203,7 +2218,7 @@
2203
2218
  to;
2204
2219
  (idx || '').split('.').forEach(function (v) {
2205
2220
  if (to) {
2206
- if (!_data[to]) {
2221
+ if (!_data[to] || _typeof(_data[to]) != 'object') {
2207
2222
  _data[to] = {};
2208
2223
  }
2209
2224
 
@@ -2301,13 +2316,6 @@
2301
2316
  return deepCopy(value);
2302
2317
  }
2303
2318
 
2304
- function byRules(ctxs, origin) {
2305
- return Object.keys(ctxs).reduce(function (initial, key) {
2306
- initial[key] = origin ? ctxs[key].origin : ctxs[key].rule;
2307
- return initial;
2308
- }, {});
2309
- }
2310
-
2311
2319
  function Api(h) {
2312
2320
  function tidyFields(fields) {
2313
2321
  if (is.Undef(fields)) fields = h.fields();else if (!Array.isArray(fields)) fields = [fields];
@@ -2316,10 +2324,10 @@
2316
2324
 
2317
2325
  function props(fields, key, val) {
2318
2326
  tidyFields(fields).forEach(function (field) {
2319
- var ctx = h.getCtx(field);
2320
- if (!ctx) return;
2321
- $set(ctx.rule, key, val);
2322
- h.$render.clearCache(ctx);
2327
+ h.getCtxs(field).forEach(function (ctx) {
2328
+ $set(ctx.rule, key, val);
2329
+ h.$render.clearCache(ctx);
2330
+ });
2323
2331
  });
2324
2332
  }
2325
2333
 
@@ -2334,11 +2342,6 @@
2334
2342
  }
2335
2343
 
2336
2344
  var api = {
2337
- helper: {
2338
- tidyFields: tidyFields,
2339
- props: props
2340
- },
2341
-
2342
2345
  get config() {
2343
2346
  return h.options;
2344
2347
  },
@@ -2365,23 +2368,26 @@
2365
2368
 
2366
2369
  formData: function formData(fields) {
2367
2370
  return tidyFields(fields).reduce(function (initial, id) {
2368
- var ctx = h.fieldCtx[id];
2371
+ var ctx = h.getFieldCtx(id);
2369
2372
  if (!ctx) return initial;
2370
2373
  initial[ctx.field] = copy(ctx.rule.value);
2371
2374
  return initial;
2372
2375
  }, copy(h.appendData));
2373
2376
  },
2374
2377
  getValue: function getValue(field) {
2375
- var ctx = h.fieldCtx[field];
2378
+ var ctx = h.getFieldCtx(field);
2376
2379
  if (!ctx) return;
2377
2380
  return copy(ctx.rule.value);
2378
2381
  },
2379
2382
  coverValue: function coverValue(formData) {
2380
2383
  h.deferSyncValue(function () {
2381
- Object.keys(h.fieldCtx).forEach(function (key) {
2382
- var ctx = h.fieldCtx[key];
2383
- if (!ctx) return h.appendData[key] = formData[key];
2384
- ctx.rule.value = hasProperty(formData, key) ? formData[key] : undefined;
2384
+ api.fields().forEach(function (key) {
2385
+ var ctxs = h.fieldCtx[key];
2386
+ if (!ctxs) return h.appendData[key] = formData[key];
2387
+ var flag = hasProperty(formData, key);
2388
+ ctxs.forEach(function (ctx) {
2389
+ ctx.rule.value = flag ? formData[key] : undefined;
2390
+ });
2385
2391
  });
2386
2392
  });
2387
2393
  },
@@ -2390,17 +2396,22 @@
2390
2396
  if (arguments.length >= 2) formData = _defineProperty({}, field, arguments[1]);
2391
2397
  h.deferSyncValue(function () {
2392
2398
  Object.keys(formData).forEach(function (key) {
2393
- var ctx = h.fieldCtx[key];
2394
- if (!ctx) return h.appendData[key] = formData[key];
2395
- ctx.rule.value = formData[key];
2399
+ var ctxs = h.fieldCtx[key];
2400
+ if (!ctxs) return h.appendData[key] = formData[key];
2401
+ ctxs.forEach(function (ctx) {
2402
+ ctx.rule.value = formData[key];
2403
+ });
2396
2404
  });
2397
2405
  });
2398
2406
  },
2399
2407
  removeField: function removeField(field) {
2400
2408
  var ctx = h.getCtx(field);
2401
- if (!ctx) return;
2402
- ctx.rm();
2403
- return ctx.origin;
2409
+ h.deferSyncValue(function () {
2410
+ h.getCtxs(field).forEach(function (ctx) {
2411
+ ctx.rm();
2412
+ });
2413
+ }, true);
2414
+ return ctx ? ctx.origin : undefined;
2404
2415
  },
2405
2416
  removeRule: function removeRule(rule) {
2406
2417
  var ctx = rule && byCtx(rule);
@@ -2416,10 +2427,8 @@
2416
2427
  return h.fields();
2417
2428
  },
2418
2429
  append: function append(rule, after, child) {
2419
- var fields = Object.keys(h.fieldCtx),
2420
- index = h.sort.length - 1,
2430
+ var index = h.sort.length - 1,
2421
2431
  rules;
2422
- if (rule.field && fields.indexOf(rule.field) > -1) return err("".concat(rule.field, " \u5B57\u6BB5\u5DF2\u5B58\u5728"), rule);
2423
2432
  var ctx = h.getCtx(after);
2424
2433
 
2425
2434
  if (ctx) {
@@ -2435,10 +2444,8 @@
2435
2444
  rules.splice(index + 1, 0, rule);
2436
2445
  },
2437
2446
  prepend: function prepend(rule, after, child) {
2438
- var fields = Object.keys(h.fieldCtx),
2439
- index = 0,
2447
+ var index = 0,
2440
2448
  rules;
2441
- if (rule.field && fields.indexOf(rule.field) > -1) return err("".concat(rule.field, " \u5B57\u6BB5\u5DF2\u5B58\u5728"), rule);
2442
2449
  var ctx = h.getCtx(after);
2443
2450
 
2444
2451
  if (ctx) {
@@ -2472,17 +2479,33 @@
2472
2479
  },
2473
2480
  disabled: function disabled(_disabled, fields) {
2474
2481
  tidyFields(fields).forEach(function (field) {
2475
- var ctx = h.fieldCtx[field];
2476
- if (!ctx) return;
2477
- $set(ctx.rule.props, 'disabled', !!_disabled);
2482
+ h.getCtxs(field).forEach(function (ctx) {
2483
+ $set(ctx.rule.props, 'disabled', !!_disabled);
2484
+ });
2478
2485
  });
2479
2486
  h.refresh();
2480
2487
  },
2488
+ all: function all(origin) {
2489
+ return Object.keys(h.ctxs).map(function (k) {
2490
+ var ctx = h.ctxs[k];
2491
+ return origin ? ctx.origin : ctx.rule;
2492
+ });
2493
+ },
2481
2494
  model: function model(origin) {
2482
- return byRules(h.fieldCtx, origin);
2495
+ return h.fields().reduce(function (initial, key) {
2496
+ var ctx = h.fieldCtx[key][0];
2497
+ initial[key] = origin ? ctx.origin : ctx.rule;
2498
+ return initial;
2499
+ }, {});
2483
2500
  },
2484
2501
  component: function component(origin) {
2485
- return byRules(h.nameCtx, origin);
2502
+ return Object.keys(h.nameCtx).reduce(function (initial, key) {
2503
+ var ctx = h.nameCtx[key].map(function (ctx) {
2504
+ return origin ? ctx.origin : ctx.rule;
2505
+ });
2506
+ initial[key] = ctx.length === 1 ? ctx[0] : ctx;
2507
+ return initial;
2508
+ }, {});
2486
2509
  },
2487
2510
  bind: function bind() {
2488
2511
  return api.form;
@@ -2500,25 +2523,39 @@
2500
2523
  });
2501
2524
  },
2502
2525
  sync: function sync(field) {
2503
- var ctx = is.Object(field) ? byCtx(field) : h.getCtx(field);
2526
+ if (Array.isArray(field)) {
2527
+ field.forEach(function (v) {
2528
+ return api.sync(v);
2529
+ });
2530
+ return;
2531
+ }
2504
2532
 
2505
- if (ctx && !ctx.deleted) {
2506
- var subForm = h.subForm[field];
2533
+ var ctxs = is.Object(field) ? byCtx(field) : h.getCtxs(field);
2507
2534
 
2508
- if (subForm) {
2509
- if (Array.isArray(subForm)) {
2510
- subForm.forEach(function (form) {
2511
- form.refresh();
2512
- });
2513
- } else if (subForm) {
2514
- subForm.refresh();
2515
- }
2516
- } //ctx.updateKey(true);
2535
+ if (!ctxs) {
2536
+ return;
2537
+ }
2517
2538
 
2539
+ ctxs = Array.isArray(ctxs) ? ctxs : [ctxs];
2540
+ ctxs.forEach(function (ctx) {
2541
+ if (!ctx.deleted) {
2542
+ var subForm = h.subForm[ctx.id];
2518
2543
 
2519
- h.$render.clearCache(ctx);
2520
- h.refresh();
2521
- }
2544
+ if (subForm) {
2545
+ if (Array.isArray(subForm)) {
2546
+ subForm.forEach(function (form) {
2547
+ form.refresh();
2548
+ });
2549
+ } else if (subForm) {
2550
+ subForm.refresh();
2551
+ }
2552
+ } //ctx.updateKey(true);
2553
+
2554
+
2555
+ h.$render.clearCache(ctx);
2556
+ }
2557
+ });
2558
+ h.refresh();
2522
2559
  },
2523
2560
  refresh: function refresh() {
2524
2561
  allSubForm().forEach(function (sub) {
@@ -2541,8 +2578,9 @@
2541
2578
  h.changeStatus = false;
2542
2579
  },
2543
2580
  updateRule: function updateRule(id, rule) {
2544
- var r = api.getRule(id);
2545
- r && extend(r, rule);
2581
+ h.getCtxs(id).forEach(function (ctx) {
2582
+ extend(ctx.rule, rule);
2583
+ });
2546
2584
  },
2547
2585
  updateRules: function updateRules(rules) {
2548
2586
  Object.keys(rules).forEach(function (id) {
@@ -2550,8 +2588,9 @@
2550
2588
  });
2551
2589
  },
2552
2590
  mergeRule: function mergeRule$1(id, rule) {
2553
- var ctx = h.getCtx(id);
2554
- ctx && mergeRule(ctx.rule, rule);
2591
+ h.getCtxs(id).forEach(function (ctx) {
2592
+ mergeRule(ctx.rule, rule);
2593
+ });
2555
2594
  },
2556
2595
  mergeRules: function mergeRules(rules) {
2557
2596
  Object.keys(rules).forEach(function (id) {
@@ -2584,13 +2623,12 @@
2584
2623
  api.refresh();
2585
2624
  },
2586
2625
  resetFields: function resetFields(fields) {
2587
- var ctxs = h.fieldCtx;
2588
2626
  tidyFields(fields).forEach(function (field) {
2589
- var ctx = ctxs[field];
2590
- if (!ctx) return;
2591
- h.$render.clearCache(ctx);
2592
- ctx.rule.value = copy(ctx.defaultValue);
2593
- h.refreshControl(ctx);
2627
+ h.getCtxs(field).forEach(function (ctx) {
2628
+ h.$render.clearCache(ctx);
2629
+ ctx.rule.value = copy(ctx.defaultValue);
2630
+ h.refreshControl(ctx);
2631
+ });
2594
2632
  });
2595
2633
  },
2596
2634
  method: function method(id, name) {
@@ -2630,7 +2668,8 @@
2630
2668
  el && el.$emit && el.$emit('close-modal');
2631
2669
  },
2632
2670
  getSubForm: function getSubForm(field) {
2633
- return h.subForm[field];
2671
+ var ctx = h.getCtx(field);
2672
+ return ctx ? h.subForm[ctx.id] : undefined;
2634
2673
  },
2635
2674
  nextTick: function nextTick(fn) {
2636
2675
  h.bus.$once('next-tick', fn);
@@ -2639,13 +2678,26 @@
2639
2678
  nextRefresh: function nextRefresh(fn) {
2640
2679
  h.nextRefresh();
2641
2680
  fn && invoke(fn);
2681
+ },
2682
+ emit: function emit(name) {
2683
+ var _h$vm;
2684
+
2685
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2686
+ args[_key3 - 1] = arguments[_key3];
2687
+ }
2688
+
2689
+ (_h$vm = h.vm).$emit.apply(_h$vm, [name].concat(args));
2690
+ },
2691
+ helper: {
2692
+ tidyFields: tidyFields,
2693
+ props: props
2642
2694
  }
2643
2695
  };
2644
2696
  ['on', 'once', 'off', 'set'].forEach(function (n) {
2645
2697
  api[n] = function () {
2646
- var _h$vm;
2698
+ var _h$vm2;
2647
2699
 
2648
- (_h$vm = h.vm)["$".concat(n)].apply(_h$vm, arguments);
2700
+ (_h$vm2 = h.vm)["$".concat(n)].apply(_h$vm2, arguments);
2649
2701
  };
2650
2702
  });
2651
2703
  api.changeValue = api.changeField = api.setValue;
@@ -2769,7 +2821,7 @@
2769
2821
 
2770
2822
  var vm = rule.vm;
2771
2823
  if (!vm) return new _vue();else if (is.Function(vm)) return invoke(function () {
2772
- return vm(_this3.$handle.getInjectData(rule));
2824
+ return rule.vm(_this3.$handle.getInjectData(rule));
2773
2825
  });else if (!vm._isVue) return new _vue(vm);
2774
2826
  return vm;
2775
2827
  },
@@ -2785,6 +2837,14 @@
2785
2837
  deepSet(ctx.prop, ctx.prop.optionsTo, ctx.prop.options);
2786
2838
  }
2787
2839
  },
2840
+ deepSet: function deepSet$1(ctx) {
2841
+ var deep = ctx.rule.deep;
2842
+ deep && Object.keys(deep).sort(function (a, b) {
2843
+ return a.length < b.length ? -1 : 1;
2844
+ }).forEach(function (str) {
2845
+ deepSet(ctx.prop, str, deep[str]);
2846
+ });
2847
+ },
2788
2848
  setTempProps: function setTempProps(vm, ctx) {
2789
2849
  if (!vm.$props) return;
2790
2850
  var prop = ctx.prop;
@@ -2852,12 +2912,17 @@
2852
2912
  return ctx.rule.slot === slot ? this.renderCtx(ctx) : undefined;
2853
2913
  },
2854
2914
  renderId: function renderId(name, type) {
2855
- var ctx = this.$handle[type === 'field' ? 'nameCtx' : 'fieldCtx'][name];
2856
- return ctx ? this.renderCtx(ctx, ctx.parent) : undefined;
2915
+ var _this5 = this;
2916
+
2917
+ var ctxs = this.$handle[type === 'field' ? 'fieldCtx' : 'nameCtx'][name];
2918
+ return ctxs ? ctxs.map(function (ctx) {
2919
+ return _this5.renderCtx(ctx, ctx.parent);
2920
+ }) : undefined;
2857
2921
  },
2858
2922
  renderCtx: function renderCtx(ctx, parent) {
2859
2923
  if (ctx.type === 'hidden') return;
2860
2924
  var rule = ctx.rule;
2925
+ var preview = this.options.preview || false;
2861
2926
 
2862
2927
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2863
2928
  var vn;
@@ -2879,6 +2944,7 @@
2879
2944
  ctx.initProp();
2880
2945
  this.mergeGlobal(ctx);
2881
2946
  this.$manager.tidyRule(ctx);
2947
+ this.deepSet(ctx);
2882
2948
  this.setOptions(ctx);
2883
2949
  this.ctxProp(ctx);
2884
2950
  var prop = ctx.prop;
@@ -2907,11 +2973,13 @@
2907
2973
  vn = this.vm.$scopedSlots[slot]({
2908
2974
  rule: rule,
2909
2975
  prop: prop,
2976
+ preview: preview,
2910
2977
  children: children,
2978
+ api: this.$handle.api,
2911
2979
  model: prop.model || {}
2912
2980
  });
2913
2981
  } else {
2914
- vn = ctx.parser.render(children, ctx);
2982
+ vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
2915
2983
  }
2916
2984
  }
2917
2985
 
@@ -2938,13 +3006,13 @@
2938
3006
  return this.getCache(ctx);
2939
3007
  },
2940
3008
  display: function display(vn) {
2941
- var _this5 = this;
3009
+ var _this6 = this;
2942
3010
 
2943
3011
  if (Array.isArray(vn)) {
2944
3012
  var data = [];
2945
3013
  vn.forEach(function (v) {
2946
- if (Array.isArray(v)) return _this5.display(v);
2947
- if (_this5.none(v)) data.push(v);
3014
+ if (Array.isArray(v)) return _this6.display(v);
3015
+ if (_this6.none(v)) data.push(v);
2948
3016
  });
2949
3017
  return data;
2950
3018
  } else {
@@ -2973,22 +3041,29 @@
2973
3041
  }, [vn]);
2974
3042
  },
2975
3043
  injectProp: function injectProp(ctx) {
2976
- var _this6 = this;
3044
+ var _this7 = this;
2977
3045
 
2978
3046
  if (!this.vm.ctxInject[ctx.id]) {
2979
- $set(this.vm.ctxInject, ctx.id, {});
3047
+ $set(this.vm.ctxInject, ctx.id, {
3048
+ api: this.$handle.api,
3049
+ form: this.fc.create,
3050
+ subForm: function subForm(_subForm) {
3051
+ _this7.$handle.addSubForm(ctx, _subForm);
3052
+ },
3053
+ options: [],
3054
+ children: [],
3055
+ prop: {},
3056
+ preview: false,
3057
+ field: ctx.field,
3058
+ rule: ctx.rule
3059
+ });
2980
3060
  }
2981
3061
 
2982
- extend(this.vm.ctxInject[ctx.id], {
2983
- api: this.$handle.api,
2984
- form: this.fc.create,
2985
- subForm: function subForm(_subForm) {
2986
- _this6.$handle.addSubForm(ctx, _subForm);
2987
- },
2988
- field: ctx.field,
3062
+ var inject = this.vm.ctxInject[ctx.id];
3063
+ extend(inject, {
3064
+ preview: this.options.preview || false,
2989
3065
  options: ctx.prop.options,
2990
3066
  children: ctx.rule.children,
2991
- rule: ctx.rule,
2992
3067
  prop: function () {
2993
3068
  var temp = _objectSpread2({}, ctx.prop);
2994
3069
 
@@ -2997,10 +3072,10 @@
2997
3072
  return temp;
2998
3073
  }()
2999
3074
  });
3000
- return this.vm.ctxInject[ctx.id];
3075
+ return inject;
3001
3076
  },
3002
3077
  ctxProp: function ctxProp(ctx, custom) {
3003
- var _this7 = this;
3078
+ var _this8 = this;
3004
3079
 
3005
3080
  var ref = ctx.ref,
3006
3081
  key = ctx.key,
@@ -3013,7 +3088,10 @@
3013
3088
  slot: undefined,
3014
3089
  on: {
3015
3090
  'hook:mounted': function hookMounted() {
3016
- _this7.onMounted(ctx);
3091
+ _this8.onMounted(ctx);
3092
+ },
3093
+ 'fc.sub-form': function fcSubForm(subForm) {
3094
+ _this8.$handle.addSubForm(ctx, subForm);
3017
3095
  }
3018
3096
  }
3019
3097
  }];
@@ -3023,9 +3101,9 @@
3023
3101
  model: {
3024
3102
  value: this.$handle.getFormData(ctx),
3025
3103
  callback: function callback(value) {
3026
- _this7.onInput(ctx, value);
3104
+ _this8.onInput(ctx, value);
3027
3105
  },
3028
- expression: "formData.".concat(ctx.field)
3106
+ expression: "formData.".concat(ctx.id)
3029
3107
  }
3030
3108
  });
3031
3109
  }
@@ -3047,13 +3125,13 @@
3047
3125
  this.$handle.onInput(ctx, value);
3048
3126
  },
3049
3127
  renderChildren: function renderChildren(ctx) {
3050
- var _this8 = this;
3128
+ var _this9 = this;
3051
3129
 
3052
3130
  var children = ctx.rule.children,
3053
3131
  orgChildren = this.orgChildren[ctx.id];
3054
3132
 
3055
3133
  var isRm = function isRm(child) {
3056
- return !is.String(child) && child.__fc__ && !_this8.$handle.ctxs[child.__fc__.id];
3134
+ return !is.String(child) && child.__fc__ && !_this9.$handle.ctxs[child.__fc__.id];
3057
3135
  };
3058
3136
 
3059
3137
  if (!is.trueArray(children) && orgChildren) {
@@ -3062,7 +3140,7 @@
3062
3140
  if (!child) return;
3063
3141
 
3064
3142
  if (isRm(child)) {
3065
- _this8.$handle.rmCtx(child.__fc__);
3143
+ _this9.$handle.rmCtx(child.__fc__);
3066
3144
  }
3067
3145
  });
3068
3146
  });
@@ -3075,7 +3153,7 @@
3075
3153
  if (!child) return;
3076
3154
 
3077
3155
  if (children.indexOf(child) === -1 && isRm(child)) {
3078
- _this8.$handle.rmCtx(child.__fc__);
3156
+ _this9.$handle.rmCtx(child.__fc__);
3079
3157
  }
3080
3158
  });
3081
3159
  });
@@ -3084,14 +3162,14 @@
3084
3162
  if (is.String(child)) return child;
3085
3163
 
3086
3164
  if (child.__fc__) {
3087
- return _this8.renderCtx(child.__fc__, ctx);
3165
+ return _this9.renderCtx(child.__fc__, ctx);
3088
3166
  }
3089
3167
 
3090
- if (!_this8.$handle.isRepeatRule(child.__origin__ || child) && child.type) {
3091
- _this8.vm.$nextTick(function () {
3092
- _this8.$handle.loadChildren(children, ctx);
3168
+ if (child.type) {
3169
+ _this9.vm.$nextTick(function () {
3170
+ _this9.$handle.loadChildren(children, ctx);
3093
3171
 
3094
- _this8.$handle.refresh();
3172
+ _this9.$handle.refresh();
3095
3173
  });
3096
3174
  }
3097
3175
  });
@@ -3103,7 +3181,7 @@
3103
3181
  return this.vNode.make(lower(ctx.originType), prop, children);
3104
3182
  },
3105
3183
  renderRule: function renderRule(rule, children, origin) {
3106
- var _this9 = this;
3184
+ var _this10 = this;
3107
3185
 
3108
3186
  if (!rule) return undefined;
3109
3187
  if (is.String(rule)) return rule;
@@ -3126,7 +3204,7 @@
3126
3204
 
3127
3205
  if (is.trueArray(rule.children)) {
3128
3206
  data.push(rule.children.map(function (v) {
3129
- return _this9.renderRule(v);
3207
+ return _this10.renderRule(v);
3130
3208
  }));
3131
3209
  }
3132
3210
 
@@ -3160,7 +3238,6 @@
3160
3238
  function useInject(Handler) {
3161
3239
  extend(Handler.prototype, {
3162
3240
  parseInjectEvent: function parseInjectEvent(rule, on) {
3163
- if (rule.inject === false) return;
3164
3241
  var inject = rule.inject || this.options.injectEvent;
3165
3242
  return this.parseEventLst(rule, on, inject);
3166
3243
  },
@@ -3177,13 +3254,16 @@
3177
3254
  return data;
3178
3255
  },
3179
3256
  parseEvent: function parseEvent(rule, fn, inject, deep) {
3180
- if (is.Function(fn) && (!is.Undef(inject) || fn.__inject)) {
3257
+ if (is.Function(fn) && (inject !== false && !is.Undef(inject) || fn.__inject)) {
3181
3258
  return this.inject(rule, fn, inject);
3182
3259
  } else if (!deep && Array.isArray(fn) && fn[0] && (is.String(fn[0]) || is.Function(fn[0]))) {
3183
3260
  return this.parseEventLst(rule, fn, inject, true);
3184
3261
  } else if (is.String(fn)) {
3185
3262
  var val = parseFn(fn);
3186
- return is.String(val) ? val : this.parseEvent(rule, val, inject, true);
3263
+
3264
+ if (val && fn !== val) {
3265
+ return val.__inject ? this.parseEvent(rule, val, inject, true) : val;
3266
+ }
3187
3267
  }
3188
3268
  },
3189
3269
  parseEmit: function parseEmit(ctx, on) {
@@ -3246,6 +3326,7 @@
3246
3326
  option = _this$vm$$options$pro.option,
3247
3327
  rule = _this$vm$$options$pro.rule;
3248
3328
  return {
3329
+ api: this.api,
3249
3330
  $f: this.api,
3250
3331
  rule: rule,
3251
3332
  self: self.__origin__,
@@ -3503,7 +3584,7 @@
3503
3584
  extend(_this2, {
3504
3585
  root: []
3505
3586
  });
3506
- });
3587
+ }, _this2.input);
3507
3588
  });
3508
3589
  },
3509
3590
  update: function update(handle, init) {
@@ -3561,7 +3642,7 @@
3561
3642
  loadFn: function loadFn(item, rule) {
3562
3643
  var _this3 = this;
3563
3644
 
3564
- ['on', 'props', 'nativeOn'].forEach(function (k) {
3645
+ ['on', 'props', 'nativeOn', 'deep'].forEach(function (k) {
3565
3646
  item[k] && _this3.parseInjectEvent(rule, item[k]);
3566
3647
  });
3567
3648
  },
@@ -3588,9 +3669,6 @@
3588
3669
  }, {})
3589
3670
  }], ctx.computed);
3590
3671
  },
3591
- isRepeatRule: function isRepeatRule(rule) {
3592
- return this.repeatRule.indexOf(rule) > -1;
3593
- },
3594
3672
  loadRule: function loadRule() {
3595
3673
  var _this5 = this;
3596
3674
 
@@ -3674,7 +3752,7 @@
3674
3752
  var rule = getRule(_rule);
3675
3753
 
3676
3754
  var isRepeat = function isRepeat() {
3677
- return !!(rule.field && _this6.fieldCtx[rule.field] && _this6.fieldCtx[rule.field] !== _rule.__fc__);
3755
+ return !!(rule.field && _this6.fieldCtx[rule.field] && _this6.fieldCtx[rule.field][0] !== _rule.__fc__);
3678
3756
  };
3679
3757
 
3680
3758
  _this6.ruleEffect(rule, 'init', {
@@ -3682,11 +3760,7 @@
3682
3760
  });
3683
3761
 
3684
3762
  if (isRepeat()) {
3685
- _this6.repeatRule.push(_rule);
3686
-
3687
3763
  _this6.vm.$emit('repeat-field', _rule, _this6.api);
3688
-
3689
- return err("".concat(rule.field, " \u5B57\u6BB5\u5DF2\u5B58\u5728"), _rule);
3690
3764
  }
3691
3765
 
3692
3766
  var ctx;
@@ -3792,14 +3866,17 @@
3792
3866
  return val === control.value;
3793
3867
  };
3794
3868
 
3869
+ if (!is.trueArray(control.rule)) return "continue";
3870
+
3795
3871
  var data = _objectSpread2(_objectSpread2({}, control), {}, {
3796
3872
  valid: invoke(function () {
3797
3873
  return handleFn(ctx.rule.value, api);
3798
3874
  }),
3799
- ctrl: findCtrl(ctx, control.rule)
3875
+ ctrl: findCtrl(ctx, control.rule),
3876
+ isHidden: is.String(control.rule[0])
3800
3877
  });
3801
3878
 
3802
- if (data.valid && data.ctrl || !data.valid && !data.ctrl) return "continue";
3879
+ if (data.valid && data.ctrl || !data.valid && !data.ctrl && !data.isHidden) return "continue";
3803
3880
  validate.push(data);
3804
3881
  };
3805
3882
 
@@ -3811,53 +3888,56 @@
3811
3888
 
3812
3889
  if (!validate.length) return false;
3813
3890
  var flag = false;
3814
- validate.reverse().forEach(function (_ref) {
3815
- var valid = _ref.valid,
3816
- rule = _ref.rule,
3817
- prepend = _ref.prepend,
3818
- append = _ref.append,
3819
- child = _ref.child,
3820
- ctrl = _ref.ctrl;
3821
-
3822
- if (is.String(rule[0])) {
3823
- valid ? ctx.ctrlRule.push({
3824
- __ctrl: true,
3825
- children: rule,
3826
- valid: valid
3827
- }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3828
-
3829
- _this7.vm.$nextTick(function () {
3830
- _this7.api.hidden(!valid, rule);
3831
- });
3891
+ this.deferSyncValue(function () {
3892
+ validate.reverse().forEach(function (_ref) {
3893
+ var isHidden = _ref.isHidden,
3894
+ valid = _ref.valid,
3895
+ rule = _ref.rule,
3896
+ prepend = _ref.prepend,
3897
+ append = _ref.append,
3898
+ child = _ref.child,
3899
+ ctrl = _ref.ctrl;
3900
+
3901
+ if (isHidden) {
3902
+ valid ? ctx.ctrlRule.push({
3903
+ __ctrl: true,
3904
+ children: rule,
3905
+ valid: valid
3906
+ }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3907
+
3908
+ _this7.vm.$nextTick(function () {
3909
+ _this7.api.hidden(!valid, rule);
3910
+ });
3832
3911
 
3833
- return;
3834
- }
3912
+ return;
3913
+ }
3835
3914
 
3836
- if (valid) {
3837
- flag = true;
3838
- var ruleCon = {
3839
- type: 'fcFragment',
3840
- "native": true,
3841
- __ctrl: true,
3842
- children: rule
3843
- };
3844
- ctx.ctrlRule.push(ruleCon);
3845
-
3846
- _this7.bus.$once('load-start', function () {
3847
- // this.cycleLoad = true;
3848
- if (prepend) {
3849
- api.prepend(ruleCon, prepend, child);
3850
- } else if (append || child) {
3851
- api.append(ruleCon, append || ctx.id, child);
3852
- } else {
3853
- ctx.root.splice(ctx.root.indexOf(ctx.origin) + 1, 0, ruleCon);
3854
- }
3855
- });
3856
- } else {
3857
- ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3858
- var ctrlCtx = byCtx(ctrl);
3859
- ctrlCtx && ctrlCtx.rm();
3860
- }
3915
+ if (valid) {
3916
+ flag = true;
3917
+ var ruleCon = {
3918
+ type: 'fcFragment',
3919
+ "native": true,
3920
+ __ctrl: true,
3921
+ children: rule
3922
+ };
3923
+ ctx.ctrlRule.push(ruleCon);
3924
+
3925
+ _this7.bus.$once('load-start', function () {
3926
+ // this.cycleLoad = true;
3927
+ if (prepend) {
3928
+ api.prepend(ruleCon, prepend, child);
3929
+ } else if (append || child) {
3930
+ api.append(ruleCon, append || ctx.id, child);
3931
+ } else {
3932
+ ctx.root.splice(ctx.root.indexOf(ctx.origin) + 1, 0, ruleCon);
3933
+ }
3934
+ });
3935
+ } else {
3936
+ ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3937
+ var ctrlCtx = byCtx(ctrl);
3938
+ ctrlCtx && ctrlCtx.rm();
3939
+ }
3940
+ });
3861
3941
  });
3862
3942
  this.vm.$emit('control', ctx.origin, this.api);
3863
3943
  this.effect(ctx, 'control');
@@ -3893,6 +3973,7 @@
3893
3973
  this.refresh();
3894
3974
  this.bus.$off('next-tick', this.nextReload);
3895
3975
  this.bus.$once('next-tick', this.nextReload);
3976
+ this.vm.$emit('update', this.api);
3896
3977
  },
3897
3978
  //todo 组件生成全部通过 alias
3898
3979
  refresh: function refresh() {
@@ -3928,7 +4009,7 @@
3928
4009
  function useInput(Handler) {
3929
4010
  extend(Handler.prototype, {
3930
4011
  getValue: function getValue(ctx) {
3931
- if (!hasProperty(ctx, 'cacheValue')) {
4012
+ if (is.Undef(ctx.cacheValue)) {
3932
4013
  ctx.cacheValue = ctx.parser.toValue(this.getFormData(ctx), ctx);
3933
4014
  }
3934
4015
 
@@ -3954,18 +4035,19 @@
3954
4035
  }
3955
4036
  },
3956
4037
  setFormData: function setFormData(ctx, value) {
3957
- $set(this.formData, ctx.field, value);
4038
+ $set(this.formData, ctx.id, value);
3958
4039
  },
3959
4040
  getFormData: function getFormData(ctx) {
3960
- return this.formData[ctx.field];
4041
+ return this.formData[ctx.id];
3961
4042
  },
3962
4043
  validate: function validate() {
3963
4044
  var _this = this;
3964
4045
 
3965
4046
  toEmpty(this.vm.validate);
3966
- Object.keys(this.fieldCtx).forEach(function (id) {
3967
- var ctx = _this.fieldCtx[id];
3968
- _this.vm.validate[ctx.field] = toArray(ctx.rule.validate);
4047
+ this.fields().forEach(function (id) {
4048
+ _this.fieldCtx[id].forEach(function (ctx) {
4049
+ _this.vm.validate[ctx.id] = toArray(ctx.rule.validate);
4050
+ });
3969
4051
  });
3970
4052
  return this.vm.validate;
3971
4053
  },
@@ -3973,8 +4055,8 @@
3973
4055
  var _this2 = this;
3974
4056
 
3975
4057
  toEmpty(this.form);
3976
- Object.defineProperties(this.form, Object.keys(this.formData).reduce(function (initial, field) {
3977
- var ctx = _this2.getCtx(field);
4058
+ Object.defineProperties(this.form, this.fields().reduce(function (initial, field) {
4059
+ var ctx = _this2.getFieldCtx(field);
3978
4060
 
3979
4061
  var handle = _this2.valueHandle(ctx);
3980
4062
 
@@ -4018,14 +4100,18 @@
4018
4100
  },
4019
4101
  addSubForm: function addSubForm(ctx, subForm) {
4020
4102
  if (ctx.input) {
4021
- this.subForm[ctx.field] = subForm;
4103
+ this.subForm[ctx.id] = subForm;
4022
4104
  }
4023
4105
  },
4024
- deferSyncValue: function deferSyncValue(fn) {
4106
+ deferSyncValue: function deferSyncValue(fn, sync) {
4025
4107
  if (!this.deferSyncFn) {
4026
4108
  this.deferSyncFn = fn;
4027
4109
  }
4028
4110
 
4111
+ if (!this.deferSyncFn.sync) {
4112
+ this.deferSyncFn.sync = sync;
4113
+ }
4114
+
4029
4115
  invoke(fn);
4030
4116
 
4031
4117
  if (this.deferSyncFn === fn) {
@@ -4052,11 +4138,9 @@
4052
4138
  refreshUpdate: function refreshUpdate(ctx, val) {
4053
4139
  var _this4 = this;
4054
4140
 
4055
- var fn = ctx.rule.update;
4056
-
4057
- if (is.Function(fn)) {
4141
+ if (is.Function(ctx.rule.update)) {
4058
4142
  var state = invoke(function () {
4059
- return fn(val, ctx.origin, _this4.api);
4143
+ return ctx.rule.update(val, ctx.origin, _this4.api);
4060
4144
  });
4061
4145
  if (state === undefined) return;
4062
4146
  ctx.rule.hidden = state === true;
@@ -4070,6 +4154,7 @@
4070
4154
  if (this.refreshControl(ctx)) {
4071
4155
  this.$render.clearCacheAll();
4072
4156
  this.loadRule();
4157
+ this.vm.$emit('update', this.api);
4073
4158
  this.refresh();
4074
4159
  }
4075
4160
 
@@ -4092,7 +4177,7 @@
4092
4177
  });
4093
4178
  },
4094
4179
  fields: function fields() {
4095
- return Object.keys(this.formData);
4180
+ return Object.keys(this.fieldCtx);
4096
4181
  }
4097
4182
  });
4098
4183
  }
@@ -4103,49 +4188,6 @@
4103
4188
  });
4104
4189
  }
4105
4190
 
4106
- function useHelper(rules) {
4107
- if (!Array.isArray(rules) || rules.findField) return;
4108
- Object.defineProperties(rules, {
4109
- findField: enumerable(findField),
4110
- findName: enumerable(findName),
4111
- setValue: enumerable(setValue)
4112
- });
4113
- }
4114
-
4115
- function find(field, name, origin) {
4116
- if (!this.length) return;
4117
- var children = [];
4118
-
4119
- for (var i = 0; i < this.length; i++) {
4120
- if (!is.Object(this[i])) continue;
4121
- var rule = getRule(this[i]);
4122
- if (rule[name] === field) return origin ? rule : this[i];
4123
- if (is.trueArray(rule.children)) children = children.concat(rule.children);
4124
- is.trueArray(rule.control) && rule.control.forEach(function (r) {
4125
- children = children.concat(r.rule);
4126
- });
4127
- }
4128
-
4129
- return find.call(children, field, name, origin);
4130
- }
4131
-
4132
- function findField(field) {
4133
- return find.call(this, field, 'field');
4134
- }
4135
-
4136
- function findName(field) {
4137
- return find.call(this, field, 'name');
4138
- }
4139
-
4140
- function setValue(formData) {
4141
- var _this = this;
4142
-
4143
- Object.keys(formData).forEach(function (field) {
4144
- var rule = find.call(_this, field, 'field', true);
4145
- if (rule) rule.value = formData[field];
4146
- });
4147
- }
4148
-
4149
4191
  var BaseParser = {
4150
4192
  init: function init(ctx) {},
4151
4193
  toFormValue: function toFormValue(value, ctx) {
@@ -4158,13 +4200,46 @@
4158
4200
  render: function render(children, ctx) {
4159
4201
  return ctx.$render.defaultRender(ctx, children);
4160
4202
  },
4203
+ preview: function preview(children, ctx) {
4204
+ return ctx.$render.defaultRender(ctx, children);
4205
+ },
4161
4206
  mergeProp: function mergeProp(ctx) {}
4162
4207
  };
4163
4208
 
4164
4209
  function useContext(Handler) {
4165
4210
  extend(Handler.prototype, {
4166
4211
  getCtx: function getCtx(id) {
4167
- return this.fieldCtx[id] || this.nameCtx[id] || this.ctxs[id];
4212
+ return this.getFieldCtx(id) || this.getNameCtx(id)[0] || this.ctxs[id];
4213
+ },
4214
+ getCtxs: function getCtxs(id) {
4215
+ return this.fieldCtx[id] || this.nameCtx[id] || (this.ctxs[id] ? [this.ctxs[id]] : []);
4216
+ },
4217
+ setIdCtx: function setIdCtx(ctx, key, type) {
4218
+ var field = "".concat(type, "Ctx");
4219
+
4220
+ if (!this[field][key]) {
4221
+ this[field][key] = [ctx];
4222
+ } else {
4223
+ this[field][key].push(ctx);
4224
+ }
4225
+ },
4226
+ rmIdCtx: function rmIdCtx(ctx, key, type) {
4227
+ var field = "".concat(type, "Ctx");
4228
+ var lst = this[field][key];
4229
+ if (!lst) return false;
4230
+ var flag = lst.splice(lst.indexOf(ctx) >>> 0, 1).length > 0;
4231
+
4232
+ if (!lst.length) {
4233
+ delete this[field][key];
4234
+ }
4235
+
4236
+ return flag;
4237
+ },
4238
+ getFieldCtx: function getFieldCtx(field) {
4239
+ return (this.fieldCtx[field] || [])[0];
4240
+ },
4241
+ getNameCtx: function getNameCtx(name) {
4242
+ return this.nameCtx[name] || [];
4168
4243
  },
4169
4244
  setCtx: function setCtx(ctx) {
4170
4245
  var id = ctx.id,
@@ -4172,9 +4247,9 @@
4172
4247
  name = ctx.name,
4173
4248
  rule = ctx.rule;
4174
4249
  this.ctxs[id] = ctx;
4175
- if (name) $set(this.nameCtx, name, ctx);
4250
+ name && this.setIdCtx(ctx, name, 'name');
4176
4251
  if (!ctx.input) return;
4177
- this.fieldCtx[field] = ctx;
4252
+ this.setIdCtx(ctx, field, 'field');
4178
4253
  this.setFormData(ctx, ctx.parser.toFormValue(rule.value, ctx));
4179
4254
 
4180
4255
  if (this.isMounted && !this.reloading) {
@@ -4233,7 +4308,7 @@
4233
4308
  if (key === 'link') {
4234
4309
  ctx.link();
4235
4310
  return;
4236
- } else if (['props', 'on', 'nativeOn'].indexOf(key) > -1) {
4311
+ } else if (['props', 'on', 'nativeOn', 'deep'].indexOf(key) > -1) {
4237
4312
  _this.parseInjectEvent(ctx.rule, n || {});
4238
4313
 
4239
4314
  if (key === 'props' && ctx.input) {
@@ -4254,6 +4329,8 @@
4254
4329
  }
4255
4330
 
4256
4331
  _flag && _this.loadChildren(n, ctx);
4332
+
4333
+ _this.vm.$emit('update', _this.api);
4257
4334
  });
4258
4335
  }
4259
4336
 
@@ -4280,6 +4357,7 @@
4280
4357
  if (ctx.deleted) return;
4281
4358
  var id = ctx.id,
4282
4359
  field = ctx.field,
4360
+ input = ctx.input,
4283
4361
  name = ctx.name;
4284
4362
 
4285
4363
  if (ctx.input) {
@@ -4293,40 +4371,26 @@
4293
4371
  $del(this.$render.tempList, id);
4294
4372
  $del(this.$render.orgChildren, id);
4295
4373
  $del(this.vm.ctxInject, id);
4374
+ $del(this.formData, id);
4375
+ $del(this.subForm, id);
4296
4376
  $del(ctx, 'cacheValue');
4297
- var f = this.fieldCtx[field];
4298
- var flag = false;
4299
-
4300
- if (field && (!f || f === ctx)) {
4301
- $del(this.formData, field);
4302
- $del(this.form, field);
4303
- $del(this.fieldCtx, field);
4304
- $del(this.subForm, field);
4305
- flag = true;
4306
- }
4307
-
4308
- if (name && this.nameCtx[name] === ctx) {
4309
- $del(this.nameCtx, name);
4310
- }
4311
-
4312
- if (!this.reloading) {
4313
- if (ctx.parser.loadChildren !== false) {
4314
- this.deferSyncValue(function () {
4377
+ input && this.rmIdCtx(ctx, field, 'field');
4378
+ name && this.rmIdCtx(ctx, name, 'name');
4379
+ this.deferSyncValue(function () {
4380
+ if (!_this3.reloading) {
4381
+ if (ctx.parser.loadChildren !== false) {
4315
4382
  if (is.trueArray(ctx.rule.children)) {
4316
4383
  ctx.rule.children.forEach(function (h) {
4317
4384
  return h.__fc__ && _this3.rmCtx(h.__fc__);
4318
4385
  });
4319
4386
  }
4387
+ }
4320
4388
 
4321
- _this3.syncValue();
4322
- });
4323
- }
4324
-
4325
- if (ctx.root === this.rules) {
4326
- this.vm._renderRule();
4389
+ if (ctx.root === _this3.rules) {
4390
+ _this3.vm._renderRule();
4391
+ }
4327
4392
  }
4328
- }
4329
-
4393
+ }, input);
4330
4394
  var index = this.sort.indexOf(id);
4331
4395
 
4332
4396
  if (index > -1) {
@@ -4336,7 +4400,7 @@
4336
4400
  this.$render.clearCache(ctx);
4337
4401
  ctx["delete"]();
4338
4402
  this.effect(ctx, 'deleted');
4339
- flag && this.vm.$emit('removeField', field, ctx.rule, this.api);
4403
+ input && !this.fieldCtx[field] && this.vm.$emit('removeField', field, ctx.rule, this.api);
4340
4404
  ctx.rule.__ctrl || this.vm.$emit('removeRule', ctx.rule, this.api);
4341
4405
  return ctx;
4342
4406
  }
@@ -4541,14 +4605,12 @@
4541
4605
  extend(Handler.prototype, {
4542
4606
  initData: function initData(rules) {
4543
4607
  extend(this, {
4544
- fieldCtx: {},
4545
4608
  ctxs: {},
4609
+ fieldCtx: {},
4546
4610
  nameCtx: {},
4547
4611
  sort: [],
4548
- rules: rules,
4549
- repeatRule: []
4612
+ rules: rules
4550
4613
  });
4551
- useHelper(rules);
4552
4614
  },
4553
4615
  init: function init() {
4554
4616
  this.appendData = _objectSpread2(_objectSpread2(_objectSpread2({}, this.fc.options.formData || {}), this.vm.value || {}), this.appendData);
@@ -4804,6 +4866,11 @@
4804
4866
 
4805
4867
  function run(inject, rule, api) {
4806
4868
  var option = inject.value;
4869
+
4870
+ if (is.Function(option)) {
4871
+ option = option(rule, api);
4872
+ }
4873
+
4807
4874
  option = parseOpt(option);
4808
4875
 
4809
4876
  if (!option || !option.action) {
@@ -4914,9 +4981,7 @@
4914
4981
 
4915
4982
 
4916
4983
  function FormCreateFactory(config) {
4917
- var _fragment = _vue.extend(fragment);
4918
-
4919
- var components = _defineProperty({}, fragment.name, _fragment);
4984
+ var components = _defineProperty({}, fragment.name, fragment);
4920
4985
 
4921
4986
  var parsers = {};
4922
4987
  var directives = {};
@@ -4981,6 +5046,10 @@
4981
5046
 
4982
5047
  function $form() {
4983
5048
  return _vue.extend($FormCreate(FormCreate));
5049
+ }
5050
+
5051
+ function $vnode() {
5052
+ return _vue.extend(fragment);
4984
5053
  } //todo 检查回调函数作用域
4985
5054
 
4986
5055
 
@@ -5102,6 +5171,7 @@
5102
5171
  },
5103
5172
  created: function created() {
5104
5173
  this.$handle.init();
5174
+ this.vm.$emit('created', this.api());
5105
5175
  },
5106
5176
  api: function api() {
5107
5177
  return this.$handle.api;
@@ -5123,7 +5193,7 @@
5123
5193
  component: component,
5124
5194
  directive: directive,
5125
5195
  register: register,
5126
- fragment: _fragment,
5196
+ $vnode: $vnode,
5127
5197
  parser: parser,
5128
5198
  use: use,
5129
5199
  factory: factory,
@@ -5177,7 +5247,7 @@
5177
5247
  useAttr($formCreate);
5178
5248
  Vue.prototype.$formCreate = $formCreate;
5179
5249
  Vue.component('FormCreate', $form());
5180
- Vue.component('FcFragment', _fragment);
5250
+ Vue.component('FcFragment', $vnode());
5181
5251
  }
5182
5252
  });
5183
5253
  }
@@ -5526,9 +5596,10 @@
5526
5596
  _col = _this$rule$props.col;
5527
5597
  var item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
5528
5598
  props: _objectSpread2(_objectSpread2({
5529
- labelWidth: labelWidth === void 0 ? labelWidth : toString(labelWidth)
5599
+ labelWidth: labelWidth === void 0 ? labelWidth : toString(labelWidth),
5600
+ label: isTitle ? rule.title.title : undefined
5530
5601
  }, rule.wrap || {}), {}, {
5531
- prop: ctx.field,
5602
+ prop: ctx.id,
5532
5603
  rules: rule.validate
5533
5604
  }),
5534
5605
  "class": rule.className,
@@ -5544,32 +5615,13 @@
5544
5615
  return !(!title.title && !title["native"] || isFalse(title.show));
5545
5616
  },
5546
5617
  makeInfo: function makeInfo(rule, uni) {
5547
- var _this = this;
5548
-
5549
5618
  var titleProp = rule.title;
5550
5619
  var infoProp = rule.info;
5551
5620
  var isTip = isTooltip(infoProp);
5552
5621
  var form = this.options.form;
5553
- var children = [titleProp.title + (form.labelSuffix || form['label-suffix'] || '')];
5554
-
5555
- var titleFn = function titleFn(pop) {
5556
- return _this.$r(mergeProps([titleProp, {
5557
- props: titleProp,
5558
- slot: titleProp.slot || (pop ? isTip ? 'default' : 'reference' : '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: 'i',
5568
- "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5569
- key: "".concat(uni, "i")
5570
- }));
5571
- }
5622
+ var children = [(titleProp.title || '') + (form.labelSuffix || form['label-suffix'] || '')];
5572
5623
 
5624
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5573
5625
  var prop = {
5574
5626
  type: infoProp.type || 'popover',
5575
5627
  props: _objectSpread2({}, infoProp),
@@ -5582,10 +5634,20 @@
5582
5634
  prop.props[field] = infoProp.info;
5583
5635
  }
5584
5636
 
5585
- return this.$r(mergeProps([infoProp, prop]), [titleFn(true)]);
5637
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), [this.$r({
5638
+ type: 'i',
5639
+ slot: isTip ? 'default' : 'reference',
5640
+ "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5641
+ key: "".concat(uni, "i")
5642
+ })]));
5586
5643
  }
5587
5644
 
5588
- return titleFn();
5645
+ return this.$r(mergeProps([titleProp, {
5646
+ props: titleProp,
5647
+ slot: titleProp.slot || 'label',
5648
+ key: "".concat(uni, "tit"),
5649
+ type: titleProp.type || 'span'
5650
+ }]), children);
5589
5651
  },
5590
5652
  makeCol: function makeCol(rule, uni, children) {
5591
5653
  var col = rule.col;
@@ -5635,7 +5697,7 @@
5635
5697
  }, [item]);
5636
5698
  },
5637
5699
  makeResetBtn: function makeResetBtn() {
5638
- var _this2 = this;
5700
+ var _this = this;
5639
5701
 
5640
5702
  var resetBtn = this.options.resetBtn;
5641
5703
  return this.$r({
@@ -5646,7 +5708,7 @@
5646
5708
  },
5647
5709
  on: {
5648
5710
  click: function click() {
5649
- var fApi = _this2.$handle.api;
5711
+ var fApi = _this.$handle.api;
5650
5712
  resetBtn.click ? resetBtn.click(fApi) : fApi.resetFields();
5651
5713
  }
5652
5714
  },
@@ -5654,7 +5716,7 @@
5654
5716
  }, [resetBtn.innerText]);
5655
5717
  },
5656
5718
  makeSubmitBtn: function makeSubmitBtn() {
5657
- var _this3 = this;
5719
+ var _this2 = this;
5658
5720
 
5659
5721
  var submitBtn = this.options.submitBtn;
5660
5722
  return this.$r({
@@ -5665,7 +5727,7 @@
5665
5727
  },
5666
5728
  on: {
5667
5729
  click: function click() {
5668
- var fApi = _this3.$handle.api;
5730
+ var fApi = _this2.$handle.api;
5669
5731
  submitBtn.click ? submitBtn.click(fApi) : fApi.submit();
5670
5732
  }
5671
5733
  },
@@ -5818,13 +5880,14 @@
5818
5880
  }
5819
5881
  },
5820
5882
  validateField: function validateField(field, callback) {
5821
- if (!h.fieldCtx[field]) return;
5822
- var sub = h.subForm[field];
5883
+ var ctx = h.getFieldCtx(field);
5884
+ if (!ctx) return;
5885
+ var sub = h.subForm[ctx.id];
5823
5886
  var len = 0;
5824
5887
  var flag;
5825
5888
 
5826
5889
  var validate = function validate() {
5827
- h.$manager.validateField(field, function () {
5890
+ h.$manager.validateField(ctx.id, function () {
5828
5891
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
5829
5892
  args[_key3] = arguments[_key3];
5830
5893
  }
@@ -5874,23 +5937,25 @@
5874
5937
  var clearSub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
5875
5938
  api.helper.tidyFields(fields).forEach(function (field) {
5876
5939
  if (clearSub) _this.clearSubValidateState(field);
5877
- var ctx = h.fieldCtx[field];
5878
- if (!ctx) return;
5879
- h.$manager.clearValidateState(ctx);
5940
+ h.getCtxs(field).forEach(function (ctx) {
5941
+ h.$manager.clearValidateState(ctx);
5942
+ });
5880
5943
  });
5881
5944
  },
5882
5945
  clearSubValidateState: function clearSubValidateState(fields) {
5883
5946
  api.helper.tidyFields(fields).forEach(function (field) {
5884
- var subForm = h.subForm[field];
5885
- if (!subForm) return;
5947
+ h.getCtxs(field).forEach(function (ctx) {
5948
+ var subForm = h.subForm[ctx.id];
5949
+ if (!subForm) return;
5886
5950
 
5887
- if (Array.isArray(subForm)) {
5888
- subForm.forEach(function (form) {
5889
- form.clearValidateState();
5890
- });
5891
- } else if (subForm) {
5892
- subForm.clearValidateState();
5893
- }
5951
+ if (Array.isArray(subForm)) {
5952
+ subForm.forEach(function (form) {
5953
+ form.clearValidateState();
5954
+ });
5955
+ } else if (subForm) {
5956
+ subForm.clearValidateState();
5957
+ }
5958
+ });
5894
5959
  });
5895
5960
  },
5896
5961
  btn: {
@@ -5993,7 +6058,7 @@
5993
6058
  function elmFormCreate() {
5994
6059
  return FormCreateFactory({
5995
6060
  ui: "".concat("element-ui"),
5996
- version: "".concat("2.5.10"),
6061
+ version: "".concat("2.5.14"),
5997
6062
  manager: manager,
5998
6063
  extendApi: extendApi,
5999
6064
  install: install,