@byteluck-fe/model-driven-engine 2.4.1-beta.5 → 2.4.1-beta.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.
@@ -860,8 +860,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
860
860
  return data;
861
861
  } else {
862
862
  var _loop = function(key1) {
863
- var ref17, ref8, ref9, ref10;
864
- if ((ref17 = controlIdMapping[key1]) === null || ref17 === void 0 ? void 0 : (ref8 = ref17.dataBind) === null || ref8 === void 0 ? void 0 : ref8.fieldCode) {
863
+ var ref19, ref8, ref9, ref10;
864
+ if ((ref19 = controlIdMapping[key1]) === null || ref19 === void 0 ? void 0 : (ref8 = ref19.dataBind) === null || ref8 === void 0 ? void 0 : ref8.fieldCode) {
865
865
  var ref11;
866
866
  obj1[(ref11 = controlIdMapping[key1]) === null || ref11 === void 0 ? void 0 : ref11.dataBind.fieldCode] = getFieldData[key1];
867
867
  } else if ((ref9 = controlIdMapping[key1]) === null || ref9 === void 0 ? void 0 : (ref10 = ref9.dataBind) === null || ref10 === void 0 ? void 0 : ref10.dataCode) {
@@ -873,12 +873,19 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
873
873
  var ref;
874
874
  if ((ref = controlIdMapping[key1].children[keyChi]) === null || ref === void 0 ? void 0 : ref.dataBind.fieldCode) {
875
875
  var ref15;
876
- objChi[(ref15 = controlIdMapping[key1].children[keyChi]) === null || ref15 === void 0 ? void 0 : ref15.dataBind.fieldCode] = item[keyChi];
876
+ var testKeyObject = objChi[(ref15 = controlIdMapping[key1].children[keyChi]) === null || ref15 === void 0 ? void 0 : ref15.dataBind.fieldCode];
877
+ if (testKeyObject !== undefined) {
878
+ var ref16;
879
+ objChi[(ref16 = controlIdMapping[key1].children[keyChi]) === null || ref16 === void 0 ? void 0 : ref16.dataBind.fieldCode] = item[keyChi];
880
+ }
877
881
  } else {
878
882
  for(var keyChi1 in item[keyChi]){
879
- var ref16;
880
- objChi[(ref16 = controlIdMapping[key1].children[keyChi]) === null || ref16 === void 0 ? void 0 : ref16.dataBind[keyChi1].fieldCode] = item[keyChi][keyChi1];
881
- //
883
+ var ref17;
884
+ var testKeyObject1 = objChi[(ref17 = controlIdMapping[key1].children[keyChi]) === null || ref17 === void 0 ? void 0 : ref17.dataBind[keyChi1].fieldCode];
885
+ if (testKeyObject1 !== undefined) {
886
+ var ref18;
887
+ objChi[(ref18 = controlIdMapping[key1].children[keyChi]) === null || ref18 === void 0 ? void 0 : ref18.dataBind[keyChi1].fieldCode] = item[keyChi][keyChi1];
888
+ }
882
889
  }
883
890
  }
884
891
  }
@@ -1029,20 +1036,20 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1029
1036
  * @options 传递给关联事件中 EventPayload中的options,一般在plugin中监听使用
1030
1037
  */ key: "setData",
1031
1038
  value: function setData(dataSet, options) {
1032
- var _this7 = this;
1039
+ var _this6 = this;
1033
1040
  this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
1034
1041
  var newState = {};
1035
1042
  Object.keys(dataSet).map(function(dataCode) {
1036
1043
  var entity = dataSet[dataCode];
1037
1044
  if (Array.isArray(entity)) {
1038
- var _this5 = _this7;
1045
+ var _this4 = _this6;
1039
1046
  entity.map(function(row) {
1040
- var _this = _this5;
1041
- var mapping = _this5.getDataBindMapping(dataCode);
1047
+ var _this = _this4;
1048
+ var mapping = _this4.getDataBindMapping(dataCode);
1042
1049
  if (!mapping) {
1043
1050
  return;
1044
1051
  }
1045
- var newRow = JSONCopy(_this5.store.emptyState[mapping.dataViewId][mapping.controlId]);
1052
+ var newRow = JSONCopy(_this4.store.emptyState[mapping.dataViewId][mapping.controlId]);
1046
1053
  var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1047
1054
  ;
1048
1055
  Object.keys(row).map(function(fieldCode) {
@@ -1082,28 +1089,16 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1082
1089
  var ref24;
1083
1090
  var skipKey1 = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1084
1091
  ;
1085
- var emptyState = JSONCopy(_this7.store.emptyState);
1092
+ var emptyState = JSONCopy(_this6.store.emptyState);
1086
1093
  if (!((ref24 = Object.keys(entity)) === null || ref24 === void 0 ? void 0 : ref24.length)) {
1087
- var _this3 = _this7;
1088
- var ref18;
1089
- //判断entity 为空对象就给表单赋值默认值
1090
- newState = JSONCopy(emptyState);
1091
- var ref19;
1092
- var dataViewControlId = (ref19 = (ref18 = _this7.getDataBindMapping(dataCode)) === null || ref18 === void 0 ? void 0 : ref18.controlId) !== null && ref19 !== void 0 ? ref19 : '';
1093
- var _dataViewControlId;
1094
- var state = (_dataViewControlId = emptyState[dataViewControlId]) !== null && _dataViewControlId !== void 0 ? _dataViewControlId : {};
1095
- Object.keys(state).map(function(key) {
1096
- if (_this3.getControlIdMapping()[key].children !== undefined) {
1097
- newState[dataViewControlId][key] = undefined;
1098
- }
1099
- });
1094
+ newState = _this6.store.defaultState;
1100
1095
  } else {
1101
- var _this4 = _this7;
1096
+ var _this3 = _this6;
1102
1097
  Object.keys(entity).map(function(fieldCode) {
1103
1098
  if (skipKey1.includes(fieldCode)) {
1104
1099
  return;
1105
1100
  }
1106
- var mapping = _this4.getDataBindMapping(dataCode, fieldCode);
1101
+ var mapping = _this3.getDataBindMapping(dataCode, fieldCode);
1107
1102
  if (mapping) {
1108
1103
  if (!newState[mapping.dataViewId[0]]) {
1109
1104
  newState[mapping.dataViewId[0]] = {};
@@ -1112,7 +1107,7 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1112
1107
  newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
1113
1108
  } else if (_instanceof(mapping.dataBind, ObjectDataBind)) {
1114
1109
  var ref;
1115
- var objValue = (ref = _this4.getEmptyState(mapping.controlId)) !== null && ref !== void 0 ? ref : {};
1110
+ var objValue = (ref = _this3.getEmptyState(mapping.controlId)) !== null && ref !== void 0 ? ref : {};
1116
1111
  Object.keys(mapping.dataBind).map(function(key) {
1117
1112
  var dataBind = mapping.dataBind[key];
1118
1113
  if (entity[dataBind.fieldCode] !== undefined) {
@@ -1125,13 +1120,13 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1125
1120
  }
1126
1121
  });
1127
1122
  }
1128
- var newMapping = _this7.getDataBindMapping(dataCode);
1123
+ var newMapping = _this6.getDataBindMapping(dataCode);
1129
1124
  if (newMapping) {
1130
1125
  var ref20;
1131
1126
  var mappingKeys = newMapping === null || newMapping === void 0 ? void 0 : (ref20 = newMapping.fields) === null || ref20 === void 0 ? void 0 : ref20.map(function(item) {
1132
1127
  return item === null || item === void 0 ? void 0 : item.controlId;
1133
1128
  });
1134
- var mappingValue = _this7.getEmptyState(newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId);
1129
+ var mappingValue = _this6.getEmptyState(newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId);
1135
1130
  var ref21;
1136
1131
  var mainStateKeys = Object.keys((ref21 = newState === null || newState === void 0 ? void 0 : newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) !== null && ref21 !== void 0 ? ref21 : {});
1137
1132
  mappingKeys === null || mappingKeys === void 0 ? void 0 : mappingKeys.forEach(function(key) {
@@ -1143,7 +1138,7 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1143
1138
  }
1144
1139
  }
1145
1140
  });
1146
- _this7.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
1141
+ _this6.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
1147
1142
  }
1148
1143
  }
1149
1144
  });
@@ -44,11 +44,12 @@ var Store = /*#__PURE__*/ function() {
44
44
  "use strict";
45
45
  function Store(props) {
46
46
  _classCallCheck(this, Store);
47
- var ref = init(props.instance), state = ref.state, emptyState = ref.emptyState, databindMapping = ref.databindMapping, controlidMapping = ref.controlidMapping;
47
+ var ref = init(props.instance), state = ref.state, emptyState = ref.emptyState, databindMapping = ref.databindMapping, controlidMapping = ref.controlidMapping, defaultState = ref.defaultState;
48
48
  this.emptyState = emptyState;
49
49
  this.state = state;
50
50
  this.dataBindMapping = databindMapping;
51
51
  this.controlIdMapping = controlidMapping;
52
+ this.defaultState = defaultState;
52
53
  }
53
54
  _createClass(Store, [
54
55
  {
@@ -214,6 +215,7 @@ function init(instance) {
214
215
  var emptyState = {};
215
216
  var databindMapping = {};
216
217
  var controlidMapping = {};
218
+ var defaultState = {};
217
219
  // loopFormControl(instance, (item, children) => {
218
220
  // })
219
221
  // @ts-ignore
@@ -229,11 +231,13 @@ function init(instance) {
229
231
  buildDataBindMapping(databindMapping, dvId, item);
230
232
  buildControlIdMapping(controlidMapping, dvId, item);
231
233
  });
232
- state[dvId] = dataViewState;
234
+ state[dvId] = {};
235
+ defaultState[dvId] = dataViewState;
233
236
  emptyState[dvId] = emptyDataViewState;
234
237
  });
235
238
  return {
236
239
  state: state,
240
+ defaultState: defaultState,
237
241
  emptyState: emptyState,
238
242
  databindMapping: databindMapping,
239
243
  controlidMapping: controlidMapping
@@ -244,7 +248,7 @@ item) {
244
248
  //if (item instanceof RuntimeFormControl) {
245
249
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
246
250
  // 2023-4-2 jiaqi 首次进入页面去除填充默认值
247
- // dataViewState[item.id] = JSONCopy(item.props.defaultValue)
251
+ dataViewState[item.id] = JSONCopy(item.props.defaultValue);
248
252
  emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
249
253
  } else {
250
254
  var emptyTemplate = {};