@byteluck-fe/model-driven-engine 6.2.0-beta.17 → 6.2.0-beta.19
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.
- package/dist/esm/common/Engine.js +94 -77
- package/dist/index.umd.js +20 -20
- package/package.json +2 -2
|
@@ -324,7 +324,6 @@ function _ts_generator(thisArg, body) {
|
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
import { getLocaleText } from '@byteluck-fe/locale-message';
|
|
328
327
|
import { isDataBind } from '@byteluck-fe/model-driven-core';
|
|
329
328
|
import { CONTROL_BASE_TYPE, CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, updateValueFromKeys, warn, Watcher, deepFreeze, isBuiltInControls } from '@byteluck-fe/model-driven-shared';
|
|
330
329
|
import { Runtime } from './Runtime';
|
|
@@ -1260,127 +1259,133 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
1260
1259
|
* @options 传递给关联事件中 EventPayload中的options,一般在plugin中监听使用
|
|
1261
1260
|
*/ key: "setData",
|
|
1262
1261
|
value: function setData(dataSet, options) {
|
|
1263
|
-
var _this =
|
|
1264
|
-
|
|
1265
|
-
this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
|
|
1266
|
-
var onlySetData = options === null || options === void 0 ? void 0 : options.onlySetData;
|
|
1267
|
-
var newState = this.store.defaultState;
|
|
1268
|
-
if (onlySetData === true) {
|
|
1269
|
-
newState = {};
|
|
1270
|
-
}
|
|
1271
|
-
Object.keys(dataSet).map(function(dataCode) {
|
|
1262
|
+
var _this, _loop = function(i) {
|
|
1263
|
+
var dataCode = dataCodes[i];
|
|
1272
1264
|
var entity = dataSet[dataCode];
|
|
1273
1265
|
if (Array.isArray(entity)) {
|
|
1274
|
-
var
|
|
1266
|
+
var _storeEmptyState_dataViewId;
|
|
1267
|
+
var mapping = dataBindMapping[dataCode];
|
|
1275
1268
|
if (!mapping) {
|
|
1276
|
-
return;
|
|
1269
|
+
return "continue";
|
|
1277
1270
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1271
|
+
var dataViewId = mapping.dataViewId, controlId = mapping.controlId, fields = mapping.fields;
|
|
1272
|
+
if (!newState[dataViewId]) {
|
|
1273
|
+
newState[dataViewId] = {};
|
|
1280
1274
|
}
|
|
1281
1275
|
if (!entity.length) {
|
|
1282
|
-
var
|
|
1283
|
-
newState[
|
|
1276
|
+
var _newState_dataViewId_controlId;
|
|
1277
|
+
newState[dataViewId][controlId] = (_newState_dataViewId_controlId = newState[dataViewId][controlId]) !== null && _newState_dataViewId_controlId !== void 0 ? _newState_dataViewId_controlId : [];
|
|
1284
1278
|
} else {
|
|
1285
|
-
newState[
|
|
1279
|
+
newState[dataViewId][controlId] = [];
|
|
1286
1280
|
}
|
|
1281
|
+
var fieldMap = new Map();
|
|
1282
|
+
for(var j = 0; j < fields.length; j++){
|
|
1283
|
+
var field = fields[j];
|
|
1284
|
+
fieldMap.set(field.fieldCode, field);
|
|
1285
|
+
}
|
|
1286
|
+
var unboundFields = new Set();
|
|
1287
|
+
for(var j1 = 0; j1 < fields.length; j1++){
|
|
1288
|
+
var field1 = fields[j1];
|
|
1289
|
+
if (field1.fieldCode) {
|
|
1290
|
+
unboundFields.add(field1.fieldCode);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
var emptyRowTemplate = (_storeEmptyState_dataViewId = storeEmptyState[dataViewId]) === null || _storeEmptyState_dataViewId === void 0 ? void 0 : _storeEmptyState_dataViewId[controlId];
|
|
1287
1294
|
var cacheEmptyState = {};
|
|
1288
1295
|
var cacheFieldMapping = {};
|
|
1289
|
-
entity.
|
|
1290
|
-
var
|
|
1291
|
-
var
|
|
1292
|
-
;
|
|
1293
|
-
Object.keys(row)
|
|
1294
|
-
|
|
1295
|
-
var
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
if (!existField) {
|
|
1300
|
-
if (fieldCode in newRow && row[fieldCode] !== undefined) {
|
|
1301
|
-
newRow[fieldCode] = row[fieldCode];
|
|
1302
|
-
}
|
|
1296
|
+
for(var j2 = 0; j2 < entity.length; j2++){
|
|
1297
|
+
var row = entity[j2];
|
|
1298
|
+
var newRow = JSONCopy(emptyRowTemplate);
|
|
1299
|
+
var skipKey = new Set();
|
|
1300
|
+
var rowKeys = Object.keys(row);
|
|
1301
|
+
for(var k = 0; k < rowKeys.length; k++){
|
|
1302
|
+
var fieldCode = rowKeys[k];
|
|
1303
|
+
var rowValue = row[fieldCode];
|
|
1304
|
+
if (!unboundFields.has(fieldCode) && fieldCode in newRow && rowValue !== undefined) {
|
|
1305
|
+
newRow[fieldCode] = rowValue;
|
|
1303
1306
|
}
|
|
1304
|
-
if (skipKey.
|
|
1305
|
-
|
|
1307
|
+
if (skipKey.has(fieldCode)) {
|
|
1308
|
+
continue;
|
|
1306
1309
|
}
|
|
1307
|
-
if (cacheFieldMapping
|
|
1308
|
-
var
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
}
|
|
1310
|
+
if (!cacheFieldMapping[fieldCode]) {
|
|
1311
|
+
var mappedField = fieldMap.get(fieldCode);
|
|
1312
|
+
if (mappedField) {
|
|
1313
|
+
cacheFieldMapping[fieldCode] = mappedField;
|
|
1314
|
+
}
|
|
1312
1315
|
}
|
|
1313
1316
|
var fieldMapping = cacheFieldMapping[fieldCode];
|
|
1314
1317
|
if (fieldMapping) {
|
|
1315
|
-
if (
|
|
1316
|
-
|
|
1317
|
-
newRow[fieldMapping.controlId] = row[fieldCode];
|
|
1318
|
-
// } else if (fieldMapping.dataBind instanceof ObjectDataBind) {
|
|
1318
|
+
if (isDataBind(fieldMapping.dataBind) && rowValue !== undefined) {
|
|
1319
|
+
newRow[fieldMapping.controlId] = rowValue;
|
|
1319
1320
|
} else if (!isDataBind(fieldMapping.dataBind)) {
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1321
|
+
var fieldControlId = fieldMapping.controlId;
|
|
1322
|
+
if (!cacheEmptyState[fieldControlId]) {
|
|
1323
|
+
var _this_store_getEmptyState;
|
|
1324
|
+
cacheEmptyState[fieldControlId] = JSONCopy((_this_store_getEmptyState = _this.store.getEmptyState(fieldControlId)) !== null && _this_store_getEmptyState !== void 0 ? _this_store_getEmptyState : {});
|
|
1323
1325
|
}
|
|
1324
|
-
var objValue = JSONCopy(cacheEmptyState[
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1326
|
+
var objValue = JSONCopy(cacheEmptyState[fieldControlId]);
|
|
1327
|
+
var dataBind = fieldMapping.dataBind;
|
|
1328
|
+
var bindKeys = Object.keys(dataBind);
|
|
1329
|
+
for(var m = 0; m < bindKeys.length; m++){
|
|
1330
|
+
var key = bindKeys[m];
|
|
1331
|
+
var bindInfo = dataBind[key];
|
|
1332
|
+
var fieldCodeValue = row[bindInfo.fieldCode];
|
|
1333
|
+
if (fieldCodeValue !== undefined) {
|
|
1334
|
+
objValue[key] = fieldCodeValue;
|
|
1329
1335
|
}
|
|
1330
|
-
skipKey.
|
|
1331
|
-
}
|
|
1332
|
-
newRow[
|
|
1336
|
+
skipKey.add(bindInfo.fieldCode);
|
|
1337
|
+
}
|
|
1338
|
+
newRow[fieldControlId] = objValue;
|
|
1333
1339
|
}
|
|
1334
|
-
} else if (fieldCode === 'uid' &&
|
|
1335
|
-
newRow.uid =
|
|
1336
|
-
} else if (fieldCode === 'virtualStore' &&
|
|
1337
|
-
newRow.virtualStore = Object.freeze(
|
|
1340
|
+
} else if (fieldCode === 'uid' && rowValue !== undefined) {
|
|
1341
|
+
newRow.uid = rowValue;
|
|
1342
|
+
} else if (fieldCode === 'virtualStore' && rowValue !== undefined) {
|
|
1343
|
+
newRow.virtualStore = Object.freeze(rowValue);
|
|
1338
1344
|
}
|
|
1339
|
-
}
|
|
1340
|
-
newState[
|
|
1341
|
-
}
|
|
1345
|
+
}
|
|
1346
|
+
newState[dataViewId][controlId].push(newRow);
|
|
1347
|
+
}
|
|
1342
1348
|
} else if (entity) {
|
|
1343
1349
|
var _Object_keys;
|
|
1344
|
-
var
|
|
1345
|
-
;
|
|
1350
|
+
var skipKey1 = [];
|
|
1346
1351
|
var emptyState = JSONCopy(_this.store.emptyState);
|
|
1347
1352
|
if (!((_Object_keys = Object.keys(entity)) === null || _Object_keys === void 0 ? void 0 : _Object_keys.length)) {
|
|
1348
|
-
//
|
|
1353
|
+
// 空对象,不做处理
|
|
1349
1354
|
} else {
|
|
1350
1355
|
Object.keys(entity).map(function(fieldCode) {
|
|
1351
|
-
if (
|
|
1356
|
+
if (skipKey1.includes(fieldCode)) {
|
|
1352
1357
|
return;
|
|
1353
1358
|
}
|
|
1354
|
-
var mapping =
|
|
1359
|
+
var mapping = _this1.getDataBindMapping(dataCode, fieldCode);
|
|
1355
1360
|
if (mapping) {
|
|
1356
1361
|
if (!newState[mapping.dataViewId[0]]) {
|
|
1357
1362
|
newState[mapping.dataViewId[0]] = {};
|
|
1358
1363
|
}
|
|
1359
|
-
if (
|
|
1360
|
-
isDataBind(mapping.dataBind) && entity[fieldCode] !== undefined) {
|
|
1364
|
+
if (isDataBind(mapping.dataBind) && entity[fieldCode] !== undefined) {
|
|
1361
1365
|
newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
|
|
1362
|
-
// } else if (mapping.dataBind instanceof ObjectDataBind) {
|
|
1363
1366
|
} else if (!isDataBind(mapping.dataBind)) {
|
|
1364
1367
|
var _this_getEmptyState;
|
|
1365
|
-
var objValue = (_this_getEmptyState =
|
|
1368
|
+
var objValue = (_this_getEmptyState = _this1.getEmptyState(mapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {};
|
|
1366
1369
|
Object.keys(mapping.dataBind).map(function(key) {
|
|
1367
1370
|
var dataBind = mapping.dataBind[key];
|
|
1368
|
-
//金额及计算公式控件在赋值时会经过两次 且当控件值不为同一个模型时,会赋值两次 会导致前后覆盖行为。
|
|
1369
1371
|
if (dataSet[dataBind.dataCode]) {
|
|
1370
1372
|
var extendEntity = dataSet[dataBind.dataCode];
|
|
1371
1373
|
if (extendEntity[dataBind.fieldCode] !== undefined) {
|
|
1372
1374
|
objValue[key] = extendEntity[dataBind.fieldCode];
|
|
1373
1375
|
}
|
|
1374
1376
|
}
|
|
1375
|
-
|
|
1377
|
+
skipKey1.push(dataBind.fieldCode);
|
|
1376
1378
|
});
|
|
1377
1379
|
newState[mapping.dataViewId[0]][mapping.controlId] = objValue;
|
|
1378
1380
|
}
|
|
1379
1381
|
} else {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1382
|
+
var mapping1 = _this1.getDataBindMapping(dataCode);
|
|
1383
|
+
if ((mapping1 === null || mapping1 === void 0 ? void 0 : mapping1.dataViewId) && entity[fieldCode] !== undefined) {
|
|
1384
|
+
var dataViweId = mapping1 === null || mapping1 === void 0 ? void 0 : mapping1.dataViewId;
|
|
1385
|
+
var isInDataView = fieldCode in (emptyState[dataViweId] || {});
|
|
1386
|
+
if (isInDataView) {
|
|
1387
|
+
newState[dataViweId][fieldCode] = entity[fieldCode];
|
|
1388
|
+
}
|
|
1384
1389
|
}
|
|
1385
1390
|
}
|
|
1386
1391
|
});
|
|
@@ -1407,7 +1412,19 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
1407
1412
|
_this.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
|
|
1408
1413
|
}
|
|
1409
1414
|
}
|
|
1410
|
-
}
|
|
1415
|
+
};
|
|
1416
|
+
var _this1 = this;
|
|
1417
|
+
// @i18n-translate-ignore
|
|
1418
|
+
this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
|
|
1419
|
+
var onlySetData = options === null || options === void 0 ? void 0 : options.onlySetData;
|
|
1420
|
+
var newState = this.store.defaultState;
|
|
1421
|
+
if (onlySetData === true) {
|
|
1422
|
+
newState = {};
|
|
1423
|
+
}
|
|
1424
|
+
var dataBindMapping = this.store.dataBindMapping;
|
|
1425
|
+
var storeEmptyState = this.store.emptyState;
|
|
1426
|
+
var dataCodes = Object.keys(dataSet);
|
|
1427
|
+
for(var i = 0; i < dataCodes.length; i++)_this = this, _loop(i);
|
|
1411
1428
|
// @i18n-translate-ignore
|
|
1412
1429
|
this.debugLog("engine setData方法数据组合完成,参数为%o。", newState);
|
|
1413
1430
|
this.setStates(newState, undefined, _object_spread({
|
|
@@ -1415,7 +1432,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
1415
1432
|
}, options));
|
|
1416
1433
|
this.runtime.getFlatInstances();
|
|
1417
1434
|
// @i18n-translate-ignore
|
|
1418
|
-
this.debugLog(
|
|
1435
|
+
this.debugLog("engine setData方法执行完成。");
|
|
1419
1436
|
}
|
|
1420
1437
|
},
|
|
1421
1438
|
{
|