@byteluck-fe/model-driven-engine 2.4.1-beta.7 → 2.4.1-beta.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.
@@ -1036,36 +1036,36 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1036
1036
  * @options 传递给关联事件中 EventPayload中的options,一般在plugin中监听使用
1037
1037
  */ key: "setData",
1038
1038
  value: function setData(dataSet, options) {
1039
- var _this6 = this;
1039
+ var _this7 = this;
1040
1040
  this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
1041
1041
  var newState = {};
1042
1042
  Object.keys(dataSet).map(function(dataCode) {
1043
1043
  var entity = dataSet[dataCode];
1044
1044
  if (Array.isArray(entity)) {
1045
- var _this4 = _this6;
1045
+ var _this5 = _this7;
1046
1046
  entity.map(function(row) {
1047
- var _this = _this4;
1048
- var mapping = _this4.getDataBindMapping(dataCode);
1047
+ var _this = _this5;
1048
+ var mapping = _this5.getDataBindMapping(dataCode);
1049
1049
  if (!mapping) {
1050
1050
  return;
1051
1051
  }
1052
- var newRow = JSONCopy(_this4.store.emptyState[mapping.dataViewId][mapping.controlId]);
1052
+ var newRow = JSONCopy(_this5.store.emptyState[mapping.dataViewId][mapping.controlId]);
1053
1053
  var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1054
1054
  ;
1055
1055
  Object.keys(row).map(function(fieldCode) {
1056
- var ref, ref22;
1056
+ var ref, ref24;
1057
1057
  if (skipKey.includes(fieldCode)) {
1058
1058
  return;
1059
1059
  }
1060
- var fieldMapping = (ref = _this.store.dataBindMapping[dataCode]) === null || ref === void 0 ? void 0 : (ref22 = ref.fields) === null || ref22 === void 0 ? void 0 : ref22.find(function(i) {
1060
+ var fieldMapping = (ref = _this.store.dataBindMapping[dataCode]) === null || ref === void 0 ? void 0 : (ref24 = ref.fields) === null || ref24 === void 0 ? void 0 : ref24.find(function(i) {
1061
1061
  return i.fieldCode === fieldCode;
1062
1062
  });
1063
1063
  if (fieldMapping) {
1064
1064
  if (_instanceof(fieldMapping.dataBind, DataBind) && row[fieldCode] !== undefined) {
1065
1065
  newRow[fieldMapping.controlId] = row[fieldCode];
1066
1066
  } else if (_instanceof(fieldMapping.dataBind, ObjectDataBind)) {
1067
- var ref23;
1068
- var objValue = JSONCopy((ref23 = _this.getEmptyState(fieldMapping.controlId)) !== null && ref23 !== void 0 ? ref23 : {});
1067
+ var ref25;
1068
+ var objValue = JSONCopy((ref25 = _this.getEmptyState(fieldMapping.controlId)) !== null && ref25 !== void 0 ? ref25 : {});
1069
1069
  Object.keys(fieldMapping.dataBind).map(function(key) {
1070
1070
  var dataBind = fieldMapping.dataBind[key];
1071
1071
  if (row[dataBind.fieldCode] !== undefined) {
@@ -1086,19 +1086,31 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1086
1086
  newState[mapping.dataViewId][mapping.controlId].push(newRow);
1087
1087
  });
1088
1088
  } else if (entity) {
1089
- var ref24;
1089
+ var ref26;
1090
1090
  var skipKey1 = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1091
1091
  ;
1092
- var emptyState = JSONCopy(_this6.store.emptyState);
1093
- if (!((ref24 = Object.keys(entity)) === null || ref24 === void 0 ? void 0 : ref24.length)) {
1094
- newState = _this6.store.defaultState;
1092
+ var emptyState = JSONCopy(_this7.store.emptyState);
1093
+ if (!((ref26 = Object.keys(entity)) === null || ref26 === void 0 ? void 0 : ref26.length)) {
1094
+ var _this3 = _this7;
1095
+ var ref20;
1096
+ //判断entity 为空对象就给表单赋值默认值
1097
+ newState = JSONCopy(emptyState);
1098
+ var ref21;
1099
+ var dataViewControlId = (ref21 = (ref20 = _this7.getDataBindMapping(dataCode)) === null || ref20 === void 0 ? void 0 : ref20.controlId) !== null && ref21 !== void 0 ? ref21 : '';
1100
+ var _dataViewControlId;
1101
+ var state = (_dataViewControlId = emptyState[dataViewControlId]) !== null && _dataViewControlId !== void 0 ? _dataViewControlId : {};
1102
+ Object.keys(state).map(function(key) {
1103
+ if (_this3.getControlIdMapping()[key].children !== undefined) {
1104
+ newState[dataViewControlId][key] = undefined;
1105
+ }
1106
+ });
1095
1107
  } else {
1096
- var _this3 = _this6;
1108
+ var _this4 = _this7;
1097
1109
  Object.keys(entity).map(function(fieldCode) {
1098
1110
  if (skipKey1.includes(fieldCode)) {
1099
1111
  return;
1100
1112
  }
1101
- var mapping = _this3.getDataBindMapping(dataCode, fieldCode);
1113
+ var mapping = _this4.getDataBindMapping(dataCode, fieldCode);
1102
1114
  if (mapping) {
1103
1115
  if (!newState[mapping.dataViewId[0]]) {
1104
1116
  newState[mapping.dataViewId[0]] = {};
@@ -1107,7 +1119,7 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1107
1119
  newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
1108
1120
  } else if (_instanceof(mapping.dataBind, ObjectDataBind)) {
1109
1121
  var ref;
1110
- var objValue = (ref = _this3.getEmptyState(mapping.controlId)) !== null && ref !== void 0 ? ref : {};
1122
+ var objValue = (ref = _this4.getEmptyState(mapping.controlId)) !== null && ref !== void 0 ? ref : {};
1111
1123
  Object.keys(mapping.dataBind).map(function(key) {
1112
1124
  var dataBind = mapping.dataBind[key];
1113
1125
  if (entity[dataBind.fieldCode] !== undefined) {
@@ -1120,15 +1132,15 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1120
1132
  }
1121
1133
  });
1122
1134
  }
1123
- var newMapping = _this6.getDataBindMapping(dataCode);
1135
+ var newMapping = _this7.getDataBindMapping(dataCode);
1124
1136
  if (newMapping) {
1125
- var ref20;
1126
- var mappingKeys = newMapping === null || newMapping === void 0 ? void 0 : (ref20 = newMapping.fields) === null || ref20 === void 0 ? void 0 : ref20.map(function(item) {
1137
+ var ref22;
1138
+ var mappingKeys = newMapping === null || newMapping === void 0 ? void 0 : (ref22 = newMapping.fields) === null || ref22 === void 0 ? void 0 : ref22.map(function(item) {
1127
1139
  return item === null || item === void 0 ? void 0 : item.controlId;
1128
1140
  });
1129
- var mappingValue = _this6.getEmptyState(newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId);
1130
- var ref21;
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 : {});
1141
+ var mappingValue = _this7.getEmptyState(newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId);
1142
+ var ref23;
1143
+ var mainStateKeys = Object.keys((ref23 = newState === null || newState === void 0 ? void 0 : newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) !== null && ref23 !== void 0 ? ref23 : {});
1132
1144
  mappingKeys === null || mappingKeys === void 0 ? void 0 : mappingKeys.forEach(function(key) {
1133
1145
  if (!mainStateKeys.includes(key) && key !== 'uid' && newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) {
1134
1146
  if (Object.keys(newState).length) {
@@ -1138,7 +1150,7 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1138
1150
  }
1139
1151
  }
1140
1152
  });
1141
- _this6.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
1153
+ _this7.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
1142
1154
  }
1143
1155
  }
1144
1156
  });
@@ -1207,11 +1219,11 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1207
1219
  } else {
1208
1220
  var ref;
1209
1221
  var controlIdMapping = (ref = this.getControlIdMapping()) !== null && ref !== void 0 ? ref : {};
1210
- var ref25;
1211
- var ref26 = _slicedToArray((ref25 = Object.entries(controlIdMapping).find(function(param) {
1222
+ var ref27;
1223
+ var ref28 = _slicedToArray((ref27 = Object.entries(controlIdMapping).find(function(param) {
1212
1224
  var _param = _slicedToArray(param, 2), _ = _param[0], mapping = _param[1];
1213
1225
  return mapping.children && controlId in mapping.children;
1214
- })) !== null && ref25 !== void 0 ? ref25 : [], 1), subtableId = ref26[0];
1226
+ })) !== null && ref27 !== void 0 ? ref27 : [], 1), subtableId = ref28[0];
1215
1227
  if (subtableId) {
1216
1228
  var subtable = this.getInstance(subtableId);
1217
1229
  // @ts-ignore
@@ -1434,8 +1446,8 @@ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
1434
1446
  var _controlIdMapping;
1435
1447
  var mapping = (_controlIdMapping = this.store.controlIdMapping) !== null && _controlIdMapping !== void 0 ? _controlIdMapping : {};
1436
1448
  var result = Object.keys(mapping).some(function(key) {
1437
- var ref, ref27;
1438
- return (ref = mapping[key]) === null || ref === void 0 ? void 0 : (ref27 = ref.children) === null || ref27 === void 0 ? void 0 : ref27.hasOwnProperty(controlId);
1449
+ var ref, ref29;
1450
+ return (ref = mapping[key]) === null || ref === void 0 ? void 0 : (ref29 = ref.children) === null || ref29 === void 0 ? void 0 : ref29.hasOwnProperty(controlId);
1439
1451
  });
1440
1452
  return result;
1441
1453
  }
@@ -44,12 +44,11 @@ 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, defaultState = ref.defaultState;
47
+ var ref = init(props.instance), state = ref.state, emptyState = ref.emptyState, databindMapping = ref.databindMapping, controlidMapping = ref.controlidMapping;
48
48
  this.emptyState = emptyState;
49
49
  this.state = state;
50
50
  this.dataBindMapping = databindMapping;
51
51
  this.controlIdMapping = controlidMapping;
52
- this.defaultState = defaultState;
53
52
  }
54
53
  _createClass(Store, [
55
54
  {
@@ -215,7 +214,6 @@ function init(instance) {
215
214
  var emptyState = {};
216
215
  var databindMapping = {};
217
216
  var controlidMapping = {};
218
- var defaultState = {};
219
217
  // loopFormControl(instance, (item, children) => {
220
218
  // })
221
219
  // @ts-ignore
@@ -231,13 +229,11 @@ function init(instance) {
231
229
  buildDataBindMapping(databindMapping, dvId, item);
232
230
  buildControlIdMapping(controlidMapping, dvId, item);
233
231
  });
234
- state[dvId] = {};
235
- defaultState[dvId] = dataViewState;
232
+ state[dvId] = dataViewState;
236
233
  emptyState[dvId] = emptyDataViewState;
237
234
  });
238
235
  return {
239
236
  state: state,
240
- defaultState: defaultState,
241
237
  emptyState: emptyState,
242
238
  databindMapping: databindMapping,
243
239
  controlidMapping: controlidMapping
@@ -248,7 +244,7 @@ item) {
248
244
  //if (item instanceof RuntimeFormControl) {
249
245
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
250
246
  // 2023-4-2 jiaqi 首次进入页面去除填充默认值
251
- dataViewState[item.id] = JSONCopy(item.props.defaultValue);
247
+ // dataViewState[item.id] = JSONCopy(item.props.defaultValue)
252
248
  emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
253
249
  } else {
254
250
  var emptyTemplate = {};