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

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
  },
@@ -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,47 @@ 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
+ var _item_props_dataBind;
357
+ data[((_item_props_dataBind = item.props.dataBind) === null || _item_props_dataBind === void 0 ? void 0 : _item_props_dataBind.fieldCode) || item.id] = result;
358
+ } else if (item.type === CONTROL_TYPE.SUBTABLE) {
359
+ var _item_props_datasourceBind, _item_props_datasourceBind1;
360
+ data[(_item_props_datasourceBind = item.props.datasourceBind) === null || _item_props_datasourceBind === void 0 ? void 0 : _item_props_datasourceBind.dataCode] = result;
361
+ var itemRules = {
362
+ type: "array",
363
+ fields: {}
364
+ };
365
+ item.children.forEach(function(row, index) {
366
+ loopFormSchema(row.children, function(formControl) {
367
+ if (itemRules.fields) {
368
+ var _formControl_props_dataBind;
369
+ if (!itemRules.fields[index]) {
370
+ itemRules.fields[index] = {
371
+ type: "object",
372
+ required: true,
373
+ fields: {}
374
+ };
375
+ }
376
+ // // @ts-ignore
377
+ // itemRules.fields[index].fields[formControl.id] = (
378
+ // formControl as RuntimeFormControl
379
+ // ).rules
380
+ var childResult = Runtime.staticGetRules(formControl.type, formControl.props);
381
+ // @ts-ignore
382
+ itemRules.fields[index].fields[((_formControl_props_dataBind = formControl.props.dataBind) === null || _formControl_props_dataBind === void 0 ? void 0 : _formControl_props_dataBind.fieldCode) || formControl.id] = childResult;
383
+ }
384
+ });
385
+ });
386
+ data[(_item_props_datasourceBind1 = item.props.datasourceBind) === null || _item_props_datasourceBind1 === void 0 ? void 0 : _item_props_datasourceBind1.dataCode].push(itemRules);
387
+ }
388
+ }
327
389
  function buildControlAntdRules(antdRules, // @ts-ignore
328
390
  item) {
329
391
  if (getControlIsHide(item)) {