@form-create/element-ui 2.5.34 → 2.5.36

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.34
2
+ * @form-create/element-ui v2.5.36
3
3
  * (c) 2018-2024 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -1505,6 +1505,7 @@
1505
1505
  for (var i = len; i < 0; i++) {
1506
1506
  this.addRule(n.length + i);
1507
1507
  }
1508
+ this.sort = Object.keys(this.cacheRule);
1508
1509
  for (var _i = 0; _i < total; _i++) {
1509
1510
  this.setValue(keys[_i], n[_i]);
1510
1511
  }
@@ -1513,6 +1514,7 @@
1513
1514
  for (var _i2 = 0; _i2 < len; _i2++) {
1514
1515
  this.removeRule(keys[total - _i2 - 1]);
1515
1516
  }
1517
+ this.sort = Object.keys(this.cacheRule);
1516
1518
  }
1517
1519
  n.forEach(function (val, i) {
1518
1520
  _this2.setValue(keys[i], n[i]);
@@ -1933,6 +1935,10 @@
1933
1935
  }
1934
1936
  },
1935
1937
  extendOption: Boolean,
1938
+ disabled: {
1939
+ type: Boolean,
1940
+ "default": undefined
1941
+ },
1936
1942
  value: Object,
1937
1943
  api: Object,
1938
1944
  name: String,
@@ -1981,8 +1987,8 @@
1981
1987
  deep: true
1982
1988
  },
1983
1989
  option: {
1984
- handler: function handler(n) {
1985
- this.formCreate.initOptions(n);
1990
+ handler: function handler() {
1991
+ this.formCreate.initOptions();
1986
1992
  this.$f.refresh();
1987
1993
  },
1988
1994
  deep: true
@@ -1994,14 +2000,14 @@
1994
2000
  })) return;
1995
2001
  this.formCreate.$handle.reloadRule(n);
1996
2002
  this._renderRule();
2003
+ },
2004
+ disabled: function disabled() {
2005
+ this.$f.refresh();
1997
2006
  }
1998
2007
  },
