@byteluck-fe/model-driven-engine 2.8.1-alpha.0 → 2.8.1-alpha.11

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.
@@ -902,11 +902,30 @@ var Engine = /*#__PURE__*/ function(Watcher) {
902
902
  {
903
903
  key: "getRules",
904
904
  value: function getRules(controlId) {
905
+ var isGetFieldCodeRules = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
906
+ var controlIdRules = this.runtime.rules;
907
+ var fieldCodeRules = this.runtime.fieldCodeRules;
908
+ var controlIdMapping = this.store.controlIdMapping;
909
+ var rules = isGetFieldCodeRules ? fieldCodeRules : controlIdRules;
905
910
  if (controlId === undefined) {
906
- return this.runtime.rules;
911
+ return isGetFieldCodeRules ? fieldCodeRules : rules;
907
912
  } else {
908
- var _this_runtime_rules_controlId;
909
- return (_this_runtime_rules_controlId = this.runtime.rules[controlId]) === null || _this_runtime_rules_controlId === void 0 ? void 0 : _this_runtime_rules_controlId.fields;
913
+ var _controlIdMapping_controlId, _controlIdMapping_controlId_dataBind, _controlIdMapping_controlId_dataBind1;
914
+ controlId = isGetFieldCodeRules ? ((_controlIdMapping_controlId = controlIdMapping[controlId]) === null || _controlIdMapping_controlId === void 0 ? void 0 : _controlIdMapping_controlId.children) ? (_controlIdMapping_controlId_dataBind = controlIdMapping[controlId].dataBind) === null || _controlIdMapping_controlId_dataBind === void 0 ? void 0 : _controlIdMapping_controlId_dataBind.dataCode : ((_controlIdMapping_controlId_dataBind1 = controlIdMapping[controlId].dataBind) === null || _controlIdMapping_controlId_dataBind1 === void 0 ? void 0 : _controlIdMapping_controlId_dataBind1.fieldCode) || controlId : controlId;
915
+ if (controlId in rules) {
916
+ var _rules_controlId;
917
+ return (_rules_controlId = rules[controlId]) === null || _rules_controlId === void 0 ? void 0 : _rules_controlId.fields;
918
+ }
919
+ var ruleItems;
920
+ for(var id in rules){
921
+ var _rules_id;
922
+ if (controlId in (((_rules_id = rules[id]) === null || _rules_id === void 0 ? void 0 : _rules_id.fields) || {})) {
923
+ var _rules_id_fields, _rules_id1;
924
+ ruleItems = (_rules_id1 = rules[id]) === null || _rules_id1 === void 0 ? void 0 : (_rules_id_fields = _rules_id1.fields) === null || _rules_id_fields === void 0 ? void 0 : _rules_id_fields[controlId];
925
+ break;
926
+ }
927
+ }
928
+ return ruleItems;
910
929
  }
911
930
  }
912
931
  },
@@ -1471,37 +1490,9 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1471
1490
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1472
1491
  if (instances.length) {
1473
1492
  var instance = instances[0];
1474
- // if (this.inList(instance.id) === true) {
1475
- if (this.inList(instance.id) !== undefined) {
1476
- var headerInstance = this.getInstanceInSubtableHeader(instance);
1477
- if (headerInstance) {
1478
- instances.unshift(headerInstance);
1479
- }
1480
- }
1481
- } else {
1482
- var _this_getControlIdMapping;
1483
- var controlIdMapping = (_this_getControlIdMapping = this.getControlIdMapping()) !== null && _this_getControlIdMapping !== void 0 ? _this_getControlIdMapping : {};
1484
- var _Object_entries_find;
1485
- var _ref = _sliced_to_array((_Object_entries_find = Object.entries(controlIdMapping).find(function(param) {
1486
- var _param = _sliced_to_array(param, 2), _ = _param[0], mapping = _param[1];
1487
- return mapping.children && controlId in mapping.children;
1488
- })) !== null && _Object_entries_find !== void 0 ? _Object_entries_find : [], 1), subtableId = _ref[0];
1489
- if (subtableId) {
1490
- var subtable = this.getInstance(subtableId);
1491
- // @ts-ignore
1492
- var headerColumn = subtable.props.headers.find(function(column) {
1493
- return column.children.find(function(item) {
1494
- return item.id === controlId;
1495
- });
1496
- });
1497
- if (headerColumn) {
1498
- var headerInstance1 = headerColumn.children.find(function(item) {
1499
- return item.id === controlId;
1500
- });
1501
- if (headerInstance1) {
1502
- instances.unshift(headerInstance1);
1503
- }
1504
- }
1493
+ var headerInstance = this.findSubtableHeadersControl(instance.id);
1494
+ if (headerInstance !== undefined) {
1495
+ instances.unshift(headerInstance);
1505
1496
  }
1506
1497
  }
1507
1498
  }
@@ -1744,18 +1735,29 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1744
1735
  {
1745
1736
  key: "inList",
1746
1737
  value: function inList(controlId) {
1747
- var _this_store_controlIdMapping;
1748
- var mapping = (_this_store_controlIdMapping = this.store.controlIdMapping) !== null && _this_store_controlIdMapping !== void 0 ? _this_store_controlIdMapping : {};
1749
- var listKey = undefined;
1750
- Object.keys(mapping).some(function(key) {
1751
- var _mapping_key_children, _mapping_key;
1752
- var matched = (_mapping_key = mapping[key]) === null || _mapping_key === void 0 ? void 0 : (_mapping_key_children = _mapping_key.children) === null || _mapping_key_children === void 0 ? void 0 : _mapping_key_children.hasOwnProperty(controlId);
1753
- if (matched) {
1754
- listKey = key;
1738
+ var mapping = this.store.subtableHeadersControlIdMapping;
1739
+ var subtableId = undefined;
1740
+ for(var key in mapping){
1741
+ if (controlId in mapping[key]) {
1742
+ subtableId = key;
1743
+ break;
1755
1744
  }
1756
- return matched;
1757
- });
1758
- return listKey;
1745
+ }
1746
+ return subtableId;
1747
+ }
1748
+ },
1749
+ {
1750
+ key: "findSubtableHeadersControl",
1751
+ value: function findSubtableHeadersControl(controlId) {
1752
+ var mapping = this.store.subtableHeadersControlIdMapping;
1753
+ var instance = undefined;
1754
+ for(var key in mapping){
1755
+ if (controlId in mapping[key]) {
1756
+ instance = mapping[key][controlId];
1757
+ break;
1758
+ }
1759
+ }
1760
+ return instance;
1759
1761
  }
1760
1762
  }
1761
1763
  ], [
@@ -96,7 +96,7 @@ function _create_super(Derived) {
96
96
  return _possible_constructor_return(this, result);
97
97
  };
98
98
  }
99
- import { RegisterControls } from "@byteluck-fe/model-driven-core";
99
+ import { RegisterControls, isDataBind } from "@byteluck-fe/model-driven-core";
100
100
  import { CONTROL_BASE_TYPE, CONTROL_TYPE, JSONCopy, loopFormSchema, isArray } from "@byteluck-fe/model-driven-shared";
101
101
  import { hasChildrenControl, loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
102
102
  export var Runtime = /*#__PURE__*/ function(RegisterControls) {
@@ -224,6 +224,27 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
224
224
  return ruleItems;
225
225
  }
226
226
  },
227
+ {
228
+ key: "fieldCodeRules",
229
+ get: function get() {
230
+ var ruleItems = {};
231
+ loopDataViewControl(this._instance, function(dataView) {
232
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
233
+ // ruleItems[dataView.id] = dataView.rules[0]
234
+ ruleItems[dataView.id] = result[0];
235
+ loopFormControl(dataView.children, function(item) {
236
+ // if (
237
+ // item instanceof RuntimeFormControl ||
238
+ // item instanceof RuntimeListControl
239
+ // ) {
240
+ if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
241
+ buildFieldCodeRules(ruleItems[dataView.id].fields, item);
242
+ }
243
+ });
244
+ });
245
+ return ruleItems;
246
+ }
247
+ },
227
248
  {
228
249
  key: "antdRules",
229
250
  get: function get() {
@@ -324,6 +345,84 @@ item) {
324
345
  data[item.id].push(itemRules);
325
346
  }
326
347
  }
