@byteluck-fe/model-driven-engine 2.8.1-alpha.5 → 2.8.1-alpha.8

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
  },
@@ -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,75 @@ 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;
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] = result[0].fields[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 _childResult_;
398
+ // @ts-ignore
399
+ itemRules.fields[index].fields[// @ts-ignore
400
+ formControl.props.dataBind[dataBindKey].fieldCode] = (_childResult_ = childResult[0]) === null || _childResult_ === void 0 ? void 0 : _childResult_.fields[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
+ }
327
417
  function buildControlAntdRules(antdRules, // @ts-ignore
328
418
  item) {
329
419
  if (getControlIsHide(item)) {