1999
2008
  beforeCreate: function beforeCreate() {
2000
2009
  var _this2 = this;
2001
- var _this$$options$propsD = this.$options.propsData,
2002
- rule = _this$$options$propsD.rule,
2003
- option = _this$$options$propsD.option;
2004
- this.formCreate = new FormCreate(this, rule, option);
2010
+ this.formCreate = new FormCreate(this);
2005
2011
  Object.keys(this.formCreate.prop).forEach(function (k) {
2006
2012
  extend(_this2.$options[k], _this2.formCreate.prop[k]);
2007
2013
  });
@@ -2141,7 +2147,7 @@
2141
2147
  var $TX = '$FNX:';
2142
2148
  var FUNCTION = 'function';
2143
2149
  function toJson(obj, space) {
2144
- return JSON.stringify(deepExtend([], obj, true), function (key, val) {
2150
+ return JSON.stringify(deepExtend(Array.isArray(obj) ? [] : {}, obj, true), function (key, val) {
2145
2151
  if (val && val._isVue === true) return undefined;
2146
2152
  if (_typeof(val) !== FUNCTION) {
2147
2153
  return val;
@@ -2252,6 +2258,61 @@
2252
2258
  }
2253
2259
  return def;
2254
2260
  }
2261
+ var changeType = function changeType(a, b) {
2262
+ if (typeof a === 'string') {
2263
+ return String(b);
2264
+ } else if (typeof a === 'number') {
2265
+ return Number(b);
2266
+ }
2267
+ return b;
2268
+ };
2269
+ var condition = {
2270
+ '==': function _(a, b) {
2271
+ return JSON.stringify(a) === JSON.stringify(changeType(a, b));
2272
+ },
2273
+ '!=': function _(a, b) {
2274
+ return !condition['=='](a, b);
2275
+ },
2276
+ '>': function _(a, b) {
2277
+ return a > b;
2278
+ },
2279
+ '>=': function _(a, b) {
2280
+ return a >= b;
2281
+ },
2282
+ '<': function _(a, b) {
2283
+ return a < b;
2284
+ },
2285
+ '<=': function _(a, b) {
2286
+ return a <= b;
2287
+ },
2288
+ on: function on(a, b) {
2289
+ return a && a.indexOf && a.indexOf(changeType(a[0], b)) > -1;
2290
+ },
2291
+ notOn: function notOn(a, b) {
2292
+ return !condition.on(a, b);
2293
+ },
2294
+ "in": function _in(a, b) {
2295
+ return b && b.indexOf && b.indexOf(a) > -1;
2296
+ },
2297
+ notIn: function notIn(a, b) {
2298
+ return !condition["in"](a, b);
2299
+ },
2300
+ between: function between(a, b) {
2301
+ return a > b[0] && a < b[1];
2302
+ },
2303
+ notBetween: function notBetween(a, b) {
2304
+ return a < b[0] || a > b[1];
2305
+ },
2306
+ empty: function empty(a) {
2307
+ return is.empty(a);
2308
+ },
2309
+ notEmpty: function notEmpty(a) {
2310
+ return !is.empty(a);
2311
+ },
2312
+ pattern: function pattern(a, b) {
2313
+ return new RegExp(b, 'g').test(a);
2314
+ }
2315
+ };
2255
2316
 
2256
2317
  function baseRule() {
2257
2318
  return {
@@ -2333,6 +2394,92 @@
2333
2394
  };
2334
2395
  }
2335
2396
 
2397
+ function getError(action, option, xhr) {
2398
+ var msg = "fail to ".concat(action, " ").concat(xhr.status, "'");
2399
+ var err = new Error(msg);
2400
+ err.status = xhr.status;
2401
+ err.url = action;
2402
+ return err;
2403
+ }
2404
+ function getBody(xhr) {
2405
+ var text = xhr.responseText || xhr.response;
2406
+ if (!text) {
2407
+ return text;
2408
+ }
2409
+ try {
2410
+ return JSON.parse(text);
2411
+ } catch (e) {
2412
+ return text;
2413
+ }
2414
+ }
2415
+ function fetch(option) {
2416
+ if (typeof XMLHttpRequest === 'undefined') {
2417
+ return;
2418
+ }
2419
+ var xhr = new XMLHttpRequest();
2420
+ var action = option.action;
2421
+ xhr.onerror = function error(e) {
2422
+ option.onError(e);
2423
+ };
2424
+ xhr.onload = function onload() {
2425
+ if (xhr.status < 200 || xhr.status >= 300) {
2426
+ return option.onError(getError(action, option, xhr), getBody(xhr));
2427
+ }
2428
+ option.onSuccess(getBody(xhr));
2429
+ };
2430
+ xhr.open(option.method || 'get', action, true);
2431
+ var formData;
2432
+ if (option.data) {
2433
+ if ((option.dataType || '').toLowerCase() !== 'json') {
2434
+ formData = new FormData();
2435
+ Object.keys(option.data).map(function (key) {
2436
+ formData.append(key, option.data[key]);
2437
+ });
2438
+ } else {
2439
+ formData = JSON.stringify(option.data);
2440
+ xhr.setRequestHeader('content-type', 'application/json');
2441
+ }
2442
+ }
2443
+ if (option.withCredentials && 'withCredentials' in xhr) {
2444
+ xhr.withCredentials = true;
2445
+ }
2446
+ var headers = option.headers || {};
2447
+ Object.keys(headers).forEach(function (item) {
2448
+ if (headers[item] !== null) {
2449
+ xhr.setRequestHeader(item, headers[item]);
2450
+ }
2451
+ });
2452
+ xhr.send(formData);
2453
+ }
2454
+ function asyncFetch(config) {
2455
+ return new Promise(function (resolve, reject) {
2456
+ fetch(_objectSpread2(_objectSpread2({}, config), {}, {
2457
+ onSuccess: function onSuccess(res) {
2458
+ var fn = function fn(v) {
2459
+ return v;
2460
+ };
2461
+ var parse = parseFn(config.parse);
2462
+ if (is.Function(parse)) {
2463
+ fn = parse;
2464
+ } else if (parse && is.String(parse)) {
2465
+ fn = function fn(v) {
2466
+ parse.split('.').forEach(function (k) {
2467
+ if (v) {
2468
+ v = v[k];
2469
+ }
2470
+ });
2471
+ return v;
2472
+ };
2473
+ }
2474
+ resolve(fn(res));
2475
+ },
2476
+ onError: function onError(err) {
2477
+ reject(err);
2478
+ }
2479
+ }));
2480
+ });
2481
+ }
2482
+
2336
2483
  function copy(value) {
2337
2484
  return deepCopy(value);
2338
2485
  }
@@ -2374,6 +2521,12 @@
2374
2521
  get parent() {
2375
2522
  return h.vm.$pfc && h.vm.$pfc.$f;
2376
2523
  },
2524
+ get top() {
2525
+ if (api.parent) {
2526
+ return api.parent.top;
2527
+ }
2528
+ return api;
2529
+ },
2377
2530
  get children() {
2378
2531
  return allSubForm();
2379
2532
  },
@@ -2608,6 +2761,21 @@
2608
2761
  return origin ? ctx.origin : ctx.rule;
2609
2762
  }
2610
2763
  },
2764
+ getRenderRule: function getRenderRule(id) {
2765
+ var ctx = h.getCtx(id);
2766
+ if (ctx) {
2767
+ return ctx.prop;
2768
+ }
2769
+ },
2770
+ getRefRule: function getRefRule(id) {
2771
+ var ctxs = h.getCtxs(id);
2772
+ if (ctxs && ctxs.length) {
2773
+ var rules = ctxs.map(function (ctx) {
2774
+ return ctx.rule;
2775
+ });
2776
+ return rules.length === 1 ? rules[0] : rules;
2777
+ }
2778
+ },
2611
2779
  setEffect: function setEffect(id, attr, value) {
2612
2780
  var ctx = h.getCtx(id);
2613
2781
  if (ctx && attr) {
@@ -2714,12 +2882,23 @@
2714
2882
  deferSyncValue: function deferSyncValue(fn, sync) {
2715
2883
  h.deferSyncValue(fn, sync);
2716
2884
  },
2885
+ fetch: function fetch(opt) {
2886
+ h.options.beforeFetch && invoke(function () {
2887
+ return h.options.beforeFetch(opt, {
2888
+ api: api
2889
+ });
2890
+ });
2891
+ return asyncFetch(opt);
2892
+ },
2893
+ getData: function getData(id, def) {
2894
+ return hasProperty(h.fc.loadData, id) ? h.fc.loadData[id] : def;
2895
+ },
2717
2896
  helper: {
2718
2897
  tidyFields: tidyFields,
2719
2898
  props: props
2720
2899
  }
2721
2900
  };
2722
- ['on', 'once', 'off', 'set'].forEach(function (n) {
2901
+ ['on', 'once', 'off', 'set', 'emit'].forEach(function (n) {
2723
2902
  api[n] = function () {
2724
2903
  var _h$vm2;
2725
2904
  (_h$vm2 = h.vm)["$".concat(n)].apply(_h$vm2, arguments);
@@ -2793,7 +2972,8 @@
2793
2972
 
2794
2973
  var id = 0;
2795
2974
  function uniqueId() {
2796
- return 'F' + Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now()).concat(++id)).toString(36);
2975
+ var num = 370 + ++id;
2976
+ return 'F' + Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now())).toString(36) + num.toString(36) + 'c';
2797
2977
  }
2798
2978
 
2799
2979
  function deepSet(data, idx, val) {
@@ -3104,6 +3284,7 @@
3104
3284
  children: [],
3105
3285
  prop: {},
3106
3286
  preview: false,
3287
+ id: ctx.id,
3107
3288
  field: ctx.field,
3108
3289
  rule: ctx.rule,
3109
3290
  input: ctx.input
@@ -3123,13 +3304,13 @@
3123
3304
  });
3124
3305
  return inject;
3125
3306
  },
3126
- ctxProp: function ctxProp(ctx, custom) {
3307
+ ctxProp: function ctxProp(ctx) {
3127
3308
  var _this8 = this;
3128
3309
  var ref = ctx.ref,
3129
3310
  key = ctx.key,
3130
3311
  rule = ctx.rule;
3131
- this.$manager.mergeProp(ctx, custom);
3132
- ctx.parser.mergeProp(ctx, custom);
3312
+ this.$manager.mergeProp(ctx);
3313
+ ctx.parser.mergeProp(ctx);
3133
3314
  var props = [{
3134
3315
  ref: ref,
3135
3316
  key: rule.key || "".concat(key, "fc"),
@@ -3149,7 +3330,10 @@
3149
3330
  }
3150
3331
  }
3151
3332
  }];
3152
- if (!custom && ctx.input) {
3333
+ if (ctx.input) {
3334
+ if (this.vm.$props.disabled !== undefined) {
3335
+ ctx.prop.props.disabled = !!this.vm.$props.disabled;
3336
+ }
3153
3337
  ctx.prop.model = {
3154
3338
  value: this.$handle.getFormData(ctx),
3155
3339
  callback: function callback(value) {
@@ -3307,16 +3491,17 @@
3307
3491
  inject = rule.inject;
3308
3492
  var emit = rule[on ? 'emit' : 'nativeEmit'] || [];
3309
3493
  if (is.trueArray(emit)) {
3310
- var emitKey = emitPrefix || field || name;
3311
- if (emitKey) {
3312
- if (!on) emitKey = "native-".concat(emitKey);
3313
- emit.forEach(function (eventName) {
3314
- if (!eventName) return;
3315
- var eventInject;
3316
- if (is.Object(eventName)) {
3317
- eventInject = eventName.inject;
3318
- eventName = eventName.name;
3319
- }
3494
+ emit.forEach(function (eventName) {
3495
+ if (!eventName) return;
3496
+ var eventInject;
3497
+ var emitKey = emitPrefix || field || name;
3498
+ if (is.Object(eventName)) {
3499
+ eventInject = eventName.inject;
3500
+ eventName = eventName.name;
3501
+ emitKey = eventName.prefix || emitKey;
3502
+ }
3503
+ if (emitKey) {
3504
+ if (!on) emitKey = "native-".concat(emitKey);
3320
3505
  var fieldKey = toLine("".concat(emitKey, "-").concat(eventName));
3321
3506
  var fn = function fn() {
3322
3507
  var _this2$vm, _this2$vm2;
@@ -3333,8 +3518,8 @@
3333
3518
  var _inject = eventInject || inject || _this2.options.injectEvent;
3334
3519
  event[eventName] = is.Undef(_inject) ? fn : _this2.inject(rule, fn, _inject);
3335
3520
  }
3336
- });
3337
- }
3521
+ }
3522
+ });
3338
3523
  }
3339
3524
  ctx.computed[on ? 'on' : 'nativeOn'] = event;
3340
3525
  return event;
@@ -3510,6 +3695,30 @@
3510
3695
  return _this.payload[k];
3511
3696
  })), [this.computed]));
3512
3697
  },
3698
+ injectValidate: function injectValidate() {
3699
+ var _this2 = this;
3700
+ return toArray(this.prop.validate).map(function (item) {
3701
+ if (is.Function(item.validator)) {
3702
+ var temp = _objectSpread2({}, item);
3703
+ var that = _this2;
3704
+ temp.validator = function () {
3705
+ var _item$validator;
3706
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3707
+ args[_key] = arguments[_key];
3708
+ }
3709
+ return (_item$validator = item.validator).call.apply(_item$validator, [{
3710
+ that: this,
3711
+ id: that.id,
3712
+ field: that.field,
3713
+ rule: that.rule,
3714
+ api: that.$handle.api
3715
+ }].concat(args));
3716
+ };
3717
+ return temp;
3718
+ }
3719
+ return item;
3720
+ });
3721
+ },
3513
3722
  check: function check(handle) {
3514
3723
  return this.vm === handle.vm;
3515
3724
  },
