@byteluck-fe/model-driven-engine 2.8.1-alpha.1 → 2.8.1-alpha.12

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,35 +1490,10 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1471
1490
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1472
1491
  if (instances.length) {
1473
1492
  var instance = instances[0];
1474
- var headerInstance = this.getInstanceInSubtableHeader(instance);
1475
- if (headerInstance) {
1493
+ var headerInstance = this.findSubtableHeadersControl(instance.id);
1494
+ if (headerInstance !== undefined) {
1476
1495
  instances.unshift(headerInstance);
1477
1496
  }
1478
- } else {
1479
- var _this_getControlIdMapping;
1480
- var controlIdMapping = (_this_getControlIdMapping = this.getControlIdMapping()) !== null && _this_getControlIdMapping !== void 0 ? _this_getControlIdMapping : {};
1481
- var _Object_entries_find;
1482
- var _ref = _sliced_to_array((_Object_entries_find = Object.entries(controlIdMapping).find(function(param) {
1483
- var _param = _sliced_to_array(param, 2), _ = _param[0], mapping = _param[1];
1484
- return mapping.children && controlId in mapping.children;
1485
- })) !== null && _Object_entries_find !== void 0 ? _Object_entries_find : [], 1), subtableId = _ref[0];
1486
- if (subtableId) {
1487
- var subtable = this.getInstance(subtableId);
1488
- // @ts-ignore
1489
- var headerColumn = subtable.props.headers.find(function(column) {
1490
- return column.children.find(function(item) {
1491
- return item.id === controlId;
1492
- });
1493
- });
1494
- if (headerColumn) {
1495
- var headerInstance1 = headerColumn.children.find(function(item) {
1496
- return item.id === controlId;
1497
- });
1498
- if (headerInstance1) {
1499
- instances.unshift(headerInstance1);
1500
- }
1501
- }
1502
- }
1503
1497
  }
1504
1498
  }
1505
1499
  // @ts-ignore
@@ -1741,18 +1735,29 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1741
1735
  {
1742
1736
  key: "inList",
1743
1737
  value: function inList(controlId) {
1744
- var _this_store_controlIdMapping;
1745
- var mapping = (_this_store_controlIdMapping = this.store.controlIdMapping) !== null && _this_store_controlIdMapping !== void 0 ? _this_store_controlIdMapping : {};
1746
- var listKey = undefined;
1747
- Object.keys(mapping).some(function(key) {
1748
- var _mapping_key_children, _mapping_key;
1749
- 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);
1750
- if (matched) {
1751
- 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;
1752
1744
  }
1753
- return matched;
1754
- });
1755
- 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;
1756
1761
  }
1757
1762
  }
1758
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) {
@@ -180,26 +180,33 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
180
180
  {
181
181
  key: "allRules",
182
182
  get: function get() {
183
- var antdRules = {};
184
- var ruleItems = {};
183
+ var defaultAntdRules = {};
184
+ var defaultRule = {};
185
+ var defaultFieldRules = {};
185
186
  loopDataViewControl(this._instance, function(dataView) {
186
187
  var result = Runtime.staticGetRules(dataView.type, dataView.props);
187
- ruleItems[dataView.id] = JSONCopy(result[0]);
188
- antdRules[dataView.id] = JSONCopy(result[0]);
188
+ defaultRule[dataView.id] = JSONCopy(result[0]);
189
+ defaultAntdRules[dataView.id] = JSONCopy(result[0]);
190
+ defaultFieldRules[dataView.id] = JSONCopy(result[0]);
189
191
  loopFormControl(dataView.children, function(item) {
190
192
  // if (
191
193
  // item instanceof RuntimeFormControl ||
192
194
  // item instanceof RuntimeListControl
193
195
  // ) {
194
196
  if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
195
- buildControlRules(ruleItems[dataView.id].fields, item);
196
- buildControlAntdRules(antdRules[dataView.id].fields, item);
197
+ buildControlRules(defaultRule[dataView.id].fields, item, true);
198
+ buildControlAntdRules(defaultAntdRules[dataView.id].fields, item, true);
199
+ buildFieldCodeRules(defaultFieldRules[dataView.id].fields, item, true);
197
200
  }
198
201
  });
199
202
  });
200
203
  return {
201
- rules: ruleItems,
202
- antdRules: antdRules
204
+ rules: this.rules,
205
+ antdRules: this.antdRules,
206
+ fieldCodeRules: this.fieldCodeRules,
207
+ defaultAntdRules: defaultAntdRules,
208
+ defaultRule: defaultRule,
209
+ defaultFieldRules: defaultFieldRules
203
210
  };
204
211
  }
205
212
  },
