@teamias/rex-design 0.1.24 → 0.1.25

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.
@@ -80,6 +80,20 @@ export default (function () {
80
80
  field: 'category',
81
81
  action: 'clear'
82
82
  }]
83
+ }, {
84
+ valueType: 'select',
85
+ field: 'subProduct',
86
+ label: '商品(依赖请求)',
87
+ tooltip: '开启 dependenciesRequest,类别有值后才发起请求,挂载时不会自动请求',
88
+ api: '/products',
89
+ dependenciesRequest: true,
90
+ dependenciesV2: [{
91
+ field: 'category',
92
+ action: 'updateData'
93
+ }, {
94
+ field: 'category',
95
+ action: 'clear'
96
+ }]
83
97
  }, {
84
98
  valueType: 'input',
85
99
  field: 'showField',
@@ -65,6 +65,25 @@ var getValueTypeMinWidth = function getValueTypeMinWidth(type) {
65
65
  return 100;
66
66
  };
67
67
 
68
+ /**
69
+ * 判断依赖参数是否就绪
70
+ * - dependenciesV2 updateData: 依赖字段未就绪时跳过请求
71
+ */
72
+ var areDependenciesReady = function areDependenciesReady(dependenciesRequest, dependencies, params) {
73
+ if (!dependenciesRequest) return true;
74
+ var updateDataFields = dependencies === null || dependencies === void 0 ? void 0 : dependencies.filter(function (dep) {
75
+ return dep.action === 'updateData';
76
+ }).map(function (dep) {
77
+ return dep.field;
78
+ });
79
+ if (updateDataFields !== null && updateDataFields !== void 0 && updateDataFields.length) {
80
+ return updateDataFields.every(function (k) {
81
+ return params[k] !== undefined && params[k] !== null && params[k] !== '';
82
+ });
83
+ }
84
+ return true;
85
+ };
86
+
68
87
  /** 渲染组件项 */
69
88
  export var renderComponentNode = function renderComponentNode(outConfig, values, form) {
70
89
  var fields = outConfig.fields,
@@ -345,27 +364,33 @@ export var renderComponentNode = function renderComponentNode(outConfig, values,
345
364
  while (1) switch (_context.prev = _context.next) {
346
365
  case 0:
347
366
  _ref5 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, keyWords = _ref5.keyWords, params = _objectWithoutProperties(_ref5, _excluded7);
367
+ if (areDependenciesReady(item.dependenciesRequest, item.dependenciesV2, params)) {
368
+ _context.next = 3;
369
+ break;
370
+ }
371
+ return _context.abrupt("return", []);
372
+ case 3:
348
373
  key = JSON.stringify(params);
349
374
  if (!map[key]) {
350
- _context.next = 4;
375
+ _context.next = 6;
351
376
  break;
352
377
  }
353
378
  return _context.abrupt("return", map[key]);
354
- case 4:
355
- _context.next = 6;
356
- return requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions(item.api, params, item);
357
379
  case 6:
380
+ _context.next = 8;
381
+ return requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions(item.api, params, item);
382
+ case 8:
358
383
  _context.t0 = _context.sent;
359
384
  if (_context.t0) {
360
- _context.next = 9;
385
+ _context.next = 11;
361
386
  break;
362
387
  }
363
388
  _context.t0 = [];
364
- case 9:
389
+ case 11:
365
390
  res = _context.t0;
366
391
  map[key] = res;
367
392
  return _context.abrupt("return", res);
368
- case 12:
393
+ case 14:
369
394
  case "end":
370
395
  return _context.stop();
371
396
  }
@@ -412,7 +437,14 @@ export var renderComponentNode = function renderComponentNode(outConfig, values,
412
437
  case 0:
413
438
  // 拆分参数,keyWords 为搜索关键字,其余为接口参数
414
439
  _params$keyWords = params.keyWords, keyWords = _params$keyWords === void 0 ? '' : _params$keyWords, restParams = _objectWithoutProperties(params, _excluded8);
415
- newParams = restParams; // 处理搜索关键字参数的传递方式
440
+ newParams = restParams;
441
+ if (areDependenciesReady(item.dependenciesRequest, item.dependenciesV2, newParams)) {
442
+ _context2.next = 4;
443
+ break;
444
+ }
445
+ return _context2.abrupt("return", []);
446
+ case 4:
447
+ // 处理搜索关键字参数的传递方式
416
448
  if (item.apiSearchKey === false) {
417
449
  // 配置为 false,默认传 keyWords 字段
418
450
  newParams.keyWords = keyWords || undefined;
@@ -427,7 +459,7 @@ export var renderComponentNode = function renderComponentNode(outConfig, values,
427
459
 
428
460
  // 发起接口请求,返回选项数据
429
461
  return _context2.abrupt("return", (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions(item.api, newParams, item)) || []);
430
- case 4:
462
+ case 6:
431
463
  case "end":
432
464
  return _context2.stop();
433
465
  }
@@ -493,8 +525,14 @@ export var renderComponentNode = function renderComponentNode(outConfig, values,
493
525
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
494
526
  while (1) switch (_context3.prev = _context3.next) {
495
527
  case 0:
528
+ if (areDependenciesReady(item.dependenciesRequest, item.dependenciesV2, params)) {
529
+ _context3.next = 2;
530
+ break;
531
+ }
532
+ return _context3.abrupt("return", []);
533
+ case 2:
496
534
  return _context3.abrupt("return", (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions(item.api, params, item)) || []);
497
- case 1:
535
+ case 3:
498
536
  case "end":
499
537
  return _context3.stop();
500
538
  }
@@ -528,8 +566,14 @@ export var renderComponentNode = function renderComponentNode(outConfig, values,
528
566
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
529
567
  while (1) switch (_context4.prev = _context4.next) {
530
568
  case 0:
569
+ if (areDependenciesReady(item.dependenciesRequest, item.dependenciesV2, params)) {
570
+ _context4.next = 2;
571
+ break;
572
+ }
573
+ return _context4.abrupt("return", []);
574
+ case 2:
531
575
  return _context4.abrupt("return", (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions(item.api, params, item)) || []);
532
- case 1:
576
+ case 3:
533
577
  case "end":
534
578
  return _context4.stop();
535
579
  }
@@ -552,8 +596,14 @@ export var renderComponentNode = function renderComponentNode(outConfig, values,
552
596
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
553
597
  while (1) switch (_context5.prev = _context5.next) {
554
598
  case 0:
599
+ if (areDependenciesReady(item.dependenciesRequest, item.dependenciesV2, params)) {
600
+ _context5.next = 2;
601
+ break;
602
+ }
603
+ return _context5.abrupt("return", []);
604
+ case 2:
555
605
  return _context5.abrupt("return", (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions(item.api, params, item)) || []);
556
- case 1:
606
+ case 3:
557
607
  case "end":
558
608
  return _context5.stop();
559
609
  }
@@ -576,8 +626,14 @@ export var renderComponentNode = function renderComponentNode(outConfig, values,
576
626
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
577
627
  while (1) switch (_context6.prev = _context6.next) {
578
628
  case 0:
629
+ if (areDependenciesReady(item.dependenciesRequest, item.dependenciesV2, params)) {
630
+ _context6.next = 2;
631
+ break;
632
+ }
633
+ return _context6.abrupt("return", []);
634
+ case 2:
579
635
  return _context6.abrupt("return", (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions(item.api, params, item)) || []);
580
- case 1:
636
+ case 3:
581
637
  case "end":
582
638
  return _context6.stop();
583
639
  }
@@ -82,6 +82,8 @@ export interface IBaseFormFieldItem<T extends TValueType = TValueType> {
82
82
  action: Extract<'value' | 'search' | 'visible' | 'disabled', 'search' | 'visible' | 'disabled'>;
83
83
  }>;
84
84
  dependenciesV2?: IDependenciesV2[];
85
+ /** 开启依赖字段有值才触发 request 请求 */
86
+ dependenciesRequest?: boolean;
85
87
  /** 选择项 */
86
88
  options?: Array<TOption>;
87
89
  /** api接口 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamias/rex-design",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",