@form-create/element-ui 3.2.19 → 3.2.20

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.2.19
2
+ * @form-create/element-ui v3.2.20
3
3
  * (c) 2018-2025 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -2323,6 +2323,9 @@ function $FormCreate(FormCreate, components, directives) {
2323
2323
  var emit$topForm = debounce(function () {
2324
2324
  fc.bus.$emit('$loadData.$topForm');
2325
2325
  }, 100);
2326
+ var emit$scopeForm = debounce(function () {
2327
+ fc.bus.$emit('$loadData.$scopeForm');
2328
+ }, 100);
2326
2329
  var emit$form = debounce(function () {
2327
2330
  fc.bus.$emit('$loadData.$form');
2328
2331
  }, 100);
@@ -2337,6 +2340,10 @@ function $FormCreate(FormCreate, components, directives) {
2337
2340
  fapi.top.bus.$on('change', emit$change);
2338
2341
  }
2339
2342
 
2343
+ if (fapi !== fapi.scope) {
2344
+ fapi.scope.bus.$on('$loadData.$scopeForm', emit$scopeForm);
2345
+ }
2346
+
2340
2347
  fc.mounted();
2341
2348
  });
2342
2349
  onBeforeUnmount(function () {
@@ -2345,6 +2352,10 @@ function $FormCreate(FormCreate, components, directives) {
2345
2352
  fapi.top.bus.$off('change', emit$change);
2346
2353
  }
2347
2354
 
2355
+ if (fapi !== fapi.scope) {
2356
+ fapi.scope.bus.$off('$loadData.$scopeForm', emit$scopeForm);
2357
+ }
2358
+
2348
2359
  styleEl && document.head.removeChild(styleEl);
2349
2360
  rmSubForm();
2350
2361
  data.destroyed = true;
@@ -2358,6 +2369,14 @@ function $FormCreate(FormCreate, components, directives) {
2358
2369
  }, {
2359
2370
  immediate: true
2360
2371
  });
2372
+ watch(function () {
2373
+ return props.option;
2374
+ }, function () {
2375
+ fc.initOptions();
2376
+ fapi.refresh();
2377
+ }, {
2378
+ deep: true
2379
+ });
2361
2380
  watch(function () {
2362
2381
  return _toConsumableArray(rule.value);
2363
2382
  }, function (n) {
@@ -2368,14 +2387,6 @@ function $FormCreate(FormCreate, components, directives) {
2368
2387
  fc.$handle.reloadRule(rule.value);
2369
2388
  vm.setupState.renderRule();
2370
2389
  });
2371
- watch(function () {
2372
- return props.option;
2373
- }, function () {
2374
- fc.initOptions();
2375
- fapi.refresh();
2376
- }, {
2377
- deep: true
2378
- });
2379
2390
  watch(function () {
2380
2391
  return [props.disabled, props.preview];
2381
2392
  }, function () {
@@ -2436,6 +2447,9 @@ function $FormCreate(FormCreate, components, directives) {
2436
2447
 
2437
2448
  if (!parent) {
2438
2449
  emit$topForm();
2450
+ emit$scopeForm();
2451
+ } else if (!subForm.value) {
2452
+ emit$scopeForm();
2439
2453
  }
2440
2454
  });
2441
2455
  }
@@ -3162,6 +3176,20 @@ function Api(h) {
3162
3176
  return api;
3163
3177
  },
3164
3178
 
3179
+ get scope() {
3180
+ var parent = h.vm;
3181
+
3182
+ while (parent && parent.setupState.fapi) {
3183
+ if (!parent.props.subForm) {
3184
+ return parent.setupState.fapi;
3185
+ } else {
3186
+ parent = parent.setupState.parent;
3187
+ }
3188
+ }
3189
+
3190
+ return api.top;
3191
+ },
3192
+
3165
3193
  get children() {
3166
3194
  return allSubForm();
3167
3195
  },
@@ -3192,10 +3220,10 @@ function Api(h) {
3192
3220
  },
3193
3221
 
3194
3222
  formData: function formData(fields) {
3195
- if (fields == null) {
3223
+ if (fields == null || typeof fields === 'boolean') {
3196
3224
  var data = {};
3197
3225
  Object.keys(h.form).forEach(function (k) {
3198
- if (h.ignoreFields.indexOf(k) === -1) {
3226
+ if (fields === true || h.ignoreFields.indexOf(k) === -1) {
3199
3227
  data[k] = copy(h.form[k]);
3200
3228
  }
3201
3229
  });
@@ -3746,7 +3774,11 @@ function Api(h) {
3746
3774
  }, opt.wait == null ? 1000 : opt.wait);
3747
3775
  },
3748
3776
  getData: function getData(id, def) {
3749
- return h.fc.getLoadData(id, def);
3777
+ if (h.fc.get) {
3778
+ return h.fc.get(id, def);
3779
+ } else {
3780
+ return h.fc.getLoadData(id, def);
3781
+ }
3750
3782
  },
3751
3783
  watchData: function watchData(fn) {
3752
3784
  return h.fc.watchLoadData(function (get, change) {
@@ -5304,7 +5336,7 @@ function useLoader(Handler) {
5304
5336
  hideLst[valid ? 'push' : 'unshift'](function () {
5305
5337
  if (method === 'disabled' || method === 'enabled') {
5306
5338
  _this7.api.disabled(!valid, rule);
5307
- } else if (method === 'display') {
5339
+ } else if (method === 'display' || method === 'show') {
5308
5340
  _this7.api.display(valid, rule);
5309
5341
  } else if (method === 'required') {
5310
5342
  rule.forEach(function (item) {
@@ -5314,6 +5346,8 @@ function useLoader(Handler) {
5314
5346
  if (!valid) {
5315
5347
  _this7.api.clearValidateState(rule);
5316
5348
  }
5349
+ } else if (method === 'if') {
5350
+ _this7.api.hidden(!valid, rule);
5317
5351
  } else {
5318
5352
  _this7.api.hidden(!valid, rule);
5319
5353
  }
@@ -5904,8 +5938,10 @@ function useContext(Handler) {
5904
5938
  var match = temp.message.match(/^\{\{\s*\$t\.(.+)\s*\}\}$/);
5905
5939
 
5906
5940
  if (match) {
5941
+ var _ctx$refRule, _ctx$refRule$__$title;
5942
+
5907
5943
  temp.message = _this.api.t(match[1], {
5908
- title: ctx.refRule.__$title.value
5944
+ title: (_ctx$refRule = ctx.refRule) === null || _ctx$refRule === void 0 ? void 0 : (_ctx$refRule$__$title = _ctx$refRule.__$title) === null || _ctx$refRule$__$title === void 0 ? void 0 : _ctx$refRule$__$title.value
5909
5945
  });
5910
5946
  }
5911
5947
  }
@@ -6053,7 +6089,7 @@ function useContext(Handler) {
6053
6089
  });
6054
6090
  } else {
6055
6091
  flag = invoke(function () {
6056
- return new Function('$condition', '$val', '$form', '$group', '$rule', "with($form){with(this){with($group){ return $condition['".concat(one.condition, "'](").concat(field, ", ").concat(compare ? compare : '$val', "); }}}")).call(_this2.api.form, condition, one.value, _this2.api.top.form, group ? _this2.subRuleData[group.id] || {} : {}, ctx.rule);
6092
+ return new Function('$condition', '$val', '$form', '$scope', '$group', '$rule', "with($form){with($scope){with(this){with($group){ return $condition['".concat(one.condition, "'](").concat(field, ", ").concat(compare ? compare : '$val', "); }}}}")).call(_this2.api.form, condition, one.value, _this2.api.top.form, _this2.api.top === _this2.api.scope ? {} : _this2.api.scope.form, group ? _this2.subRuleData[group.id] || {} : {}, ctx.rule);
6057
6093
  });
6058
6094
  }
6059
6095
 
@@ -6121,7 +6157,7 @@ function useContext(Handler) {
6121
6157
 
6122
6158
  return obj;
6123
6159
  }, {});
6124
- return new Function('$formulas', '$form', '$group', '$rule', '$api', "with($form){with(this){with($group){with($formulas){ return ".concat(str, " }}}}")).call(this.api.form, formulas, this.api.top.form, group ? this.subRuleData[group.id] || {} : {}, ctx.rule, this.api);
6160
+ return new Function('$formulas', '$form', '$scope', '$group', '$rule', '$api', "with($form){with($scope){with(this){with($group){with($formulas){ return ".concat(str, " }}}}}")).call(this.api.form, formulas, this.api.top.form, this.api.top === this.api.scope ? {} : this.api.scope.form, group ? this.subRuleData[group.id] || {} : {}, ctx.rule, this.api);
6125
6161
  },
6126
6162
  updateChildren: function updateChildren(ctx, n, o) {
6127
6163
  var _this3 = this;
@@ -6262,8 +6298,11 @@ function useLifecycle(Handler) {
6262
6298
  hook.forEach(function (fn) {
6263
6299
  invoke(function () {
6264
6300
  return fn(_objectSpread2(_objectSpread2({}, args || {}), {}, {
6301
+ self: ctx.rule,
6265
6302
  rule: ctx.rule,
6266
- api: _this2.api
6303
+ $f: _this2.api,
6304
+ api: _this2.api,
6305
+ option: _this2.vm.props.option
6267
6306
  }));
6268
6307
  });
6269
6308
  });
@@ -6517,10 +6556,10 @@ extend(Handler.prototype, {
6517
6556
  isBreakWatch: function isBreakWatch() {
6518
6557
  return this.loading || this.noWatchFn || this.reloading;
6519
6558
  },
6520
- beforeFetch: function beforeFetch(opt) {
6559
+ globalBeforeFetch: function globalBeforeFetch(opt) {
6521
6560
  var _this2 = this;
6522
6561
 
6523
- return new Promise(function (resolve) {
6562
+ return new Promise(function (resolve, reject) {
6524
6563
  var source = _this2.options.beforeFetch && invoke(function () {
6525
6564
  return _this2.options.beforeFetch(opt, {
6526
6565
  api: _this2.api
@@ -6528,10 +6567,31 @@ extend(Handler.prototype, {
6528
6567
  });
6529
6568
 
6530
6569
  if (source && is.Function(source.then)) {
6531
- source.then(resolve);
6570
+ source.then(resolve)["catch"](reject);
6571
+ } else {
6572
+ resolve();
6573
+ }
6574
+ });
6575
+ },
6576
+ beforeFetch: function beforeFetch(opt) {
6577
+ var _this3 = this;
6578
+
6579
+ return new Promise(function (resolve, reject) {
6580
+ var res = opt && opt.beforeFetch && invoke(function () {
6581
+ return opt.beforeFetch(opt, {
6582
+ api: _this3.api
6583
+ });
6584
+ });
6585
+
6586
+ if (res && is.Function(res.then)) {
6587
+ res.then(resolve)["catch"](reject);
6588
+ } else if (res === false) {
6589
+ reject();
6532
6590
  } else {
6533
6591
  resolve();
6534
6592
  }
6593
+ }).then(function () {
6594
+ return _this3.globalBeforeFetch(opt);
6535
6595
  });
6536
6596
  }
6537
6597
  });
@@ -6734,7 +6794,7 @@ var loadData = function loadData(fc) {
6734
6794
  var loadData = {
6735
6795
  name: 'loadData',
6736
6796
  _fn: [],
6737
- loaded: function loaded(inject, rule, api) {
6797
+ mounted: function mounted(inject, rule, api) {
6738
6798
  this.deleted(inject);
6739
6799
  var attrs = toArray(inject.getValue());
6740
6800
  var unwatchs = [];
@@ -7490,6 +7550,7 @@ function FormCreateFactory(config) {
7490
7550
  components: components,
7491
7551
  directives: directives
7492
7552
  },
7553
+ get: null,
7493
7554
  drivers: drivers,
7494
7555
  renderDriver: null,
7495
7556
  refreshData: refreshData,
@@ -7747,9 +7808,11 @@ function FormCreateFactory(config) {
7747
7808
  var key = split.shift();
7748
7809
 
7749
7810
  if (key === '$topForm') {
7750
- val = this.$handle.api.top.formData();
7811
+ val = this.$handle.api.top.formData(true);
7812
+ } else if (key === '$scopeForm') {
7813
+ val = this.$handle.api.scope.formData(true);
7751
7814
  } else if (key === '$form') {
7752
- val = this.$handle.api.formData();
7815
+ val = this.$handle.api.formData(true);
7753
7816
  } else if (key === '$options') {
7754
7817
  val = this.options.value;
7755
7818
  } else if (key === '$globalData') {
@@ -7790,9 +7853,17 @@ function FormCreateFactory(config) {
7790
7853
  var unwatch = {};
7791
7854
 
7792
7855
  var run = function run(flag) {
7856
+ if (!_this6.get) {
7857
+ _this6.get = get;
7858
+ }
7859
+
7793
7860
  invoke(function () {
7794
7861
  fn(get, flag);
7795
7862
  });
7863
+
7864
+ if (_this6.get === get) {
7865
+ _this6.get = undefined;
7866
+ }
7796
7867
  };
7797
7868
 
7798
7869
  var get = function get(id, def) {
@@ -8437,7 +8508,9 @@ var manager = {
8437
8508
  },
8438
8509
  makeInfo: function makeInfo(rule, uni, ctx) {
8439
8510
  var _ctx$refRule,
8511
+ _ctx$refRule$__$title,
8440
8512
  _ctx$refRule2,
8513
+ _ctx$refRule2$__$titl,
8441
8514
  _this5 = this;
8442
8515
 
8443
8516
  var titleProp = _objectSpread2({}, rule.title);
@@ -8448,10 +8521,10 @@ var manager = {
8448
8521
  var form = this.options.form;
8449
8522
  var titleSlot = this.getSlot('title');
8450
8523
  var children = [titleSlot ? titleSlot({
8451
- title: (_ctx$refRule = ctx.refRule) === null || _ctx$refRule === void 0 ? void 0 : _ctx$refRule.__$title.value,
8524
+ title: (_ctx$refRule = ctx.refRule) === null || _ctx$refRule === void 0 ? void 0 : (_ctx$refRule$__$title = _ctx$refRule.__$title) === null || _ctx$refRule$__$title === void 0 ? void 0 : _ctx$refRule$__$title.value,
8452
8525
  rule: ctx.rule,
8453
8526
  options: this.options
8454
- }) : ((_ctx$refRule2 = ctx.refRule) === null || _ctx$refRule2 === void 0 ? void 0 : _ctx$refRule2.__$title.value) + (form.labelSuffix || form['label-suffix'] || '')];
8527
+ }) : ((_ctx$refRule2 = ctx.refRule) === null || _ctx$refRule2 === void 0 ? void 0 : (_ctx$refRule2$__$titl = _ctx$refRule2.__$title) === null || _ctx$refRule2$__$titl === void 0 ? void 0 : _ctx$refRule2$__$titl.value) + (form.labelSuffix || form['label-suffix'] || '')];
8455
8528
 
8456
8529
  if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
8457
8530
  var prop = {
@@ -8467,9 +8540,9 @@ var manager = {
8467
8540
  var field = 'content';
8468
8541
 
8469
8542
  if (infoProp.info && !hasProperty(prop.props, field)) {
8470
- var _ctx$refRule3;
8543
+ var _ctx$refRule3, _ctx$refRule3$__$info;
8471
8544
 
8472
- prop.props[field] = (_ctx$refRule3 = ctx.refRule) === null || _ctx$refRule3 === void 0 ? void 0 : _ctx$refRule3.__$info.value;
8545
+ prop.props[field] = (_ctx$refRule3 = ctx.refRule) === null || _ctx$refRule3 === void 0 ? void 0 : (_ctx$refRule3$__$info = _ctx$refRule3.__$info) === null || _ctx$refRule3$__$info === void 0 ? void 0 : _ctx$refRule3$__$info.value;
8473
8546
  }
8474
8547
 
8475
8548
  children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), _defineProperty({}, titleProp.slot || (isTip ? 'default' : 'reference'), function () {
@@ -8868,6 +8941,8 @@ var required = {
8868
8941
  inject.clearProp();
8869
8942
  api.clearValidateState([rule.field]);
8870
8943
  } else {
8944
+ var _rule$__fc__$refRule$;
8945
+
8871
8946
  var validate = _objectSpread2({
8872
8947
  required: true,
8873
8948
  validator: function validator(_, v, call) {
@@ -8875,7 +8950,7 @@ var required = {
8875
8950
  }
8876
8951
  }, val);
8877
8952
 
8878
- var title = rule.__fc__.refRule.__$title.value;
8953
+ var title = (_rule$__fc__$refRule$ = rule.__fc__.refRule.__$title) === null || _rule$__fc__$refRule$ === void 0 ? void 0 : _rule$__fc__$refRule$.value;
8879
8954
 
8880
8955
  if (!validate.message) {
8881
8956
  validate.message = api.t('required', {
@@ -8948,7 +9023,7 @@ function install(FormCreate) {
8948
9023
  function elmFormCreate() {
8949
9024
  return FormCreateFactory({
8950
9025
  ui: 'element-ui',
8951
- version: '3.2.19',
9026
+ version: '3.2.20',
8952
9027
  manager: manager,
8953
9028
  extendApi: extendApi,
8954
9029
  install: install,