@byteluck-fe/model-driven-engine 2.5.0-alpha.9 → 2.5.0-beta.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.
@@ -495,7 +495,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
495
495
  }, {});
496
496
  // @ts-ignore
497
497
  var emptyState = this.getEmptyState(instance.id);
498
- return newValue.map(function(row) {
498
+ return newValue === null || newValue === void 0 ? void 0 : newValue.map(function(row) {
499
499
  return(// @ts-ignore
500
500
  checkerSubtableValue(fieldTypeMap, row, emptyState));
501
501
  });
@@ -901,7 +901,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
901
901
  */ key: "setStates",
902
902
  value: function setStates(states, rowIndex, options) {
903
903
  var _this = this;
904
- var newStates = states;
904
+ var newStates = states !== null && states !== void 0 ? states : {};
905
905
  Object.keys(newStates).forEach(function(stateId) {
906
906
  Object.entries(_this.store.controlIdMapping).forEach(function(param) {
907
907
  var _param = _slicedToArray(param, 2), controlId = _param[0], controlIdMapping = _param[1];
@@ -973,15 +973,19 @@ var Engine = /*#__PURE__*/ function(Watcher) {
973
973
  var data = getFieldData.map(function(item) {
974
974
  var obj = {};
975
975
  for(var key in item){
976
- var _controlIdMapping_controlId_children_key, _controlIdMapping_controlId, _controlIdMapping_controlId_children_key_dataBind, _controlIdMapping_controlId1;
977
- if ((_controlIdMapping_controlId_children_key = (_controlIdMapping_controlId = controlIdMapping[controlId]) === null || _controlIdMapping_controlId === void 0 ? void 0 : _controlIdMapping_controlId.children[key]) === null || _controlIdMapping_controlId_children_key === void 0 ? void 0 : (_controlIdMapping_controlId_children_key_dataBind = _controlIdMapping_controlId_children_key.dataBind) === null || _controlIdMapping_controlId_children_key_dataBind === void 0 ? void 0 : _controlIdMapping_controlId_children_key_dataBind.fieldCode) {
978
- var _controlIdMapping_controlId_children_key1;
979
- obj[(_controlIdMapping_controlId_children_key1 = controlIdMapping[controlId].children[key]) === null || _controlIdMapping_controlId_children_key1 === void 0 ? void 0 : _controlIdMapping_controlId_children_key1.dataBind.fieldCode] = item[key];
980
- } else if ((_controlIdMapping_controlId1 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId1 === void 0 ? void 0 : _controlIdMapping_controlId1.children[key]) {
981
- // 兼容一个控件需要绑定多个字段的情况
982
- for(var keyChi in item[key]){
983
- var _controlIdMapping_controlId_children_key2, _controlIdMapping_controlId2;
984
- obj[(_controlIdMapping_controlId_children_key2 = (_controlIdMapping_controlId2 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId2 === void 0 ? void 0 : _controlIdMapping_controlId2.children[key]) === null || _controlIdMapping_controlId_children_key2 === void 0 ? void 0 : _controlIdMapping_controlId_children_key2.dataBind[keyChi].fieldCode] = item[key][keyChi];
976
+ var _controlIdMapping_controlId_children_key, _controlIdMapping_controlId, _controlIdMapping_controlId_children_key_dataBind;
977
+ var fieldCode = (_controlIdMapping_controlId_children_key = (_controlIdMapping_controlId = controlIdMapping[controlId]) === null || _controlIdMapping_controlId === void 0 ? void 0 : _controlIdMapping_controlId.children[key]) === null || _controlIdMapping_controlId_children_key === void 0 ? void 0 : (_controlIdMapping_controlId_children_key_dataBind = _controlIdMapping_controlId_children_key.dataBind) === null || _controlIdMapping_controlId_children_key_dataBind === void 0 ? void 0 : _controlIdMapping_controlId_children_key_dataBind.fieldCode;
978
+ //未绑定字段的控件,直接抛弃
979
+ if (fieldCode !== "") {
980
+ var _controlIdMapping_controlId1;
981
+ if (fieldCode) {
982
+ obj[fieldCode] = item[key];
983
+ } else if ((_controlIdMapping_controlId1 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId1 === void 0 ? void 0 : _controlIdMapping_controlId1.children[key]) {
984
+ // 兼容一个控件需要绑定多个字段的情况
985
+ for(var keyChi in item[key]){
986
+ var _controlIdMapping_controlId_children_key1, _controlIdMapping_controlId2;
987
+ obj[(_controlIdMapping_controlId_children_key1 = (_controlIdMapping_controlId2 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId2 === void 0 ? void 0 : _controlIdMapping_controlId2.children[key]) === null || _controlIdMapping_controlId_children_key1 === void 0 ? void 0 : _controlIdMapping_controlId_children_key1.dataBind[keyChi].fieldCode] = item[key][keyChi];
988
+ }
985
989
  }
986
990
  }
987
991
  }
@@ -1001,14 +1005,16 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1001
1005
  var objChi = {};
1002
1006
  for(var keyChi in item){
1003
1007
  var _controlIdMapping_key_children_keyChi;
1004
- if ((_controlIdMapping_key_children_keyChi = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi === void 0 ? void 0 : _controlIdMapping_key_children_keyChi.dataBind.fieldCode) {
1005
- var _controlIdMapping_key_children_keyChi1;
1006
- objChi[(_controlIdMapping_key_children_keyChi1 = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi1 === void 0 ? void 0 : _controlIdMapping_key_children_keyChi1.dataBind.fieldCode] = item[keyChi];
1007
- } else {
1008
- for(var keyChi1 in item[keyChi]){
1009
- var _controlIdMapping_key_children_keyChi2;
1010
- objChi[(_controlIdMapping_key_children_keyChi2 = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi2 === void 0 ? void 0 : _controlIdMapping_key_children_keyChi2.dataBind[keyChi1].fieldCode] = item[keyChi][keyChi1];
1011
- //
1008
+ var fieldCode = (_controlIdMapping_key_children_keyChi = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi === void 0 ? void 0 : _controlIdMapping_key_children_keyChi.dataBind.fieldCode;
1009
+ //未绑定字段的控件,直接抛弃
1010
+ if (fieldCode !== "") {
1011
+ if (fieldCode) {
1012
+ objChi[fieldCode] = item[keyChi];
1013
+ } else {
1014
+ for(var keyChi1 in item[keyChi]){
1015
+ var _controlIdMapping_key_children_keyChi1;
1016
+ objChi[(_controlIdMapping_key_children_keyChi1 = controlIdMapping[key].children[keyChi]) === null || _controlIdMapping_key_children_keyChi1 === void 0 ? void 0 : _controlIdMapping_key_children_keyChi1.dataBind[keyChi1].fieldCode] = item[keyChi][keyChi1];
1017
+ }
1012
1018
  }
1013
1019
  }
1014
1020
  }
@@ -1161,21 +1167,19 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1161
1167
  value: function setData(dataSet, options) {
1162
1168
  var _this = this;
1163
1169
  this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
1164
- var isEmpty = function(value) {
1165
- if (isString(value) || Array.isArray(value)) {
1166
- return value.length === 0;
1167
- }
1168
- return false;
1169
- };
1170
- var newState = {};
1170
+ var newState = this.store.defaultState;
1171
1171
  Object.keys(dataSet).map(function(dataCode) {
1172
1172
  var entity = dataSet[dataCode];
1173
1173
  if (Array.isArray(entity)) {
1174
+ var mapping = _this.getDataBindMapping(dataCode);
1175
+ if (!mapping) {
1176
+ return;
1177
+ }
1178
+ if (!newState[mapping.dataViewId]) {
1179
+ newState[mapping.dataViewId] = {};
1180
+ }
1181
+ newState[mapping.dataViewId][mapping.controlId] = [];
1174
1182
  entity.map(function(row) {
1175
- var mapping = _this.getDataBindMapping(dataCode);
1176
- if (!mapping) {
1177
- return;
1178
- }
1179
1183
  var newRow = JSONCopy(_this.store.emptyState[mapping.dataViewId][mapping.controlId]);
1180
1184
  var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1181
1185
  ;
@@ -1204,43 +1208,42 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1204
1208
  }
1205
1209
  }
1206
1210
  });
1207
- if (!newState[mapping.dataViewId]) {
1208
- newState[mapping.dataViewId] = {};
1209
- }
1210
- if (!newState[mapping.dataViewId][mapping.controlId]) {
1211
- newState[mapping.dataViewId][mapping.controlId] = [];
1212
- }
1213
1211
  newState[mapping.dataViewId][mapping.controlId].push(newRow);
1214
1212
  });
1215
1213
  } else if (entity) {
1214
+ var _Object_keys;
1216
1215
  var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1217
1216
  ;
1218
1217
  var emptyState = JSONCopy(_this.store.emptyState);
1219
- Object.keys(entity).map(function(fieldCode) {
1220
- if (skipKey.includes(fieldCode)) {
1221
- return;
1222
- }
1223
- var mapping = _this.getDataBindMapping(dataCode, fieldCode);
1224
- if (mapping) {
1225
- if (!newState[mapping.dataViewId[0]]) {
1226
- newState[mapping.dataViewId[0]] = {};
1218
+ if (!((_Object_keys = Object.keys(entity)) === null || _Object_keys === void 0 ? void 0 : _Object_keys.length)) {
1219
+ // newState = this.store.defaultState
1220
+ } else {
1221
+ Object.keys(entity).map(function(fieldCode) {
1222
+ if (skipKey.includes(fieldCode)) {
1223
+ return;
1227
1224
  }
1228
- if (_instanceof(mapping.dataBind, DataBind) && entity[fieldCode] !== undefined) {
1229
- newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
1230
- } else if (_instanceof(mapping.dataBind, ObjectDataBind)) {
1231
- var _this_getEmptyState;
1232
- var objValue = (_this_getEmptyState = _this.getEmptyState(mapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {};
1233
- Object.keys(mapping.dataBind).map(function(key) {
1234
- var dataBind = mapping.dataBind[key];
1235
- if (entity[dataBind.fieldCode] !== undefined) {
1236
- objValue[key] = entity[dataBind.fieldCode];
1237
- }
1238
- skipKey.push(dataBind.fieldCode);
1239
- });
1240
- newState[mapping.dataViewId[0]][mapping.controlId] = objValue;
1225
+ var mapping = _this.getDataBindMapping(dataCode, fieldCode);
1226
+ if (mapping) {
1227
+ if (!newState[mapping.dataViewId[0]]) {
1228
+ newState[mapping.dataViewId[0]] = {};
1229
+ }
1230
+ if (_instanceof(mapping.dataBind, DataBind) && entity[fieldCode] !== undefined) {
1231
+ newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
1232
+ } else if (_instanceof(mapping.dataBind, ObjectDataBind)) {
1233
+ var _this_getEmptyState;
1234
+ var objValue = (_this_getEmptyState = _this.getEmptyState(mapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {};
1235
+ Object.keys(mapping.dataBind).map(function(key) {
1236
+ var dataBind = mapping.dataBind[key];
1237
+ if (entity[dataBind.fieldCode] !== undefined) {
1238
+ objValue[key] = entity[dataBind.fieldCode];
1239
+ }
1240
+ skipKey.push(dataBind.fieldCode);
1241
+ });
1242
+ newState[mapping.dataViewId[0]][mapping.controlId] = objValue;
1243
+ }
1241
1244
  }
1242
- }
1243
- });
1245
+ });
1246
+ }
1244
1247
  var newMapping = _this.getDataBindMapping(dataCode);
1245
1248
  if (newMapping) {
1246
1249
  var _newMapping_fields;
@@ -1251,8 +1254,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1251
1254
  var _newState_newMapping_controlId;
1252
1255
  var mainStateKeys = Object.keys((_newState_newMapping_controlId = newState === null || newState === void 0 ? void 0 : newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) !== null && _newState_newMapping_controlId !== void 0 ? _newState_newMapping_controlId : {});
1253
1256
  mappingKeys === null || mappingKeys === void 0 ? void 0 : mappingKeys.forEach(function(key) {
1254
- if (!mainStateKeys.includes(key) && key !== "uid") {
1255
- if (Object.keys(newState).length && newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) {
1257
+ if (!mainStateKeys.includes(key) && key !== "uid" && newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) {
1258
+ if (Object.keys(newState).length) {
1256
1259
  Object.assign(newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId], _defineProperty({}, key, mappingValue[key]));
1257
1260
  } else {
1258
1261
  Object.assign(newState, _defineProperty({}, newMapping.controlId, _defineProperty({}, key, mappingValue[key])));
@@ -1319,14 +1322,15 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1319
1322
  // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1320
1323
  if (instances.length) {
1321
1324
  var instance = instances[0];
1322
- if (this.inList(instance.id) === true) {
1325
+ if (this.inList(instance.id) !== undefined) {
1323
1326
  var headerInstance = this.getInstanceInSubtableHeader(instance);
1324
1327
  if (headerInstance) {
1325
1328
  instances.unshift(headerInstance);
1326
1329
  }
1327
1330
  }
1328
1331
  } else {
1329
- var controlIdMapping = this.getControlIdMapping();
1332
+ var _this_getControlIdMapping;
1333
+ var controlIdMapping = (_this_getControlIdMapping = this.getControlIdMapping()) !== null && _this_getControlIdMapping !== void 0 ? _this_getControlIdMapping : {};
1330
1334
  var _Object_entries_find;
1331
1335
  var _ref = _slicedToArray((_Object_entries_find = Object.entries(controlIdMapping).find(function(param) {
1332
1336
  var _param = _slicedToArray(param, 2), _ = _param[0], mapping = _param[1];
@@ -1551,12 +1555,18 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1551
1555
  {
1552
1556
  key: "inList",
1553
1557
  value: function inList(controlId) {
1554
- var mapping = this.store.controlIdMapping;
1555
- var result = Object.keys(mapping).some(function(key) {
1558
+ var _this_store_controlIdMapping;
1559
+ var mapping = (_this_store_controlIdMapping = this.store.controlIdMapping) !== null && _this_store_controlIdMapping !== void 0 ? _this_store_controlIdMapping : {};
1560
+ var listKey = undefined;
1561
+ Object.keys(mapping).some(function(key) {
1556
1562
  var _mapping_key, _mapping_key_children;
1557
- return (_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);
1563
+ 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);
1564
+ if (matched) {
1565
+ listKey = key;
1566
+ }
1567
+ return matched;
1558
1568
  });
1559
- return result;
1569
+ return listKey;
1560
1570
  }
1561
1571
  }
1562
1572
  ], [
@@ -1581,4 +1591,3 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1581
1591
  return Engine;
1582
1592
  }(Watcher);
1583
1593
  export { Engine };
1584
- console.log("a");
@@ -37,6 +37,21 @@ function _instanceof(left, right) {
37
37
  return left instanceof right;
38
38
  }
39
39
  }
40
+ function _objectSpread(target) {
41
+ for(var i = 1; i < arguments.length; i++){
42
+ var source = arguments[i] != null ? arguments[i] : {};
43
+ var ownKeys = Object.keys(source);
44
+ if (typeof Object.getOwnPropertySymbols === "function") {
45
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
46
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
47
+ }));
48
+ }
49
+ ownKeys.forEach(function(key) {
50
+ _defineProperty(target, key, source[key]);
51
+ });
52
+ }
53
+ return target;
54
+ }
40
55
  import { DataBind, ObjectDataBind } from "@byteluck-fe/model-driven-core";
41
56
  import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from "@byteluck-fe/model-driven-shared";
42
57
  import { loopDataViewControl, loopFormControl, buildUUID } from "../utils/runtimeUtils";
@@ -49,11 +64,13 @@ var Store = /*#__PURE__*/ function() {
49
64
  _defineProperty(this, "dataBindMapping", void 0 // 主要提供给二开使用
50
65
  );
51
66
  _defineProperty(this, "controlIdMapping", void 0);
52
- var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping;
67
+ _defineProperty(this, "defaultState", void 0);
68
+ var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState;
53
69
  this.emptyState = emptyState;
54
70
  this.state = state;
55
71
  this.dataBindMapping = databindMapping;
56
72
  this.controlIdMapping = controlidMapping;
73
+ this.defaultState = defaultState;
57
74
  }
58
75
  _createClass(Store, [
59
76
  {
@@ -85,7 +102,9 @@ var Store = /*#__PURE__*/ function() {
85
102
  if (children !== undefined) {
86
103
  Object.keys(children).map(function(childControlId) {
87
104
  if (childControlId === controlId) {
88
- _this.state[dataView][subtableId][rowIndex][controlId] = value;
105
+ if (_this.state[dataView][subtableId][rowIndex]) {
106
+ _this.state[dataView][subtableId][rowIndex][controlId] = value;
107
+ }
89
108
  }
90
109
  });
91
110
  }
@@ -214,6 +233,7 @@ function init(instance) {
214
233
  var emptyState = {};
215
234
  var databindMapping = {};
216
235
  var controlidMapping = {};
236
+ var defaultState = {};
217
237
  // loopFormControl(instance, (item, children) => {
218
238
  // })
219
239
  // @ts-ignore
@@ -229,11 +249,13 @@ function init(instance) {
229
249
  buildDataBindMapping(databindMapping, dvId, item);
230
250
  buildControlIdMapping(controlidMapping, dvId, item);
231
251
  });
232
- state[dvId] = dataViewState;
252
+ state[dvId] = {};
253
+ defaultState[dvId] = dataViewState;
233
254
  emptyState[dvId] = emptyDataViewState;
234
255
  });
235
256
  return {
236
257
  state: state,
258
+ defaultState: defaultState,
237
259
  emptyState: emptyState,
238
260
  databindMapping: databindMapping,
239
261
  controlidMapping: controlidMapping
@@ -244,7 +266,7 @@ item) {
244
266
  //if (item instanceof RuntimeFormControl) {
245
267
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
246
268
  // 2023-4-2 jiaqi 首次进入页面去除填充默认值
247
- // dataViewState[item.id] = JSONCopy(item.props.defaultValue)
269
+ dataViewState[item.id] = JSONCopy(item.props.defaultValue);
248
270
  emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
249
271
  } else {
250
272
  var emptyTemplate = {};
@@ -253,7 +275,9 @@ item) {
253
275
  });
254
276
  var _item_props_defaultRows;
255
277
  dataViewState[item.id] = new Array((_item_props_defaultRows = item.props.defaultRows) !== null && _item_props_defaultRows !== void 0 ? _item_props_defaultRows : 1).fill(0).map(function() {
256
- return JSONCopy(emptyTemplate);
278
+ return _objectSpread({
279
+ uid: "new:" + buildUUID("uid")
280
+ }, JSONCopy(emptyTemplate));
257
281
  });
258
282
  emptyDataViewState[item.id] = emptyTemplate;
259
283
  }
@@ -359,6 +359,10 @@ export var CalcPlugin = /*#__PURE__*/ function() {
359
359
  if (!scriptEcho || scriptEcho.length === 0) {
360
360
  return;
361
361
  }
362
+ var rowIndex = undefined;
363
+ if (this.controlInSubtable(control)) {
364
+ rowIndex = this.engine.getInstanceRowIndex(control);
365
+ }
362
366
  // @ts-ignore
363
367
  var scriptText = scriptEcho.reduce(function(result, current) {
364
368
  if (current.type === CALC_TOKEN_TYPE.Operator || current.type === CALC_TOKEN_TYPE.Number) {
@@ -376,7 +380,7 @@ export var CalcPlugin = /*#__PURE__*/ function() {
376
380
  }
377
381
  case CALC_TOKEN_TYPE.VariableInCurrentSubTable:
378
382
  {
379
- var rowIndex = _this.engine.getInstanceRowIndex(control);
383
+ //const rowIndex = this.engine.getInstanceRowIndex(control)
380
384
  instance = _this.engine.getInstance(current.id, rowIndex);
381
385
  var state = _this.engine.getState(current.id, rowIndex);
382
386
  var value1 = _this.getNumberValue(state);
@@ -414,9 +418,9 @@ export var CalcPlugin = /*#__PURE__*/ function() {
414
418
  }));
415
419
  this.cacheComputedResult[scriptText] = value;
416
420
  }
417
- var rowIndex = undefined;
421
+ // let rowIndex = undefined
418
422
  if (this.controlInSubtable(control)) {
419
- rowIndex = this.engine.getInstanceRowIndex(control);
423
+ // rowIndex = this.engine.getInstanceRowIndex(control)
420
424
  // 控件在明细表内,但是没有行下标,说明控件被已经删除了,所以直接return
421
425
  if (rowIndex === undefined) {
422
426
  return;
@@ -26,7 +26,7 @@ callback) {
26
26
  if (item.type === CONTROL_TYPE.DATA_VIEW || item.type === CONTROL_TYPE.SIMPLE_SEARCH) {
27
27
  callback(item);
28
28
  } else if (hasChildrenControl(item)) {
29
- // @ts-ignore
29
+ // @ts-ignore
30
30
  loopDataViewControl(item === null || item === void 0 ? void 0 : item.children, callback);
31
31
  }
32
32
  });