@@ -3558,12 +3767,12 @@
3558
3767
  this.ctrlRule = [];
3559
3768
  },
3560
3769
  rm: function rm() {
3561
- var _this2 = this;
3770
+ var _this3 = this;
3562
3771
  var _rm = function _rm() {
3563
- var index = _this2.root.indexOf(_this2.origin);
3772
+ var index = _this3.root.indexOf(_this3.origin);
3564
3773
  if (index > -1) {
3565
- _this2.root.splice(index, 1);
3566
- _this2.$handle && _this2.$handle.refresh();
3774
+ _this3.root.splice(index, 1);
3775
+ _this3.$handle && _this3.$handle.refresh();
3567
3776
  }
3568
3777
  };
3569
3778
  if (this.deleted) {
@@ -3571,14 +3780,14 @@
3571
3780
  return;
3572
3781
  }
3573
3782
  this.$handle.noWatch(function () {
3574
- _this2.$handle.deferSyncValue(function () {
3575
- _this2.rmCtrl();
3783
+ _this3.$handle.deferSyncValue(function () {
3784
+ _this3.rmCtrl();
3576
3785
  _rm();
3577
- _this2.$handle.rmCtx(_this2);
3578
- extend(_this2, {
3786
+ _this3.$handle.rmCtx(_this3);
3787
+ extend(_this3, {
3579
3788
  root: []
3580
3789
  });
3581
- }, _this2.input);
3790
+ }, _this3.input);
3582
3791
  });
3583
3792
  },
3584
3793
  update: function update(handle, init) {
@@ -3599,73 +3808,6 @@
3599
3808
  }
3600
3809
  });