@@ -224,6 +231,27 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
224
231
  return ruleItems;
225
232
  }
226
233
  },
234
+ {
235
+ key: "fieldCodeRules",
236
+ get: function get() {
237
+ var ruleItems = {};
238
+ loopDataViewControl(this._instance, function(dataView) {
239
+ var result = Runtime.staticGetRules(dataView.type, dataView.props);
240
+ // ruleItems[dataView.id] = dataView.rules[0]
241
+ ruleItems[dataView.id] = result[0];
242
+ loopFormControl(dataView.children, function(item) {
243
+ // if (
244
+ // item instanceof RuntimeFormControl ||
245
+ // item instanceof RuntimeListControl
246
+ // ) {
247
+ if (item.controlType === CONTROL_BASE_TYPE.FORM || item.controlType === CONTROL_BASE_TYPE.LIST) {
248
+ buildFieldCodeRules(ruleItems[dataView.id].fields, item);
249
+ }
250
+ });
251
+ });
252
+ return ruleItems;
253
+ }
254
+ },
227
255
  {
228
256
  key: "antdRules",
229
257
  get: function get() {
@@ -286,6 +314,7 @@ function hasHeaderOrFooterControl(control, checkType) {
286
314
  }
287
315
  function buildControlRules(data, // @ts-ignore
288
316
  item) {
317
+ var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
289
318
  if (getControlIsHide(item)) {
290
319
  return;
291
320
  }
@@ -301,7 +330,11 @@ item) {
301
330
  type: "array",
302
331
  fields: {}
303
332
  };
304
- item.children.forEach(function(row, index) {
333
+ (isSubtableDefaultRules === true ? [
334
+ {
335
+ children: item.props.headers
336
+ }
337
+ ] : item.children).forEach(function(row, index) {
305
338
  loopFormSchema(row.children, function(formControl) {
306
339
  if (itemRules.fields) {
307
340
  if (!itemRules.fields[index]) {
@@ -324,8 +357,92 @@ item) {
324
357
  data[item.id].push(itemRules);
325
358
  }
326
359
  }
360
+ function buildFieldCodeRules(data, // @ts-ignore
361
+ item) {
362
+ var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
363
+ if (getControlIsHide(item)) {
364
+ return;
365
+ }
366
+ var result = Runtime.staticGetRules(item.type, item.props);
367
+ // if (item instanceof RuntimeFormControl) {
368
+ if (item.controlType === CONTROL_BASE_TYPE.FORM) {
369
+ if (isDataBind(item.props.dataBind)) {
370
+ var _item_props_dataBind;
371
+ if (((_item_props_dataBind = item.props.dataBind) === null || _item_props_dataBind === void 0 ? void 0 : _item_props_dataBind.fieldCode) != "") {
372
+ var _item_props_dataBind1;
373
+ data[(_item_props_dataBind1 = item.props.dataBind) === null || _item_props_dataBind1 === void 0 ? void 0 : _item_props_dataBind1.fieldCode] = result;
374
+ }
375
+ } else {
376
+ for(var dataBindKey in item.props.dataBind){
377
+ var _item_props_dataBind_dataBindKey;
378
+ // @ts-ignore
379
+ if (((_item_props_dataBind_dataBindKey = item.props.dataBind[dataBindKey]) === null || _item_props_dataBind_dataBindKey === void 0 ? void 0 : _item_props_dataBind_dataBindKey.fieldCode) != "") {
380
+ var // @ts-ignore
381
+ _item_props_dataBind_dataBindKey1, _findFields;
382
+ // @ts-ignore
383
+ 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]) || [];
384
+ }
385
+ }
386
+ }
387
+ } else if (item.type === CONTROL_TYPE.SUBTABLE) {
388
+ var _item_props_datasourceBind, _item_props_datasourceBind1;
389
+ data[(_item_props_datasourceBind = item.props.datasourceBind) === null || _item_props_datasourceBind === void 0 ? void 0 : _item_props_datasourceBind.dataCode] = result;
390
+ var itemRules = {
391
+ type: "array",
392
+ fields: {}
393
+ };
394
+ (isSubtableDefaultRules === true ? [
395
+ {
396
+ children: item.props.headers
397
+ }
398
+ ] : item.children).forEach(function(row, index) {
399
+ loopFormSchema(row.children, function(formControl) {
400
+ if (itemRules.fields) {
401
+ if (!itemRules.fields[index]) {
402
+ itemRules.fields[index] = {
403
+ type: "object",
404
+ required: true,
405
+ fields: {}
406
+ };
407
+ }
408
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
409
+ if (!isDataBind(formControl.props.dataBind)) {
410
+ for(var dataBindKey in formControl.props.dataBind){
411
+ var _formControl_props_dataBind_dataBindKey;
412
+ // @ts-ignore
413
+ if (((_formControl_props_dataBind_dataBindKey = formControl.props.dataBind[dataBindKey]) === null || _formControl_props_dataBind_dataBindKey === void 0 ? void 0 : _formControl_props_dataBind_dataBindKey.fieldCode) != "") {
414
+ var _findFields;
415
+ // @ts-ignore
416
+ itemRules.fields[index].fields[// @ts-ignore
417
+ formControl.props.dataBind[dataBindKey].fieldCode] = ((_findFields = findFields(childResult)) === null || _findFields === void 0 ? void 0 : _findFields[dataBindKey]) || [];
418
+ }
419
+ }
420
+ } else {
421
+ var _formControl_props_dataBind;
422
+ if (((_formControl_props_dataBind = formControl.props.dataBind) === null || _formControl_props_dataBind === void 0 ? void 0 : _formControl_props_dataBind.fieldCode) != "") {
423
+ var _formControl_props_dataBind1;
424
+ // @ts-ignore
425
+ itemRules.fields[index].fields[(_formControl_props_dataBind1 = formControl.props.dataBind) === null || _formControl_props_dataBind1 === void 0 ? void 0 : _formControl_props_dataBind1.fieldCode] = childResult;
426
+ }
427
+ }
428
+ }
429
+ });
430
+ });
431
+ data[(_item_props_datasourceBind1 = item.props.datasourceBind) === null || _item_props_datasourceBind1 === void 0 ? void 0 : _item_props_datasourceBind1.dataCode].push(itemRules);
432
+ }
433
+ }
434
+ function findFields(childResult) {
435
+ var ruleItem = {};
436
+ childResult.map(function(item) {
437
+ if (item.fields) {
438
+ ruleItem = item;
439
+ }
440
+ });
441
+ return ruleItem === null || ruleItem === void 0 ? void 0 : ruleItem.fields;
442
+ }
327
443
  function buildControlAntdRules(antdRules, // @ts-ignore
328
444
  item) {
445
+ var isSubtableDefaultRules = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
329
446
  if (getControlIsHide(item)) {
330
447
  return;
331
448
  }
@@ -336,7 +453,11 @@ item) {
336
453
  antdRules[item.id] = result;
337
454
  } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
338
455
  antdRules[item.id] = [];
339
- item.children.forEach(function(row) {
456
+ (isSubtableDefaultRules === true ? [
457
+ {
458
+ children: item.props.headers
459
+ }
460
+ ] : item.children).forEach(function(row) {
340
461
  var rules = {};
341
462
  loopFormSchema(row.children, function(formControl) {
342
463
  // rules[formControl.id] = (formControl as RuntimeFormControl).rules
@@ -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 };