@form-create/element-ui 3.1.32 → 3.1.34

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 v3.1.32
2
+ * @form-create/element-ui v3.1.34
3
3
  * (c) 2018-2024 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -1612,14 +1612,6 @@ var Group = defineComponent({
1612
1612
  },
1613
1613
  deep: true
1614
1614
  },
1615
- disabled: function disabled(n) {
1616
- if (this.syncDisabled) {
1617
- var lst = this.cacheRule;
1618
- Object.keys(lst).forEach(function (k) {
1619
- lst[k].$f.disabled(n);
1620
- });
1621
- }
1622
- },
1623
1615
  expand: function expand(n) {
1624
1616
  var d = n - this.modelValue.length;
1625
1617
 
@@ -1741,10 +1733,6 @@ var Group = defineComponent({
1741
1733
 
1742
1734
  this.cacheRule[key].$f = $f;
1743
1735
  nextTick(function () {
1744
- if (_this5.syncDisabled) {
1745
- $f.disabled(_this5.disabled);
1746
- }
1747
-
1748
1736
  _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
1749
1737
  });
1750
1738
  },
@@ -1915,6 +1903,7 @@ var Group = defineComponent({
1915
1903
  }, [createVNode(Type, mergeProps$1({
1916
1904
  "key": key
1917
1905
  }, {
1906
+ disabled: disabled,
1918
1907
  'onUpdate:modelValue': function onUpdateModelValue(formData) {
1919
1908
  return _this12.formData(key, formData);
1920
1909
  },
@@ -1985,9 +1974,6 @@ var Sub = defineComponent({
1985
1974
  },
1986
1975
  emits: ['fc:subform', 'update:modelValue', 'change', 'itemMounted'],
1987
1976
  watch: {
1988
- disabled: function disabled(n) {
1989
- this.syncDisabled && this.subApi.disabled(n);
1990
- },
1991
1977
  modelValue: function modelValue(n) {
1992
1978
  this.setValue(n);
1993
1979
  }
@@ -2013,8 +1999,6 @@ var Sub = defineComponent({
2013
1999
 
2014
2000
  this.subApi = api;
2015
2001
  nextTick(function () {
2016
- _this.syncDisabled && api.disabled(_this.disabled);
2017
-
2018
2002
  _this.$emit('itemMounted', api);
2019
2003
  });
2020
2004
  }
@@ -2022,6 +2006,7 @@ var Sub = defineComponent({
2022
2006
  render: function render() {
2023
2007
  var Type = this.form;
2024
2008
  return createVNode(Type, {
2009
+ "disabled": this.disabled,
2025
2010
  "onUpdate:modelValue": this.formData,
2026
2011
  "modelValue": this.modelValue,
2027
2012
  "onEmit-event": this.$emit,
@@ -2234,6 +2219,10 @@ function $FormCreate(FormCreate, components, directives) {
2234
2219
  type: Boolean,
2235
2220
  "default": undefined
2236
2221
  },
2222
+ preview: {
2223
+ type: Boolean,
2224
+ "default": undefined
2225
+ },
2237
2226
  api: Object,
2238
2227
  name: String,
2239
2228
  subForm: {
@@ -2370,7 +2359,7 @@ function $FormCreate(FormCreate, components, directives) {
2370
2359
  deep: true
2371
2360
  });
2372
2361
  watch(function () {
2373
- return props.disabled;
2362
+ return [props.disabled, props.preview];
2374
2363
  }, function () {
2375
2364
  fapi.refresh();
2376
2365
  });
@@ -2649,6 +2638,64 @@ function setPrototypeOf(o, proto) {
2649
2638
  return o;
2650
2639
  }
2651
2640
 
2641
+ var changeType = function changeType(a, b) {
2642
+ if (typeof a === 'string') {
2643
+ return String(b);
2644
+ } else if (typeof a === 'number') {
2645
+ return Number(b);
2646
+ }
2647
+
2648
+ return b;
2649
+ };
2650
+
2651
+ var condition = {
2652
+ '==': function _(a, b) {
2653
+ return JSON.stringify(a) === JSON.stringify(changeType(a, b));
2654
+ },
2655
+ '!=': function _(a, b) {
2656
+ return !condition['=='](a, b);
2657
+ },
2658
+ '>': function _(a, b) {
2659
+ return a > b;
2660
+ },
2661
+ '>=': function _(a, b) {
2662
+ return a >= b;
2663
+ },
2664
+ '<': function _(a, b) {
2665
+ return a < b;
2666
+ },
2667
+ '<=': function _(a, b) {
2668
+ return a <= b;
2669
+ },
2670
+ on: function on(a, b) {
2671
+ return a && a.indexOf && a.indexOf(changeType(a[0], b)) > -1;
2672
+ },
2673
+ notOn: function notOn(a, b) {
2674
+ return !condition.on(a, b);
2675
+ },
2676
+ "in": function _in(a, b) {
2677
+ return b && b.indexOf && b.indexOf(a) > -1;
2678
+ },
2679
+ notIn: function notIn(a, b) {
2680
+ return !condition["in"](a, b);
2681
+ },
2682
+ between: function between(a, b) {
2683
+ return a > b[0] && a < b[1];
2684
+ },
2685
+ notBetween: function notBetween(a, b) {
2686
+ return a < b[0] || a > b[1];
2687
+ },
2688
+ empty: function empty(a) {
2689
+ return is.empty(a);
2690
+ },
2691
+ notEmpty: function notEmpty(a) {
2692
+ return !is.empty(a);
2693
+ },
2694
+ pattern: function pattern(a, b) {
2695
+ return new RegExp(b, 'g').test(a);
2696
+ }
2697
+ };
2698
+
2652
2699
  function baseRule() {
2653
2700
  return {
2654
2701
  props: {},
@@ -2901,7 +2948,7 @@ function Api(h) {
2901
2948
  if (!ctx) return initial;
2902
2949
  initial[ctx.field] = copy(ctx.rule.value);
2903
2950
  return initial;
2904
- }, {});
2951
+ }, h.options.appendValue !== false ? copy(h.appendData) : {});
2905
2952
  },
2906
2953
  getValue: function getValue(field) {
2907
2954
  var ctx = h.getFieldCtx(field);
@@ -3317,10 +3364,7 @@ function Api(h) {
3317
3364
 
3318
3365
  if (config.type === 'fetch') {
3319
3366
  api.fetch(config).then(function (res) {
3320
- resolve({
3321
- res: res,
3322
- config: config
3323
- });
3367
+ resolve(res);
3324
3368
  })["catch"](inject);
3325
3369
  } else {
3326
3370
  resolve(config.data);
@@ -3349,12 +3393,17 @@ function Api(h) {
3349
3393
  },
3350
3394
  bus: h.bus,
3351
3395
  fetch: function fetch(opt) {
3352
- h.options.beforeFetch && invoke(function () {
3353
- return h.options.beforeFetch(opt, {
3354
- api: api
3396
+ return new Promise(function (resolve, reject) {
3397
+ h.beforeFetch(opt).then(function () {
3398
+ return asyncFetch(opt).then(resolve)["catch"](reject);
3355
3399
  });
3356
3400
  });
3357
- return asyncFetch(opt);
3401
+ },
3402
+ getData: function getData(id, def) {
3403
+ return h.fc.getData(id, def);
3404
+ },
3405
+ setData: function setData(id, data) {
3406
+ return h.fc.setData(id, data);
3358
3407
  },
3359
3408
  helper: {
3360
3409
  tidyFields: tidyFields,
@@ -3564,7 +3613,7 @@ function useRender$1(Render) {
3564
3613
  this.setOptions(ctx);
3565
3614
  this.ctxProp(ctx);
3566
3615
  var prop = ctx.prop;
3567
- prop.preview = !!(hasProperty(prop, 'preview') ? prop.preview : this.options.preview || false);
3616
+ prop.preview = !!(prop.preview != null ? prop.preview : this.vm.props.preview !== undefined ? this.vm.props.preview : this.options.preview || false);
3568
3617
  prop.props.formCreateInject = this.injectProp(ctx);
3569
3618
  var cacheFlag = prop.cache !== false;
3570
3619
  var preview = prop.preview;
@@ -3756,8 +3805,8 @@ function useRender$1(Render) {
3756
3805
  }];
3757
3806
 
3758
3807
  if (ctx.input) {
3759
- if (this.vm.props.disabled !== undefined) {
3760
- ctx.prop.props.disabled = !!this.vm.props.disabled;
3808
+ if (this.vm.props.disabled === true) {
3809
+ ctx.prop.props.disabled = true;
3761
3810
  }
3762
3811
 
3763
3812
  var field = this.getModelField(ctx);
@@ -4292,14 +4341,31 @@ extend(RuleContext.prototype, {
4292
4341
  var _this4 = this;
4293
4342
 
4294
4343
  return toArray(this.prop.validate).map(function (item) {
4295
- return _objectSpread2(_objectSpread2({}, item), {}, {
4296
- inject: {
4297
- id: _this4.id,
4298
- field: _this4.field,
4299
- rule: _this4.rule,
4300
- api: _this4.$handle.api
4301
- }
4302
- });
4344
+ if (is.Function(item.validator)) {
4345
+ var temp = _objectSpread2({}, item);
4346
+
4347
+ var that = _this4;
4348
+
4349
+ temp.validator = function () {
4350
+ var _item$validator;
4351
+
4352
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4353
+ args[_key] = arguments[_key];
4354
+ }
4355
+
4356
+ return (_item$validator = item.validator).call.apply(_item$validator, [{
4357
+ that: this,
4358
+ id: that.id,
4359
+ field: that.field,
4360
+ rule: that.rule,
4361
+ api: that.$handle.api
4362
+ }].concat(args));
4363
+ };
4364
+
4365
+ return temp;
4366
+ }
4367
+
4368
+ return item;
4303
4369
  });
4304
4370
  },
4305
4371
  check: function check(handle) {
@@ -4408,73 +4474,6 @@ extend(RuleContext.prototype, {
4408
4474
  }
4409
4475
  });
4410
4476
 
4411
- var condition = {
4412
- '==': function _(b) {
4413
- return function (a) {
4414
- return a === b;
4415
- };
4416
- },
4417
- '!=': function _(b) {
4418
- return function (a) {
4419
- return a !== b;
4420
- };
4421
- },
4422
- '<>': function _(b) {
4423
- return function (a) {
4424
- return a !== b;
4425
- };
4426
- },
4427
- '>': function _(b) {
4428
- return function (a) {
4429
- return a > b;
4430
- };
4431
- },
4432
- '>=': function _(b) {
4433
- return function (a) {
4434
- return a >= b;
4435
- };
4436
- },
4437
- '<': function _(b) {
4438
- return function (a) {
4439
- return a < b;
4440
- };
4441
- },
4442
- '<=': function _(b) {
4443
- return function (a) {
4444
- return a <= b;
4445
- };
4446
- },
4447
- 'in': function _in(b) {
4448
- return function (a) {
4449
- return b && b.indexOf && b.indexOf(a) > -1;
4450
- };
4451
- },
4452
- 'on': function on(b) {
4453
- return function (a) {
4454
- return a && a.indexOf && a.indexOf(b) > -1;
4455
- };
4456
- },
4457
- 'notIn': function notIn(b) {
4458
- return function (a) {
4459
- return !condition["in"](b)(a);
4460
- };
4461
- },
4462
- 'notOn': function notOn(b) {
4463
- return function (a) {
4464
- return !condition.on(b)(a);
4465
- };
4466
- },
4467
- 'between': function between(b) {
4468
- return function (a) {
4469
- return a > b[0] && a < b[1];
4470
- };
4471
- },
4472
- 'notBetween': function notBetween(b) {
4473
- return function (a) {
4474
- return a < b[0] || a > b[1];
4475
- };
4476
- }
4477
- };
4478
4477
  function useLoader(Handler) {
4479
4478
  extend(Handler.prototype, {
4480
4479
  nextRefresh: function nextRefresh(fn) {
@@ -4664,7 +4663,7 @@ function useLoader(Handler) {
4664
4663
  if (!ctx) {
4665
4664
  var _rule2 = _this6.parseRule(_rule);
4666
4665
 
4667
- ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
4666
+ ctx = new RuleContext(_this6, _rule2, defaultValue);
4668
4667
 
4669
4668
  _this6.bindParser(ctx);
4670
4669
  } else {
@@ -4747,7 +4746,10 @@ function useLoader(Handler) {
4747
4746
 
4748
4747
  var _loop = function _loop(i) {
4749
4748
  var control = controls[i],
4750
- handleFn = control.handle || (condition[control.condition || '=='] || condition['=='])(control.value);
4749
+ handleFn = control.handle || function (val) {
4750
+ return (condition[control.condition || '=='] || condition['=='])(val, control.value);
4751
+ };
4752
+
4751
4753
  if (!is.trueArray(control.rule)) return "continue";
4752
4754
 
4753
4755
  var data = _objectSpread2(_objectSpread2({}, control), {}, {
@@ -5015,7 +5017,7 @@ function useInput(Handler) {
5015
5017
  return this.deferSyncFn.sync = true;
5016
5018
  }
5017
5019
 
5018
- this.vm.setupState.updateValue(_objectSpread2({}, this.form));
5020
+ this.vm.setupState.updateValue(_objectSpread2(_objectSpread2({}, this.options.appendValue !== false ? this.appendData : {}), this.form));
5019
5021
  },
5020
5022
  isChange: function isChange(ctx, value) {
5021
5023
  return JSON.stringify(this.getFormData(ctx), strFn) !== JSON.stringify(value, strFn);
@@ -5269,15 +5271,56 @@ function useContext(Handler) {
5269
5271
  if (!item) return undefined;
5270
5272
  var fn;
5271
5273
 
5272
- if (is.Function(item)) {
5274
+ if (_typeof(item) === 'object') {
5275
+ var group = ctx.getParentGroup();
5276
+
5277
+ var checkCondition = function checkCondition(item) {
5278
+ item = Array.isArray(item) ? {
5279
+ mode: 'AND',
5280
+ group: item
5281
+ } : item;
5282
+
5283
+ if (!is.trueArray(item.group)) {
5284
+ return true;
5285
+ }
5286
+
5287
+ var or = item.mode === 'OR';
5288
+ var valid = true;
5289
+
5290
+ for (var i = 0; i < item.group.length; i++) {
5291
+ var one = item.group[i];
5292
+ var flag = void 0;
5293
+
5294
+ if (one.mode) {
5295
+ flag = checkCondition(one);
5296
+ } else if (!condition[one.condition]) {
5297
+ flag = false;
5298
+ } else {
5299
+ flag = new Function('_$', '_$val', 'top', 'group', "with(top){with(this){with(group){ return _$['".concat(one.condition, "'](").concat(one.field, ", ").concat(one.compare ? one.compare : '_$val', "); }}}")).call(_this.api.form, condition, one.value, _this.api.top.form, group ? _this.subRuleData[group.id] || {} : {});
5300
+ }
5301
+
5302
+ if (or && flag) {
5303
+ return true;
5304
+ }
5305
+
5306
+ if (!or) {
5307
+ valid = valid && flag;
5308
+ }
5309
+ }
5310
+
5311
+ return or ? false : valid;
5312
+ };
5313
+
5314
+ return checkCondition(item);
5315
+ } else if (is.Function(item)) {
5273
5316
  fn = function fn() {
5274
5317
  return item(_this.api.form, _this.api);
5275
5318
  };
5276
5319
  } else {
5277
- var group = ctx.getParentGroup();
5320
+ var _group = ctx.getParentGroup();
5278
5321
 
5279
5322
  fn = function fn() {
5280
- return new Function('formulas', 'top', 'group', '$rule', '$api', "with(top){with(this){with(group){with(formulas){ return ".concat(item, " }}}}")).call(_this.api.form, _this.fc.formulas, _this.api.top.form, group ? _this.subRuleData[group.id] || {} : {}, ctx.rule, _this.api);
5323
+ return new Function('formulas', 'top', 'group', '$rule', '$api', "with(top){with(this){with(group){with(formulas){ return ".concat(item, " }}}}")).call(_this.api.form, _this.fc.formulas, _this.api.top.form, _group ? _this.subRuleData[_group.id] || {} : {}, ctx.rule, _this.api);
5281
5324
  };
5282
5325
  }
5283
5326
 
@@ -5630,7 +5673,11 @@ function Handler(fc) {
5630
5673
  this.initData(fc.rules);
5631
5674
  this.$manager = new fc.manager(this);
5632
5675
  this.$render = new Render(this);
5633
- this.api = fc.extendApi(Api(this), this);
5676
+ this.api = fc.extendApiFn.reduce(function (api, fn) {
5677
+ return _objectSpread2(_objectSpread2({}, api), invoke(function () {
5678
+ return fn(_objectSpread2({}, api), _this);
5679
+ }, {}));
5680
+ }, Api(this));
5634
5681
  }
5635
5682
  extend(Handler.prototype, {
5636
5683
  initData: function initData(rules) {
@@ -5654,6 +5701,23 @@ extend(Handler.prototype, {
5654
5701
  },
5655
5702
  isBreakWatch: function isBreakWatch() {
5656
5703
  return this.loading || this.noWatchFn || this.reloading;
5704
+ },
5705
+ beforeFetch: function beforeFetch(opt) {
5706
+ var _this2 = this;
5707
+
5708
+ return new Promise(function (resolve) {
5709
+ var source = _this2.options.beforeFetch && invoke(function () {
5710
+ return _this2.options.beforeFetch(opt, {
5711
+ api: _this2.api
5712
+ });
5713
+ });
5714
+
5715
+ if (source && is.Function(source.then)) {
5716
+ source.then(resolve);
5717
+ } else {
5718
+ resolve();
5719
+ }
5720
+ });
5657
5721
  }
5658
5722
  });
5659
5723
  useInject(Handler);
@@ -5868,7 +5932,7 @@ var loadData = function loadData(fc) {
5868
5932
  if (attr.attr) {
5869
5933
  value = fc.loadData[attr.attr] || attr["default"];
5870
5934
 
5871
- if (attr.copy) {
5935
+ if (attr.copy !== false) {
5872
5936
  value = deepCopy(value);
5873
5937
  }
5874
5938
  }
@@ -5968,6 +6032,8 @@ var fetch = function fetch(fc) {
5968
6032
  return;
5969
6033
  }
5970
6034
 
6035
+ option = deepCopy(option);
6036
+
5971
6037
  if (!option.to) {
5972
6038
  option.to = 'options';
5973
6039
  }
@@ -6005,7 +6071,7 @@ var fetch = function fetch(fc) {
6005
6071
  if (check()) return;
6006
6072
 
6007
6073
  var fn = function fn(v) {
6008
- return flag ? v : v.data;
6074
+ return flag ? v : hasProperty(v, 'data') ? v.data : v;
6009
6075
  };
6010
6076
 
6011
6077
  var parse = parseFn(option.parse);
@@ -6036,27 +6102,25 @@ var fetch = function fetch(fc) {
6036
6102
  }
6037
6103
  });
6038
6104
 
6039
- fc.$handle.options.beforeFetch && invoke(function () {
6040
- return fc.$handle.options.beforeFetch(config, {
6041
- rule: rule,
6042
- api: api
6043
- });
6044
- });
6045
-
6046
- if (is.Function(option.action)) {
6047
- option.action(rule, api).then(function (val) {
6048
- config.onSuccess(val, true);
6049
- })["catch"](function (e) {
6050
- config.onError(e);
6051
- });
6052
- return;
6053
- }
6105
+ fc.$handle.beforeFetch(config, {
6106
+ rule: rule,
6107
+ api: api
6108
+ }).then(function () {
6109
+ if (is.Function(option.action)) {
6110
+ option.action(rule, api).then(function (val) {
6111
+ config.onSuccess(val, true);
6112
+ })["catch"](function (e) {
6113
+ config.onError(e);
6114
+ });
6115
+ return;
6116
+ }
6054
6117
 
6055
- invoke(function () {
6056
- return fc.create.fetch(config, {
6057
- inject: inject,
6058
- rule: rule,
6059
- api: api
6118
+ invoke(function () {
6119
+ return fc.create.fetch(config, {
6120
+ inject: inject,
6121
+ rule: rule,
6122
+ api: api
6123
+ });
6060
6124
  });
6061
6125
  });
6062
6126
  }
@@ -6137,6 +6201,7 @@ function FormCreateFactory(config) {
6137
6201
  var directives = {};
6138
6202
  var modelFields = {};
6139
6203
  var useApps = [];
6204
+ var extendApiFn = [config.extendApi];
6140
6205
 
6141
6206
  var providers = _objectSpread2({}, $provider);
6142
6207
 
@@ -6144,7 +6209,7 @@ function FormCreateFactory(config) {
6144
6209
  var globalConfig = {
6145
6210
  global: {}
6146
6211
  };
6147
- var loadData = {};
6212
+ var loadData = reactive({});
6148
6213
  var CreateNode = CreateNodeFactory();
6149
6214
  var formulas = {};
6150
6215
  exportAttrs(config.attrs || {});
@@ -6306,6 +6371,14 @@ function FormCreateFactory(config) {
6306
6371
  _emitData(id);
6307
6372
  }
6308
6373
 
6374
+ function getData(id, def) {
6375
+ return hasProperty(loadData, id) ? loadData[id] : def;
6376
+ }
6377
+
6378
+ function extendApi(fn) {
6379
+ extendApiFn.push(fn);
6380
+ }
6381
+
6309
6382
  function removeData(id) {
6310
6383
  delete loadData[id];
6311
6384
 
@@ -6331,14 +6404,14 @@ function FormCreateFactory(config) {
6331
6404
  components: components,
6332
6405
  directives: directives
6333
6406
  },
6407
+ setData: setData,
6408
+ getData: getData,
6334
6409
  loadData: loadData,
6335
6410
  CreateNode: CreateNode,
6336
6411
  bus: new Mitt(),
6337
6412
  unwatch: null,
6338
6413
  options: ref({}),
6339
- extendApi: config.extendApi || function (api) {
6340
- return api;
6341
- }
6414
+ extendApiFn: extendApiFn
6342
6415
  });
6343
6416
  nextTick(function () {
6344
6417
  watch(_this.options, function () {
@@ -6456,6 +6529,8 @@ function FormCreateFactory(config) {
6456
6529
  extend(formCreate, {
6457
6530
  version: config.version,
6458
6531
  ui: config.ui,
6532
+ extendApi: extendApi,
6533
+ getData: getData,
6459
6534
  setData: setData,
6460
6535
  removeData: removeData,
6461
6536
  maker: maker,
@@ -7173,7 +7248,7 @@ function tidyBtnProp(btn, def) {
7173
7248
  }
7174
7249
 
7175
7250
  function extendApi(api, h) {
7176
- extend(api, {
7251
+ return {
7177
7252
  formEl: function formEl() {
7178
7253
  return h.$manager.form();
7179
7254
  },
@@ -7332,8 +7407,7 @@ function extendApi(api, h) {
7332
7407
  });
7333
7408
  });
7334
7409
  }
7335
- });
7336
- return api;
7410
+ };
7337
7411
  }
7338
7412
 
7339
7413
  var required = {
@@ -7414,7 +7488,7 @@ function install(FormCreate) {
7414
7488
  function elmFormCreate() {
7415
7489
  return FormCreateFactory({
7416
7490
  ui: 'element-ui',
7417
- version: '3.1.32',
7491
+ version: '3.1.34',
7418
7492
  manager: manager,
7419
7493
  extendApi: extendApi,
7420
7494
  install: install,