3601
3810
 
3602
- var condition = {
3603
- '==': function _(b) {
3604
- return function (a) {
3605
- return a === b;
3606
- };
3607
- },
3608
- '!=': function _(b) {
3609
- return function (a) {
3610
- return a !== b;
3611
- };
3612
- },
3613
- '<>': function _(b) {
3614
- return function (a) {
3615
- return a !== b;
3616
- };
3617
- },
3618
- '>': function _(b) {
3619
- return function (a) {
3620
- return a > b;
3621
- };
3622
- },
3623
- '>=': function _(b) {
3624
- return function (a) {
3625
- return a >= b;
3626
- };
3627
- },
3628
- '<': function _(b) {
3629
- return function (a) {
3630
- return a < b;
3631
- };
3632
- },
3633
- '<=': function _(b) {
3634
- return function (a) {
3635
- return a <= b;
3636
- };
3637
- },
3638
- 'in': function _in(b) {
3639
- return function (a) {
3640
- return b && b.indexOf && b.indexOf(a) > -1;
3641
- };
3642
- },
3643
- 'on': function on(b) {
3644
- return function (a) {
3645
- return a && a.indexOf && a.indexOf(b) > -1;
3646
- };
3647
- },
3648
- 'notIn': function notIn(b) {
3649
- return function (a) {
3650
- return !condition["in"](b)(a);
3651
- };
3652
- },
3653
- 'notOn': function notOn(b) {
3654
- return function (a) {
3655
- return !condition.on(b)(a);
3656
- };
3657
- },
3658
- 'between': function between(b) {
3659
- return function (a) {
3660
- return a > b[0] && a < b[1];
3661
- };
3662
- },
3663
- 'notBetween': function notBetween(b) {
3664
- return function (a) {
3665
- return a < b[0] || a > b[1];
3666
- };
3667
- }
3668
- };
3669
3811
  function useLoader(Handler) {
3670
3812
  extend(Handler.prototype, {
3671
3813
  nextRefresh: function nextRefresh(fn) {
@@ -3817,7 +3959,7 @@
3817
3959
  }
3818
3960
  if (!ctx) {
3819
3961
  var _rule2 = _this6.parseRule(_rule);
3820
- ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
3962
+ ctx = new RuleContext(_this6, _rule2, defaultValue);
3821
3963
  _this6.bindParser(ctx);
3822
3964
  } else {
3823
3965
  if (ctx.originType !== ctx.rule.type) {
@@ -3870,7 +4012,9 @@
3870
4012
  if (!controls.length) return false;
3871
4013
  var _loop = function _loop(i) {
3872
4014
  var control = controls[i],
3873
- handleFn = control.handle || (condition[control.condition || '=='] || condition['=='])(control.value);
4015
+ handleFn = control.handle || function (val) {
4016
+ return (condition[control.condition || '=='] || condition['=='])(val, control.value);
4017
+ };
3874
4018
  if (!is.trueArray(control.rule)) return "continue";
3875
4019
  var data = _objectSpread2(_objectSpread2({}, control), {}, {
3876
4020
  valid: invoke(function () {
@@ -4032,6 +4176,11 @@
4032
4176
  this.valueChange(ctx, value);
4033
4177
  this.vm.$emit('change', ctx.field, value, ctx.origin, this.api, setFlag || false);
4034
4178
  this.effect(ctx, 'value');
4179
+ this.emitEvent('change', ctx.field, value, {
4180
+ rule: ctx.origin,
4181
+ api: this.api,
4182
+ setFlag: setFlag || false
4183
+ });
4035
4184
  },
4036
4185
  onInput: function onInput(ctx, value) {
4037
4186
  var val;
@@ -4128,12 +4277,13 @@
4128
4277
  isQuote: function isQuote(ctx, value) {
4129
4278
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
4130
4279
  },
4131
- refreshUpdate: function refreshUpdate(ctx, val, origin) {
4280
+ refreshUpdate: function refreshUpdate(ctx, val, origin, field) {
4132
4281
  var _this4 = this;
4133
4282
  if (is.Function(ctx.rule.update)) {
4134
4283
  var state = invoke(function () {
4135
4284
  return ctx.rule.update(val, ctx.origin, _this4.api, {
4136
- origin: origin || 'change'
4285
+ origin: origin || 'change',
4286
+ linkField: field
4137
4287
  });
4138
4288
  });
4139
4289
  if (state === undefined) return;
@@ -4144,21 +4294,21 @@
4144
4294
  this.refreshRule(ctx, val);
4145
4295
  this.bus.$emit('change-' + ctx.field, val);
4146
4296
  },
4147
- refreshRule: function refreshRule(ctx, val, origin) {
4297
+ refreshRule: function refreshRule(ctx, val, origin, field) {
4148
4298
  if (this.refreshControl(ctx)) {
4149
4299
  this.$render.clearCacheAll();
4150
4300
  this.loadRule();
4151
4301
  this.vm.$emit('update', this.api);
4152
4302
  this.refresh();
4153
4303
  }
4154
- this.refreshUpdate(ctx, val, origin);
4304
+ this.refreshUpdate(ctx, val, origin, field);
4155
4305
  },
4156
4306
  appendLink: function appendLink(ctx) {
4157
4307
  var _this5 = this;
4158
4308
  var link = ctx.rule.link;
4159
4309
  is.trueArray(link) && link.forEach(function (field) {
4160
4310
  var fn = function fn() {
4161
- return _this5.refreshRule(ctx, ctx.rule.value, 'link');
4311
+ return _this5.refreshRule(ctx, ctx.rule.value, 'link', field);
4162
4312
  };
4163
4313
  _this5.bus.$on('change-' + field, fn);
4164
4314
  ctx.linkOn.push(function () {
@@ -4389,12 +4539,22 @@
4389
4539
  }
4390
4540
  },
4391
4541
  lifecycle: function lifecycle(name) {
4392
- var _this2 = this;
4393
- var fn = this.options[name];
4394
- is.Function(fn) && invoke(function () {
4395
- return fn(_this2.api);
4396
- });
4397
4542
  this.vm.$emit(name, this.api);
4543
+ this.emitEvent(name, this.api);
4544
+ },
4545
+ emitEvent: function emitEvent(name) {
4546
+ var _this$bus;
4547
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
4548
+ args[_key - 1] = arguments[_key];
4549
+ }
4550
+ var _fn = this.options[name] || this.options[toCase('on-' + name)];
4551
+ if (_fn) {
4552
+ var fn = parseFn(_fn);
4553
+ is.Function(fn) && invoke(function () {
4554
+ return fn.apply(void 0, args);
4555
+ });
4556
+ }
4557
+ (_this$bus = this.bus).$emit.apply(_this$bus, [name].concat(args));
4398
4558
  }
4399
4559
  });
4400
4560
  }
@@ -4596,6 +4756,7 @@
4596
4756
  this.usePage();
4597
4757
  this.loadRule();
4598
4758
  this.$manager.__init();
4759
+ this.lifecycle('created');
4599
4760
  this.vm.$set(this.vm, 'formData', this.formData);
4600
4761
  }
4601
4762
  });
@@ -4608,64 +4769,6 @@
4608
4769
  useLifecycle(Handler);
4609
4770
  useEffect(Handler);
4610
4771
 
4611
- function getError(action, option, xhr) {
4612
- var msg = "fail to ".concat(action, " ").concat(xhr.status, "'");
4613
- var err = new Error(msg);
4614
- err.status = xhr.status;
4615
- err.url = action;
4616
- return err;
4617
- }
4618
- function getBody(xhr) {
4619
- var text = xhr.responseText || xhr.response;
4620
- if (!text) {
4621
- return text;
4622
- }
4623
- try {
4624
- return JSON.parse(text);
4625
- } catch (e) {
4626
- return text;
4627
- }
4628
- }
4629
- function fetch(option) {
4630
- if (typeof XMLHttpRequest === 'undefined') {
4631
- return;
4632
- }
4633
- var xhr = new XMLHttpRequest();
4634
- var action = option.action;
4635
- xhr.onerror = function error(e) {
4636
- option.onError(e);
4637
- };
4638
- xhr.onload = function onload() {
4639
- if (xhr.status < 200 || xhr.status >= 300) {
4640
- return option.onError(getError(action, option, xhr), getBody(xhr));
4641
- }
4642
- option.onSuccess(getBody(xhr));
4643
- };
4644
- xhr.open(option.method || 'get', action, true);
4645
- var formData;
4646
- if (option.data) {
4647
- if ((option.dataType || '').toLowerCase() !== 'json') {
4648
- formData = new FormData();
4649
- Object.keys(option.data).map(function (key) {
4650
- formData.append(key, option.data[key]);
4651
- });
4652
- } else {
4653
- formData = JSON.stringify(option.data);
4654
- xhr.setRequestHeader('content-type', 'application/json');
4655
- }
4656
- }
4657
- if (option.withCredentials && 'withCredentials' in xhr) {
4658
- xhr.withCredentials = true;
4659
- }
4660
- var headers = option.headers || {};
4661
- Object.keys(headers).forEach(function (item) {
4662
- if (headers[item] !== null) {
4663
- xhr.setRequestHeader(item, headers[item]);
4664
- }
4665
- });
4666
- xhr.send(formData);
4667
- }
4668
-
4669
4772
  var NAME$9 = 'fcFragment';
4670
4773
  var fragment = {
4671
4774
  name: NAME$9,
@@ -4908,6 +5011,7 @@
4908
5011
  set(undefined);
4909
5012
  return;
4910
5013
  }
5014
+ option = deepCopy(option);
4911
5015
  if (!option.to) {
4912
5016
  option.to = 'options';
4913
5017
  }
@@ -4988,6 +5092,7 @@
4988
5092
  var val = parseVal(inject.getValue());
4989
5093
  if (val.required === false) {
4990
5094
  inject.clearProp();
5095
+ api.clearValidateState([rule.field]);
4991
5096
  } else {
4992
5097
  var validate = _objectSpread2({
4993
5098
  required: true,
@@ -5143,11 +5248,12 @@
5143
5248
  }
5144
5249
  function parser() {
5145
5250
  var data = nameProp.apply(void 0, arguments);
5146
- if (!data.id || !data.prop) return;
5251
+ if (!data.id || !data.prop) return BaseParser;
5147
5252
  var name = toCase(data.id);
5148
5253
  var parser = data.prop;
5149
5254
  var base = parser.merge === true ? parsers[name] : undefined;
5150
- parsers[name] = _objectSpread2(_objectSpread2({}, base || BaseParser), parser);
5255
+ parsers[name] = parser;
5256
+ Object.setPrototypeOf(parser, base || BaseParser);
5151
5257
  maker[name] = creatorFactory(name);
5152
5258
  parser.maker && extend(maker, parser.maker);
5153
5259
  }
@@ -5165,7 +5271,13 @@
5165
5271
  component = id;
5166
5272
  }
5167
5273
  if (!name || !component) return;
5274
+ var nameAlias = toCase(name);
5168
5275
  components[name] = component;
5276
+ components[nameAlias] = component;
5277
+ delete CreateNode.aliasMap[name];
5278
+ delete CreateNode.aliasMap[nameAlias];
5279
+ delete parsers[name];
5280
+ delete parsers[nameAlias];
5169
5281
  if (component.formCreateParser) parser(name, component.formCreateParser);
5170
5282
  }
5171
5283
  function _emitData(id) {
@@ -5217,7 +5329,8 @@
5217
5329
  }
5218
5330
  return FormCreateFactory(_config);
5219
5331
  }
5220
- function FormCreate(vm, rules, options) {
5332
+ function FormCreate(vm) {
5333
+ var rules = vm.$options.propsData.rule;
5221
5334
  extend(this, {
5222
5335
  id: id$1++,
5223
5336
  vm: vm,
@@ -5236,13 +5349,13 @@
5236
5349
  CreateNode: CreateNode,
5237
5350
  bus: new _vue(),
5238
5351
  unwatch: null,
5239
- options: options || {},
5352
+ options: {},
5240
5353
  extendApi: config.extendApi || function (api) {
5241
5354
  return api;
5242
5355
  }
5243
5356
  });
5244
5357
  this.init();
5245
- this.initOptions(this.options);
5358
+ this.initOptions();
5246
5359
  if (this.name) {
5247
5360
  if (this.inFor) {
5248
5361
  if (!instance[this.name]) instance[this.name] = [];
@@ -5265,12 +5378,12 @@
5265
5378
  _this2.unwatch = vm.$watch(function () {
5266
5379
  return vm.$pfc.option;
5267
5380
  }, function () {
5268
- _this2.initOptions(_this2.options);
5381
+ _this2.initOptions();
5269
5382
  vm.$f.refresh();
5270
5383
  }, {
5271
5384
  deep: true
5272
5385
  });
5273
- _this2.initOptions(_this2.options);
5386
+ _this2.initOptions();
5274
5387
  }
5275
5388
  _this2.created();
5276
5389
  });
@@ -5302,8 +5415,9 @@
5302
5415
  isSub: function isSub() {
5303
5416
  return this.vm.$pfc && this.vm.extendOption;
5304
5417
  },
5305
- initOptions: function initOptions(options) {
5306
- this.options = _objectSpread2({
5418
+ initOptions: function initOptions() {
5419
+ this.options = {};
5420
+ var options = _objectSpread2({
5307
5421
  formData: {},
5308
5422
  submitBtn: {},
5309
5423
  resetBtn: {}
@@ -5311,6 +5425,7 @@
5311
5425
  if (this.isSub()) {
5312
5426
  this.mergeOptions(this.options, this.vm.$pfc.$f.config || {}, true);
5313
5427
  }
5428
+ options = this.mergeOptions(options, this.vm.$options.propsData.option);
5314
5429
  this.updateOptions(options);
5315
5430
  },
5316
5431
  mergeOptions: function mergeOptions(target, opt, parent) {
@@ -5742,8 +5857,7 @@
5742
5857
  ref: ref
5743
5858
  });
5744
5859
  extend(this.rule.props, {
5745
- model: $handle.formData,
5746
- rules: $handle.validate()
5860
+ model: $handle.formData
5747
5861
  });
5748
5862
  },
5749
5863
  render: function render(children) {
@@ -5767,7 +5881,7 @@
5767
5881
  label: isTitle ? rule.title.title : undefined
5768
5882
  }, rule.wrap || {}), {}, {
5769
5883
  prop: ctx.id,
5770
- rules: rule.validate
5884
+ rules: ctx.injectValidate()
5771
5885
  }),
5772
5886
  "class": rule.className,
5773
5887
  key: "".concat(uni, "fi"),
@@ -6158,7 +6272,7 @@
6158
6272
  function elmFormCreate() {
6159
6273
  return FormCreateFactory({
6160
6274
  ui: "".concat("element-ui"),
6161
- version: "".concat("2.5.34"),
6275
+ version: "".concat("2.5.36"),
6162
6276
  manager: manager,
6163
6277
  extendApi: extendApi,
6164
6278
  install: install,