348
+ function buildFieldCodeRules(data, // @ts-ignore
349
+ item) {
350
+ if (getControlIsHide(item)) {
351
+ return;
352
+ }
353
+ var result = Runtime.staticGetRules(item.type, item.props);
354
+ // if (item instanceof RuntimeFormControl) {
355
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
356
+ if (isDataBind(item.props.dataBind)) {
357
+ var _item_props_dataBind;
358
+ if (((_item_props_dataBind = item.props.dataBind) === null || _item_props_dataBind === void 0 ? void 0 : _item_props_dataBind.fieldCode) != "") {
359
+ var _item_props_dataBind1;
360
+ data[(_item_props_dataBind1 = item.props.dataBind) === null || _item_props_dataBind1 === void 0 ? void 0 : _item_props_dataBind1.fieldCode] = result;
361
+ }
362
+ } else {
363
+ for(var dataBindKey in item.props.dataBind){
364
+ var _item_props_dataBind_dataBindKey;
365
+ // @ts-ignore
366
+ if (((_item_props_dataBind_dataBindKey = item.props.dataBind[dataBindKey]) === null || _item_props_dataBind_dataBindKey === void 0 ? void 0 : _item_props_dataBind_dataBindKey.fieldCode) != "") {
367
+ var // @ts-ignore
368
+ _item_props_dataBind_dataBindKey1, _findFields;
369
+ // @ts-ignore
370
+ data[(_item_props_dataBind_dataBindKey1 = item.props.dataBind[dataBindKey]) === null || _item_props_dataBind_dataBindKey1 === void 0 ? void 0 : _item_props_dataBind_dataBindKey1.fieldCode] = ((_findFields = findFields(result)) === null || _findFields === void 0 ? void 0 : _findFields[dataBindKey]) || [];
371
+ }
372
+ }
373
+ }
374
+ } else if (item.type === CONTROL_TYPE.SUBTABLE) {
375
+ var _item_props_datasourceBind, _item_props_datasourceBind1;
376
+ data[(_item_props_datasourceBind = item.props.datasourceBind) === null || _item_props_datasourceBind === void 0 ? void 0 : _item_props_datasourceBind.dataCode] = result;
377
+ var itemRules = {
378
+ type: "array",
379
+ fields: {}
380
+ };
381
+ item.children.forEach(function(row, index) {
382
+ loopFormSchema(row.children, function(formControl) {
383
+ if (itemRules.fields) {
384
+ if (!itemRules.fields[index]) {
385
+ itemRules.fields[index] = {
386
+ type: "object",
387
+ required: true,
388
+ fields: {}
389
+ };
390
+ }
391
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
392
+ if (!isDataBind(formControl.props.dataBind)) {
393
+ for(var dataBindKey in formControl.props.dataBind){
394
+ var _formControl_props_dataBind_dataBindKey;
395
+ // @ts-ignore
396
+ if (((_formControl_props_dataBind_dataBindKey = formControl.props.dataBind[dataBindKey]) === null || _formControl_props_dataBind_dataBindKey === void 0 ? void 0 : _formControl_props_dataBind_dataBindKey.fieldCode) != "") {
397
+ var _findFields;
398
+ // @ts-ignore
399
+ itemRules.fields[index].fields[// @ts-ignore
400
+ formControl.props.dataBind[dataBindKey].fieldCode] = ((_findFields = findFields(childResult)) === null || _findFields === void 0 ? void 0 : _findFields[dataBindKey]) || [];
401
+ }
402
+ }
403
+ } else {
404
+ var _formControl_props_dataBind;
405
+ if (((_formControl_props_dataBind = formControl.props.dataBind) === null || _formControl_props_dataBind === void 0 ? void 0 : _formControl_props_dataBind.fieldCode) != "") {
406
+ var _formControl_props_dataBind1;
407
+ // @ts-ignore
408
+ itemRules.fields[index].fields[(_formControl_props_dataBind1 = formControl.props.dataBind) === null || _formControl_props_dataBind1 === void 0 ? void 0 : _formControl_props_dataBind1.fieldCode] = childResult;
409
+ }
410
+ }
411
+ }
412
+ });
413
+ });
414
+ data[(_item_props_datasourceBind1 = item.props.datasourceBind) === null || _item_props_datasourceBind1 === void 0 ? void 0 : _item_props_datasourceBind1.dataCode].push(itemRules);
415
+ }
416
+ }
417
+ function findFields(childResult) {
418
+ var ruleItem = {};
419
+ childResult.map(function(item) {
420
+ if (item.fields) {
421
+ ruleItem = item;
422
+ }
423
+ });
424
+ return ruleItem === null || ruleItem === void 0 ? void 0 : ruleItem.fields;
425
+ }
327
426
  function buildControlAntdRules(antdRules, // @ts-ignore
328
427
  item) {
329
428
  if (getControlIsHide(item)) {
@@ -57,13 +57,15 @@ var Store = /*#__PURE__*/ function() {
57
57
  _define_property(this, "dataBindMapping", void 0 // 主要提供给二开使用
58
58
  );
59
59
  _define_property(this, "controlIdMapping", void 0);
60
+ _define_property(this, "subtableHeadersControlIdMapping", void 0);
60
61
  _define_property(this, "defaultState", void 0);
61
- var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState;
62
+ var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState, subtableHeadersControlIdMapping = _init.subtableHeadersControlIdMapping;
62
63
  this.emptyState = emptyState;
63
64
  this.state = state;
64
65
  this.dataBindMapping = databindMapping;
65
66
  this.controlIdMapping = controlidMapping;
66
67
  this.defaultState = defaultState;
68
+ this.subtableHeadersControlIdMapping = subtableHeadersControlIdMapping;
67
69
  }
68
70
  _create_class(Store, [
69
71
  {
@@ -233,6 +235,7 @@ function init(instance) {
233
235
  var emptyState = {};
234
236
  var databindMapping = {};
235
237
  var controlidMapping = {};
238
+ var subtableHeadersControlIdMapping = {};
236
239
  var defaultState = {};
237
240
  // loopFormControl(instance, (item, children) => {
238
241
  // })
@@ -248,6 +251,7 @@ function init(instance) {
248
251
  buildState(dataViewState, emptyDataViewState, item);
249
252
  buildDataBindMapping(databindMapping, dvId, item);
250
253
  buildControlIdMapping(controlidMapping, dvId, item);
254
+ buildSubtableHeadersControlIdMapping(subtableHeadersControlIdMapping, item);
251
255
  });
252
256
  state[dvId] = {};
253
257
  defaultState[dvId] = dataViewState;
@@ -256,6 +260,7 @@ function init(instance) {
256
260
  return {
257
261
  state: state,
258
262
  defaultState: defaultState,
263
+ subtableHeadersControlIdMapping: subtableHeadersControlIdMapping,
259
264
  emptyState: emptyState,
260
265
  databindMapping: databindMapping,
261
266
  controlidMapping: controlidMapping
@@ -400,4 +405,17 @@ item) {
400
405
  });
401
406
  }
402
407
  }
408
+ function buildSubtableHeadersControlIdMapping(data, // @ts-ignore
409
+ item) {
410
+ if (item.type === CONTROL_TYPE.SUBTABLE) {
411
+ var headersInstances = {};
412
+ item.props.headers.map(// @ts-ignore
413
+ function(item) {
414
+ item.children.map(function(item) {
415
+ Object.assign(headersInstances, _define_property({}, item.id, item));
416
+ });
417
+ });
418
+ Object.assign(data, _define_property({}, item.id, headersInstances));
419
+ }
420
+ }
403
421
  export { Store };
@@ -69,13 +69,13 @@ function _ts_generator(thisArg, body) {
69
69
  trys: [],
70
70
  ops: []
71
71
  };
72
- return(g = {
72
+ return g = {
73
73
  next: verb(0),
74
74
  "throw": verb(1),
75
75
  "return": verb(2)
76
76
  }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
77
77
  return this;
78
- }), g);
78
+ }), g;
79
79
  function verb(n) {
80
80
  return function(v) {
81
81
  return step([
@@ -115,13 +115,13 @@ function _ts_generator(thisArg, body) {
115
115
  trys: [],
116
116
  ops: []
117
117
  };
118
- return(g = {
118
+ return g = {
119
119
  next: verb(0),
120
120
  "throw": verb(1),
121
121
  "return": verb(2)
122
122
  }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
123
123
  return this;
124
- }), g);
124
+ }), g;
125
125
  function verb(n) {
126
126
  return function(v) {
127
127
  return step([