@byteluck-fe/model-driven-engine 2.7.0-alpha.2 → 2.7.0-alpha.20
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/ActionManager.js +98 -63
- package/dist/esm/common/DataManager.js +75 -34
- package/dist/esm/common/Engine.js +1151 -936
- package/dist/esm/common/OkWorker.js +119 -74
- package/dist/esm/common/Runtime.js +43 -22
- package/dist/esm/common/Store.js +159 -129
- package/dist/esm/common/checkerValue.js +330 -248
- package/dist/esm/common/proxyState.js +1 -1
- package/dist/esm/plugins/CalcPlugin.js +393 -309
- package/dist/esm/plugins/ControlsEventPlugin.js +169 -130
- package/dist/esm/plugins/ES6ModulePlugin.js +65 -31
- package/dist/esm/plugins/LifecycleEventPlugin.js +119 -83
- package/dist/esm/plugins/StylePlugin.js +46 -13
- package/dist/esm/utils/runtimeUtils.js +2 -1
- package/dist/index.umd.js +11 -11
- package/dist/types/common/Engine.d.ts +1 -1
- package/package.json +4 -4
|
@@ -49,6 +49,20 @@ function _classCallCheck(instance, Constructor) {
|
|
|
49
49
|
throw new TypeError("Cannot call a class as a function");
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
function _defineProperties(target, props) {
|
|
53
|
+
for(var i = 0; i < props.length; i++){
|
|
54
|
+
var descriptor = props[i];
|
|
55
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
56
|
+
descriptor.configurable = true;
|
|
57
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
58
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
62
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
63
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
64
|
+
return Constructor;
|
|
65
|
+
}
|
|
52
66
|
function _defineProperty(obj, key, value) {
|
|
53
67
|
if (key in obj) {
|
|
54
68
|
Object.defineProperty(obj, key, {
|
|
@@ -97,13 +111,6 @@ function _inherits(subClass, superClass) {
|
|
|
97
111
|
});
|
|
98
112
|
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
99
113
|
}
|
|
100
|
-
function _instanceof(left, right) {
|
|
101
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
102
|
-
return !!right[Symbol.hasInstance](left);
|
|
103
|
-
} else {
|
|
104
|
-
return left instanceof right;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
114
|
function _iterableToArray(iter) {
|
|
108
115
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
109
116
|
}
|
|
@@ -333,7 +340,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
333
340
|
};
|
|
334
341
|
}
|
|
335
342
|
};
|
|
336
|
-
import {
|
|
343
|
+
import { isDataBind } from "@byteluck-fe/model-driven-core";
|
|
337
344
|
import { CONTROL_BASE_TYPE, CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from "@byteluck-fe/model-driven-shared";
|
|
338
345
|
import { Runtime } from "./Runtime";
|
|
339
346
|
import { Store } from "./Store";
|
|
@@ -358,15 +365,24 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
358
365
|
_classCallCheck(this, Engine);
|
|
359
366
|
var _this;
|
|
360
367
|
_this = _super.call(this);
|
|
361
|
-
_this
|
|
368
|
+
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
369
|
+
_defineProperty(_assertThisInitialized(_this), "rawStore", {});
|
|
370
|
+
_defineProperty(_assertThisInitialized(_this), "parent", void 0);
|
|
371
|
+
// 提供注册运行态控件以及实例化控件的能力
|
|
372
|
+
_defineProperty(_assertThisInitialized(_this), "runtime", void 0);
|
|
362
373
|
// 提供子线程处理脚本以及修改数据的能力
|
|
363
374
|
// public worker: OkWorker
|
|
364
|
-
_this
|
|
365
|
-
_this
|
|
366
|
-
_this
|
|
367
|
-
|
|
368
|
-
_this
|
|
369
|
-
_this
|
|
375
|
+
_defineProperty(_assertThisInitialized(_this), "isMounted", false);
|
|
376
|
+
_defineProperty(_assertThisInitialized(_this), "id", genNonDuplicateId(8));
|
|
377
|
+
_defineProperty(_assertThisInitialized(_this), "externalParams", void 0);
|
|
378
|
+
// 提供外部注册插件,在不同的hooks触发时执行固定函数的能力
|
|
379
|
+
_defineProperty(_assertThisInitialized(_this), "__plugins", void 0);
|
|
380
|
+
_defineProperty(_assertThisInitialized(_this), "__pluginsApplied", false);
|
|
381
|
+
_defineProperty(_assertThisInitialized(_this), "$options", void 0);
|
|
382
|
+
_defineProperty(_assertThisInitialized(_this), "actionManager", new ActionManager());
|
|
383
|
+
_defineProperty(_assertThisInitialized(_this), "dataManager", void 0);
|
|
384
|
+
_defineProperty(_assertThisInitialized(_this), "_jobTasks", []);
|
|
385
|
+
_defineProperty(_assertThisInitialized(_this), "createControlInstance", _this.createInstance);
|
|
370
386
|
_this.$options = Object.freeze(props);
|
|
371
387
|
var _this_$options = _this.$options, _this_$options_autoMount = _this_$options.autoMount, autoMount = _this_$options_autoMount === void 0 ? true : _this_$options_autoMount, schema = _this_$options.schema, beforeCreateInstance = _this_$options.beforeCreateInstance, externalParams = _this_$options.externalParams, _this_$options_language = _this_$options.// fieldModel,
|
|
372
388
|
language, language = _this_$options_language === void 0 ? DEFAULT_LOCALE : _this_$options_language, _this_$options_debug = _this_$options.debug, debug = _this_$options_debug === void 0 ? false : _this_$options_debug;
|
|
@@ -385,1031 +401,1230 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
385
401
|
autoMount && _this.mount();
|
|
386
402
|
return _this;
|
|
387
403
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
if (!this.__pluginsApplied) {
|
|
397
|
-
this.__plugins.push(plugin);
|
|
398
|
-
}
|
|
399
|
-
return this;
|
|
400
|
-
};
|
|
401
|
-
// 注册外部控件
|
|
402
|
-
_proto.registerControl = function registerControl() {
|
|
403
|
-
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
404
|
-
arg[_key] = arguments[_key];
|
|
405
|
-
}
|
|
406
|
-
var _this_runtime;
|
|
407
|
-
(_this_runtime = this.runtime).register.apply(_this_runtime, _toConsumableArray(arg));
|
|
408
|
-
return this;
|
|
409
|
-
};
|
|
410
|
-
_proto.mount = function mount() {
|
|
411
|
-
this.debugLog("engine的mount方法开始调用");
|
|
412
|
-
var _this_$options = this.$options, _this_$options_plugins = _this_$options.plugins, plugins = _this_$options_plugins === void 0 ? [] : _this_$options_plugins;
|
|
413
|
-
this._handlerProxyState();
|
|
414
|
-
this.__plugins = plugins;
|
|
415
|
-
this.applyPlugins();
|
|
416
|
-
// 触发所有控件的默认值的change事件
|
|
417
|
-
this.setStates(this.getState());
|
|
418
|
-
this.debugLog("engine的mount方法调用结束");
|
|
419
|
-
if (this.debug && typeof window !== "undefined") {
|
|
420
|
-
// @ts-ignore
|
|
421
|
-
window.engines[this.id] = this;
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
_proto.destroy = function destroy() {
|
|
425
|
-
if (this.debug && typeof window !== "undefined") {
|
|
426
|
-
// @ts-ignore
|
|
427
|
-
delete window.engines[this.id];
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
_proto._handlerProxyState = function _handlerProxyState() {
|
|
431
|
-
this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
|
|
432
|
-
};
|
|
433
|
-
_proto._proxyStateBeforeSetCallback = function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
|
|
434
|
-
var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
|
|
435
|
-
// 找不到控件说明不是改动控件上的字段,直接通过
|
|
436
|
-
if (!instance) {
|
|
437
|
-
return newValue;
|
|
438
|
-
}
|
|
439
|
-
// @ts-ignore
|
|
440
|
-
if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE)) {
|
|
441
|
-
if (newValue === null) {
|
|
442
|
-
return [];
|
|
404
|
+
_createClass(Engine, [
|
|
405
|
+
{
|
|
406
|
+
key: "debugLog",
|
|
407
|
+
value: function debugLog() {
|
|
408
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
409
|
+
args[_key] = arguments[_key];
|
|
410
|
+
}
|
|
411
|
+
this.debug && log.apply(void 0, _toConsumableArray(args));
|
|
443
412
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (
|
|
449
|
-
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
key: "use",
|
|
416
|
+
value: function use(plugin) {
|
|
417
|
+
if (!this.__pluginsApplied) {
|
|
418
|
+
this.__plugins.push(plugin);
|
|
419
|
+
}
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
key: "registerControl",
|
|
425
|
+
value: // 注册外部控件
|
|
426
|
+
function registerControl() {
|
|
427
|
+
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
428
|
+
arg[_key] = arguments[_key];
|
|
429
|
+
}
|
|
430
|
+
var _this_runtime;
|
|
431
|
+
(_this_runtime = this.runtime).register.apply(_this_runtime, _toConsumableArray(arg));
|
|
432
|
+
return this;
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
key: "mount",
|
|
437
|
+
value: function mount() {
|
|
438
|
+
this.debugLog("engine的mount方法开始调用");
|
|
439
|
+
var _this_$options = this.$options, _this_$options_plugins = _this_$options.plugins, plugins = _this_$options_plugins === void 0 ? [] : _this_$options_plugins;
|
|
440
|
+
this._handlerProxyState();
|
|
441
|
+
this.__plugins = plugins;
|
|
442
|
+
this.applyPlugins();
|
|
443
|
+
// 触发所有控件的默认值的change事件
|
|
444
|
+
this.setStates(this.getState());
|
|
445
|
+
this.debugLog("engine的mount方法调用结束");
|
|
446
|
+
if (this.debug && typeof window !== "undefined") {
|
|
447
|
+
// @ts-ignore
|
|
448
|
+
window.engines[this.id] = this;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
key: "destroy",
|
|
454
|
+
value: function destroy() {
|
|
455
|
+
if (this.debug && typeof window !== "undefined") {
|
|
456
|
+
// @ts-ignore
|
|
457
|
+
delete window.engines[this.id];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
key: "_handlerProxyState",
|
|
463
|
+
value: function _handlerProxyState() {
|
|
464
|
+
this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
key: "_proxyStateBeforeSetCallback",
|
|
469
|
+
value: function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
|
|
470
|
+
var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
|
|
471
|
+
// 找不到控件说明不是改动控件上的字段,直接通过
|
|
472
|
+
if (!instance) {
|
|
473
|
+
return newValue;
|
|
450
474
|
}
|
|
451
|
-
return result;
|
|
452
|
-
}, {});
|
|
453
|
-
// @ts-ignore
|
|
454
|
-
var emptyState = this.getEmptyState(instance.id);
|
|
455
|
-
return newValue === null || newValue === void 0 ? void 0 : newValue.map(function(row) {
|
|
456
|
-
return(// @ts-ignore
|
|
457
|
-
checkerSubtableValue(fieldTypeMap, row, emptyState));
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
var keys = key.split(".");
|
|
461
|
-
var lastKey = keys[keys.length - 1];
|
|
462
|
-
try {
|
|
463
|
-
return checkerValue(instance.fieldType, lastKey, newValue, oldValue);
|
|
464
|
-
} catch (e) {
|
|
465
|
-
warn("the id=".concat(instance.id, "'s instance setState error, %o ").concat(e, "."), newValue);
|
|
466
|
-
throw e;
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
_proto._proxyStateCallback = function _proxyStateCallback(state, key, type, args, result) {
|
|
470
|
-
if (Array.isArray(state)) {
|
|
471
|
-
this._handlerArrayUpdate(state, key, type, args, result);
|
|
472
|
-
} else {
|
|
473
|
-
this._handlerObjectUpdate(state, key, type, args);
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
_proto._handlerArrayUpdate = function _handlerArrayUpdate(state, key, type, args, result) {
|
|
477
|
-
var _this = this;
|
|
478
|
-
var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
|
|
479
|
-
if (!_instanceof(subtable, RuntimeListControl)) return;
|
|
480
|
-
// 新增多行方法
|
|
481
|
-
var createRows = function(len) {
|
|
482
|
-
// @ts-ignore
|
|
483
|
-
var newRows = [];
|
|
484
|
-
for(var i = 0; i < len; i++){
|
|
485
475
|
// @ts-ignore
|
|
486
|
-
|
|
487
|
-
|
|
476
|
+
if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE)) {
|
|
477
|
+
if (newValue === null) {
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
// @ts-ignore
|
|
481
|
+
var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
|
|
482
|
+
var formInstance = column.children[0];
|
|
483
|
+
// if (formInstance && formInstance instanceof RuntimeFormControl) {
|
|
484
|
+
if (formInstance && formInstance.controlType === CONTROL_BASE_TYPE.FORM) {
|
|
485
|
+
result[formInstance.id] = formInstance.fieldType;
|
|
486
|
+
}
|
|
487
|
+
return result;
|
|
488
|
+
}, {});
|
|
489
|
+
// @ts-ignore
|
|
490
|
+
var emptyState = this.getEmptyState(instance.id);
|
|
491
|
+
return newValue === null || newValue === void 0 ? void 0 : newValue.map(function(row) {
|
|
492
|
+
return(// @ts-ignore
|
|
493
|
+
checkerSubtableValue(fieldTypeMap, row, emptyState));
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
var keys = key.split(".");
|
|
497
|
+
var lastKey = keys[keys.length - 1];
|
|
498
|
+
try {
|
|
499
|
+
return checkerValue(instance.fieldType, lastKey, newValue, oldValue);
|
|
500
|
+
} catch (e) {
|
|
501
|
+
warn("the id=".concat(instance.id, "'s instance setState error, %o ").concat(e, "."), newValue);
|
|
502
|
+
throw e;
|
|
503
|
+
}
|
|
488
504
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
var
|
|
514
|
-
|
|
515
|
-
createdNewRows = createRows(newRowLengths1);
|
|
516
|
-
createdNewRowsData = newValues;
|
|
517
|
-
// 从哪儿开始
|
|
518
|
-
var start = args[0];
|
|
519
|
-
// 替换几个
|
|
520
|
-
var replace = args[1];
|
|
521
|
-
(_subtable_children1 = subtable.children)[type].apply(_subtable_children1, [
|
|
522
|
-
start,
|
|
523
|
-
replace
|
|
524
|
-
].concat(_toConsumableArray(createdNewRows)));
|
|
525
|
-
this.runtime.getFlatInstances();
|
|
526
|
-
// newValues.forEach((item: any, index) => {
|
|
527
|
-
// let newIndex = start + index
|
|
528
|
-
// this.setStates(item, newIndex, options)
|
|
529
|
-
// })
|
|
530
|
-
} else {
|
|
531
|
-
var // @ts-ignore
|
|
532
|
-
_subtable_children2;
|
|
533
|
-
(_subtable_children2 = subtable.children)[type].apply(_subtable_children2, _toConsumableArray(args));
|
|
534
|
-
this.runtime.getFlatInstances();
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
key: "_proxyStateCallback",
|
|
508
|
+
value: function _proxyStateCallback(state, key, type, args, result) {
|
|
509
|
+
if (Array.isArray(state)) {
|
|
510
|
+
this._handlerArrayUpdate(state, key, type, args, result);
|
|
511
|
+
} else {
|
|
512
|
+
this._handlerObjectUpdate(state, key, type, args);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
key: "_handlerArrayUpdate",
|
|
518
|
+
value: function _handlerArrayUpdate(state, key, type, args, result) {
|
|
519
|
+
var _this = this;
|
|
520
|
+
var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
|
|
521
|
+
// if (!(subtable instanceof RuntimeListControl)) return
|
|
522
|
+
if (!((subtable === null || subtable === void 0 ? void 0 : subtable.controlType) === CONTROL_BASE_TYPE.LIST)) return;
|
|
523
|
+
// 新增多行方法
|
|
524
|
+
var createRows = function(len) {
|
|
525
|
+
// @ts-ignore
|
|
526
|
+
var newRows = [];
|
|
527
|
+
for(var i = 0; i < len; i++){
|
|
528
|
+
// @ts-ignore
|
|
529
|
+
var row = _this.listControlCreateRow(subtable, "subtable-row");
|
|
530
|
+
row && newRows.push(row);
|
|
535
531
|
}
|
|
536
|
-
|
|
537
|
-
|
|
532
|
+
// @ts-ignore
|
|
533
|
+
return newRows;
|
|
534
|
+
};
|
|
535
|
+
var options = eventOptionsTemp;
|
|
536
|
+
// @ts-ignore
|
|
537
|
+
var createdNewRows = [];
|
|
538
|
+
var createdNewRowsData = [];
|
|
539
|
+
var deleted = [];
|
|
540
|
+
var isDeleteLastOne = false;
|
|
541
|
+
if (type && args) {
|
|
542
|
+
// const subtableOldLength = subtable.children.length
|
|
543
|
+
switch(type){
|
|
544
|
+
case "push":
|
|
545
|
+
case "unshift":
|
|
546
|
+
var _subtable_children;
|
|
547
|
+
var newRowLengths = args.length;
|
|
548
|
+
createdNewRows = createRows(newRowLengths);
|
|
549
|
+
createdNewRowsData = args;
|
|
550
|
+
(_subtable_children = subtable.children)[type].apply(_subtable_children, _toConsumableArray(createdNewRows));
|
|
551
|
+
this.runtime.getFlatInstances();
|
|
552
|
+
break;
|
|
553
|
+
case "splice":
|
|
554
|
+
if (args.length > 2) {
|
|
555
|
+
var // @ts-ignore
|
|
556
|
+
_subtable_children1;
|
|
557
|
+
var newRowLengths1 = args.length - 2;
|
|
558
|
+
var newValues = args.slice(2);
|
|
559
|
+
createdNewRows = createRows(newRowLengths1);
|
|
560
|
+
createdNewRowsData = newValues;
|
|
561
|
+
// 从哪儿开始
|
|
562
|
+
var start = args[0];
|
|
563
|
+
// 替换几个
|
|
564
|
+
var replace = args[1];
|
|
565
|
+
(_subtable_children1 = subtable.children)[type].apply(_subtable_children1, [
|
|
566
|
+
start,
|
|
567
|
+
replace
|
|
568
|
+
].concat(_toConsumableArray(createdNewRows)));
|
|
569
|
+
this.runtime.getFlatInstances();
|
|
570
|
+
// newValues.forEach((item: any, index) => {
|
|
571
|
+
// let newIndex = start + index
|
|
572
|
+
// this.setStates(item, newIndex, options)
|
|
573
|
+
// })
|
|
574
|
+
} else {
|
|
575
|
+
var // @ts-ignore
|
|
576
|
+
_subtable_children2;
|
|
577
|
+
// 从哪儿开始
|
|
578
|
+
var start1 = args[0];
|
|
579
|
+
// 替换几个
|
|
580
|
+
var replace1 = args[1];
|
|
581
|
+
if (start1 + replace1 === subtable.children.length - 1) {
|
|
582
|
+
isDeleteLastOne = true;
|
|
583
|
+
}
|
|
584
|
+
(_subtable_children2 = subtable.children)[type].apply(_subtable_children2, _toConsumableArray(args));
|
|
585
|
+
this.runtime.getFlatInstances();
|
|
586
|
+
}
|
|
587
|
+
break;
|
|
588
|
+
default:
|
|
589
|
+
var // @ts-ignore
|
|
590
|
+
_subtable_children3;
|
|
591
|
+
(_subtable_children3 = subtable.children)[type].apply(_subtable_children3, _toConsumableArray(args));
|
|
592
|
+
this.runtime.getFlatInstances();
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
if (type === "splice") {
|
|
596
|
+
deleted = result;
|
|
597
|
+
} else if ([
|
|
598
|
+
"pop",
|
|
599
|
+
"shift"
|
|
600
|
+
].includes(type)) {
|
|
601
|
+
deleted = [
|
|
602
|
+
result
|
|
603
|
+
];
|
|
604
|
+
}
|
|
605
|
+
this.emit("list-change", {
|
|
606
|
+
instance: subtable,
|
|
607
|
+
value: this.getState(subtable.id),
|
|
608
|
+
options: Object.assign({}, options, {
|
|
609
|
+
changed: createdNewRows,
|
|
610
|
+
data: createdNewRowsData,
|
|
611
|
+
deleted: deleted !== null && deleted !== void 0 ? deleted : [],
|
|
612
|
+
jsonValue: JSON.stringify(this.getState(subtable.id)),
|
|
613
|
+
isDeleteLastOne: isDeleteLastOne
|
|
614
|
+
})
|
|
615
|
+
});
|
|
616
|
+
// 主动清空本次任务中的options
|
|
617
|
+
eventOptionsTemp = null;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
key: "_handlerObjectUpdate",
|
|
623
|
+
value: function _handlerObjectUpdate(state, key, value, oldValue) {
|
|
624
|
+
var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
|
|
625
|
+
if (!instance) {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
var index = this.getInstanceRowIndex(instance);
|
|
629
|
+
var options = eventOptionsTemp || {};
|
|
630
|
+
// if (instance instanceof RuntimeListControl) {
|
|
631
|
+
if (instance.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
538
632
|
var // @ts-ignore
|
|
539
|
-
|
|
540
|
-
|
|
633
|
+
_instance_children;
|
|
634
|
+
instance.children.length = 0;
|
|
635
|
+
var newValue = value;
|
|
636
|
+
// @ts-ignore
|
|
637
|
+
var newRows = [];
|
|
638
|
+
for(var i = 0; i < newValue.length; i++){
|
|
639
|
+
// @ts-ignore
|
|
640
|
+
var row = this.listControlCreateRow(instance, "subtable-row");
|
|
641
|
+
row && newRows.push(row);
|
|
642
|
+
}
|
|
643
|
+
(_instance_children = instance.children).push.apply(_instance_children, _toConsumableArray(newRows));
|
|
541
644
|
this.runtime.getFlatInstances();
|
|
542
|
-
|
|
645
|
+
// 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
|
|
646
|
+
// for (let i = 0; i < newValue.length; i++) {
|
|
647
|
+
// this.setStates(newValue[i], i, options)
|
|
648
|
+
// }
|
|
649
|
+
this.emit("list-change", {
|
|
650
|
+
instance: instance,
|
|
651
|
+
value: value,
|
|
652
|
+
options: _objectSpreadProps(_objectSpread({}, options), {
|
|
653
|
+
// @ts-ignore
|
|
654
|
+
changed: newRows,
|
|
655
|
+
data: newValue,
|
|
656
|
+
deleted: oldValue !== null && oldValue !== void 0 ? oldValue : []
|
|
657
|
+
})
|
|
658
|
+
});
|
|
659
|
+
} else {
|
|
660
|
+
this.emit("change", {
|
|
661
|
+
instance: instance,
|
|
662
|
+
value: this.getState(instance.id, index),
|
|
663
|
+
rowIndex: index,
|
|
664
|
+
options: _objectSpreadProps(_objectSpread({}, options), {
|
|
665
|
+
oldValue: oldValue
|
|
666
|
+
})
|
|
667
|
+
});
|
|
668
|
+
}
|
|
543
669
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
key: "applyPlugins",
|
|
673
|
+
value: function applyPlugins() {
|
|
674
|
+
var _this = this;
|
|
675
|
+
if (this.__pluginsApplied) return;
|
|
676
|
+
this.__plugins.forEach(function(plugin) {
|
|
677
|
+
try {
|
|
678
|
+
var _plugin_pluginName;
|
|
679
|
+
applyingPluginName = (_plugin_pluginName = plugin.pluginName) !== null && _plugin_pluginName !== void 0 ? _plugin_pluginName : plugin.constructor.name;
|
|
680
|
+
plugin.apply(_this);
|
|
681
|
+
} catch (e) {
|
|
682
|
+
error("".concat(applyingPluginName, " Plugin apply Error \n ").concat(e));
|
|
683
|
+
} finally{
|
|
684
|
+
applyingPluginName = "";
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
this.__pluginsApplied = true;
|
|
553
688
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
jsonValue: JSON.stringify(this.getState(subtable.id))
|
|
562
|
-
})
|
|
563
|
-
});
|
|
564
|
-
// 主动清空本次任务中的options
|
|
565
|
-
eventOptionsTemp = null;
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
_proto._handlerObjectUpdate = function _handlerObjectUpdate(state, key, value, oldValue) {
|
|
569
|
-
var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
|
|
570
|
-
if (!instance) {
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
var index = this.getInstanceRowIndex(instance);
|
|
574
|
-
var options = eventOptionsTemp || {};
|
|
575
|
-
// if (instance instanceof RuntimeListControl) {
|
|
576
|
-
if (instance.controlType === CONTROL_BASE_TYPE.LIST) {
|
|
577
|
-
var // @ts-ignore
|
|
578
|
-
_instance_children;
|
|
579
|
-
instance.children.length = 0;
|
|
580
|
-
var newValue = value;
|
|
581
|
-
// @ts-ignore
|
|
582
|
-
var newRows = [];
|
|
583
|
-
for(var i = 0; i < newValue.length; i++){
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
key: "listControlCreateRow",
|
|
692
|
+
value: function listControlCreateRow(instance, rowType) {
|
|
693
|
+
var row = this.runtime.createControlInstance(rowType);
|
|
694
|
+
if (!row) return;
|
|
695
|
+
// if (row instanceof RuntimeLayoutControl) {
|
|
584
696
|
// @ts-ignore
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
this.runtime.getFlatInstances();
|
|
590
|
-
// 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
|
|
591
|
-
// for (let i = 0; i < newValue.length; i++) {
|
|
592
|
-
// this.setStates(newValue[i], i, options)
|
|
593
|
-
// }
|
|
594
|
-
this.emit("list-change", {
|
|
595
|
-
instance: instance,
|
|
596
|
-
value: value,
|
|
597
|
-
options: _objectSpreadProps(_objectSpread({}, options), {
|
|
697
|
+
if (row.controlType === CONTROL_BASE_TYPE.LAYOUT) {
|
|
698
|
+
var _inst_children;
|
|
699
|
+
var inst = row;
|
|
700
|
+
var template = JSONCopy(instance.props.headers);
|
|
598
701
|
// @ts-ignore
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
});
|
|
604
|
-
} else {
|
|
605
|
-
this.emit("change", {
|
|
606
|
-
instance: instance,
|
|
607
|
-
value: this.getState(instance.id, index),
|
|
608
|
-
rowIndex: index,
|
|
609
|
-
options: _objectSpreadProps(_objectSpread({}, options), {
|
|
610
|
-
oldValue: oldValue
|
|
611
|
-
})
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
_proto.applyPlugins = function applyPlugins() {
|
|
616
|
-
var _this = this;
|
|
617
|
-
if (this.__pluginsApplied) return;
|
|
618
|
-
this.__plugins.forEach(function(plugin) {
|
|
619
|
-
try {
|
|
620
|
-
var _plugin_pluginName;
|
|
621
|
-
applyingPluginName = (_plugin_pluginName = plugin.pluginName) !== null && _plugin_pluginName !== void 0 ? _plugin_pluginName : plugin.constructor.name;
|
|
622
|
-
plugin.apply(_this);
|
|
623
|
-
} catch (e) {
|
|
624
|
-
error("".concat(applyingPluginName, " Plugin apply Error \n ").concat(e));
|
|
625
|
-
} finally{
|
|
626
|
-
applyingPluginName = "";
|
|
702
|
+
var columns = this.createControl(template);
|
|
703
|
+
(_inst_children = inst.children).push.apply(_inst_children, _toConsumableArray(columns));
|
|
704
|
+
}
|
|
705
|
+
return row;
|
|
627
706
|
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
2
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
];
|
|
704
|
-
case 4:
|
|
705
|
-
results = _state.sent();
|
|
706
|
-
if (promiseResolver && promise) {
|
|
707
|
-
// 每一个任务完成的时候,都把自己从task中去掉
|
|
708
|
-
promiseResolver();
|
|
709
|
-
_this1._jobTasks.splice(_this1._jobTasks.indexOf(promise), 1);
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
key: "listControlAddRow",
|
|
710
|
+
value: function listControlAddRow(instance) {
|
|
711
|
+
var // @ts-ignore
|
|
712
|
+
rowType = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "subtable-row";
|
|
713
|
+
var row = this.listControlCreateRow(instance, rowType);
|
|
714
|
+
if (!row) return;
|
|
715
|
+
instance.children.push(row);
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
key: "emit",
|
|
720
|
+
value: // payload应该是runtimeSchema和value,然后通过runTimeSchema去找需要修改的data里边的key
|
|
721
|
+
function emit(eventKey, payload) {
|
|
722
|
+
var _this = this;
|
|
723
|
+
var _this1 = this, _superprop_get_emit = function() {
|
|
724
|
+
return _get(_getPrototypeOf(Engine.prototype), "emit", _this);
|
|
725
|
+
};
|
|
726
|
+
return _asyncToGenerator(function() {
|
|
727
|
+
var needWait, promiseResolver, promise, results;
|
|
728
|
+
return __generator(this, function(_state) {
|
|
729
|
+
switch(_state.label){
|
|
730
|
+
case 0:
|
|
731
|
+
if (!(eventKey === "engine-mounted")) return [
|
|
732
|
+
3,
|
|
733
|
+
3
|
|
734
|
+
];
|
|
735
|
+
if (_this1.isMounted) {
|
|
736
|
+
warn("The engine-mounted life cycle can only be triggered once");
|
|
737
|
+
return [
|
|
738
|
+
2,
|
|
739
|
+
Promise.resolve([])
|
|
740
|
+
];
|
|
741
|
+
}
|
|
742
|
+
if (!_this1._jobTasks.length) return [
|
|
743
|
+
3,
|
|
744
|
+
2
|
|
745
|
+
];
|
|
746
|
+
console.time("engine-mounted need wait");
|
|
747
|
+
needWait = _toConsumableArray(_this1._jobTasks);
|
|
748
|
+
return [
|
|
749
|
+
4,
|
|
750
|
+
Promise.all(needWait)
|
|
751
|
+
];
|
|
752
|
+
case 1:
|
|
753
|
+
_state.sent();
|
|
754
|
+
console.timeEnd("engine-mounted need wait");
|
|
755
|
+
_state.label = 2;
|
|
756
|
+
case 2:
|
|
757
|
+
_this1.isMounted = true;
|
|
758
|
+
_state.label = 3;
|
|
759
|
+
case 3:
|
|
760
|
+
// 如果没有挂载的话,需要记录在挂载之前触发的所有任务
|
|
761
|
+
if (!_this1.isMounted) {
|
|
762
|
+
promise = new Promise(function(resolve) {
|
|
763
|
+
promiseResolver = resolve;
|
|
764
|
+
});
|
|
765
|
+
_this1._jobTasks.push(promise);
|
|
766
|
+
}
|
|
767
|
+
return [
|
|
768
|
+
4,
|
|
769
|
+
_superprop_get_emit().call(_this1, eventKey, payload)
|
|
770
|
+
];
|
|
771
|
+
case 4:
|
|
772
|
+
results = _state.sent();
|
|
773
|
+
if (promiseResolver && promise) {
|
|
774
|
+
// 每一个任务完成的时候,都把自己从task中去掉
|
|
775
|
+
promiseResolver();
|
|
776
|
+
_this1._jobTasks.splice(_this1._jobTasks.indexOf(promise), 1);
|
|
777
|
+
}
|
|
778
|
+
return [
|
|
779
|
+
2,
|
|
780
|
+
results
|
|
781
|
+
];
|
|
710
782
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
783
|
+
});
|
|
784
|
+
})();
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
key: "on",
|
|
789
|
+
value: function on(key, callback) {
|
|
790
|
+
if (applyingPluginName) {
|
|
791
|
+
callback.applyingPluginName = applyingPluginName;
|
|
715
792
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
793
|
+
return _get(_getPrototypeOf(Engine.prototype), "on", this).call(this, key, callback);
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
key: "createControl",
|
|
798
|
+
value: function createControl() {
|
|
799
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
800
|
+
args[_key] = arguments[_key];
|
|
801
|
+
}
|
|
802
|
+
var _this_runtime;
|
|
803
|
+
return (_this_runtime = this.runtime).createControl.apply(_this_runtime, _toConsumableArray(args));
|
|
804
|
+
}
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
key: "createInstance",
|
|
808
|
+
value: function createInstance(type, initSchema) {
|
|
809
|
+
return this.runtime.createControlInstance(type, initSchema);
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
key: "schemaEvent",
|
|
814
|
+
value: function schemaEvent(eventKey, payload) {
|
|
815
|
+
this.emit(eventKey, payload);
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
key: "updateInstanceProps",
|
|
820
|
+
value: function updateInstanceProps(instance, props, value, rowIndex) {
|
|
821
|
+
return this.setInstance(instance, props, value, rowIndex);
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
key: "getAllRules",
|
|
826
|
+
value: function getAllRules(controlId) {
|
|
827
|
+
var rules = this.runtime.allRules;
|
|
828
|
+
if (controlId === undefined) {
|
|
829
|
+
return rules;
|
|
830
|
+
} else {
|
|
831
|
+
var _rules_rules_controlId, _rules_antdRules_controlId;
|
|
832
|
+
return {
|
|
833
|
+
rules: (_rules_rules_controlId = rules.rules[controlId]) === null || _rules_rules_controlId === void 0 ? void 0 : _rules_rules_controlId.fields,
|
|
834
|
+
antdRules: (_rules_antdRules_controlId = rules.antdRules[controlId]) === null || _rules_antdRules_controlId === void 0 ? void 0 : _rules_antdRules_controlId.fields
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
key: "getRules",
|
|
841
|
+
value: function getRules(controlId) {
|
|
842
|
+
if (controlId === undefined) {
|
|
843
|
+
return this.runtime.rules;
|
|
844
|
+
} else {
|
|
845
|
+
var _this_runtime_rules_controlId;
|
|
846
|
+
return (_this_runtime_rules_controlId = this.runtime.rules[controlId]) === null || _this_runtime_rules_controlId === void 0 ? void 0 : _this_runtime_rules_controlId.fields;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
key: "getAntdRules",
|
|
852
|
+
value: function getAntdRules(controlId) {
|
|
853
|
+
if (controlId === undefined) {
|
|
854
|
+
return this.runtime.antdRules;
|
|
855
|
+
} else {
|
|
856
|
+
var _this_runtime_antdRules_controlId;
|
|
857
|
+
return (_this_runtime_antdRules_controlId = this.runtime.antdRules[controlId]) === null || _this_runtime_antdRules_controlId === void 0 ? void 0 : _this_runtime_antdRules_controlId.fields;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
key: "getState",
|
|
863
|
+
value: function getState(controlId, rowIndex) {
|
|
864
|
+
if (controlId === undefined) {
|
|
865
|
+
return this.store.state;
|
|
866
|
+
} else {
|
|
867
|
+
return this.store.getState(controlId, rowIndex);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
key: "getEmptyState",
|
|
873
|
+
value: function getEmptyState(controlId) {
|
|
874
|
+
if (controlId === undefined) {
|
|
875
|
+
return JSONCopy(this.store.emptyState);
|
|
876
|
+
} else {
|
|
877
|
+
return JSONCopy(this.store.getEmptyState(controlId));
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
/**
|
|
784
883
|
* 设置payload的options,提供在不是使用标准api修改state的时候可以传递options,会在本次任务执行完成之后清空
|
|
785
884
|
* @param options 需要携带的options
|
|
786
|
-
* */
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
885
|
+
* */ key: "setPayloadOptions",
|
|
886
|
+
value: function setPayloadOptions(options) {
|
|
887
|
+
eventOptionsTemp = options;
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
key: "setState",
|
|
892
|
+
value: function setState(controlId, value, rowIndex, options) {
|
|
893
|
+
eventOptionsTemp = options;
|
|
894
|
+
this.debugLog("[%o]: 触发setState, 修改的值为%o, rowIndex=%o, options=%o", controlId, value, rowIndex, options);
|
|
895
|
+
this.store.setState(controlId, value, rowIndex);
|
|
896
|
+
this.debugLog("[%o]: setState完成, 修改的值为%o, rowIndex=%o", controlId, value, rowIndex);
|
|
897
|
+
eventOptionsTemp = null;
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
/**
|
|
797
902
|
* 向Store设置一组值,明细表必须全量赋值,并触发事件(触发事件是根据组件在页面中的顺序逐个触发)
|
|
798
903
|
* @param states
|
|
799
|
-
*/
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
904
|
+
*/ key: "setStates",
|
|
905
|
+
value: function setStates(states, rowIndex, options) {
|
|
906
|
+
var _this = this;
|
|
907
|
+
var newStates = states !== null && states !== void 0 ? states : {};
|
|
908
|
+
Object.keys(newStates).forEach(function(stateId) {
|
|
909
|
+
Object.entries(_this.store.controlIdMapping).forEach(function(param) {
|
|
910
|
+
var _param = _slicedToArray(param, 2), controlId = _param[0], controlIdMapping = _param[1];
|
|
911
|
+
if (controlIdMapping.dataView === stateId) {
|
|
912
|
+
// state对象是dataView包裹的
|
|
913
|
+
var value = newStates[stateId][controlId];
|
|
914
|
+
if (value !== undefined) {
|
|
915
|
+
_this.setState(controlId, value, rowIndex, options);
|
|
916
|
+
}
|
|
917
|
+
} else {
|
|
918
|
+
// state对象是单独的,没有被dataView包裹的
|
|
919
|
+
if (controlId === stateId || controlIdMapping.children && controlIdMapping.children[stateId]) {
|
|
920
|
+
if (newStates[stateId] !== undefined) {
|
|
921
|
+
_this.setState(stateId, newStates[stateId], rowIndex, options);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
816
924
|
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
},
|
|
929
|
+
{
|
|
930
|
+
/**
|
|
823
931
|
* 通过dataCode和fieldCode来获取控件的值
|
|
824
932
|
* @param dataCode 模型编码 - 如果是主表的话就是主表的模型编码,明细子表的话就是子表的模型编码
|
|
825
933
|
* @param fieldCode 字段编码 - 控件绑定的数据项的编码
|
|
826
934
|
* @param rowIndex 行下标 - 如果是明细子表中的控件需要提供
|
|
827
|
-
* */
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
var dataBindMapping1 = this.getDataBindMapping(dataCode, fieldCode);
|
|
837
|
-
if (!dataBindMapping1) {
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
var dataBind = dataBindMapping1.dataBind, controlId1 = dataBindMapping1.controlId;
|
|
841
|
-
var state = this.getState(controlId1, rowIndex);
|
|
842
|
-
if (_instanceof(dataBind, ObjectDataBind)) {
|
|
843
|
-
return Object.entries(dataBind).reduce(function(result, param) {
|
|
844
|
-
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
845
|
-
// objectDataBind的元素,跳过下一次赋值
|
|
846
|
-
if (dataBind.fieldCode === fieldCode) {
|
|
847
|
-
return result[key];
|
|
935
|
+
* */ key: "getField",
|
|
936
|
+
value: function getField(dataCode, fieldCode, rowIndex) {
|
|
937
|
+
if (!fieldCode) {
|
|
938
|
+
var dataBindMapping = this.getDataBindMapping(dataCode);
|
|
939
|
+
if (dataBindMapping) {
|
|
940
|
+
var controlId = dataBindMapping.controlId;
|
|
941
|
+
return this.getState(controlId);
|
|
942
|
+
}
|
|
943
|
+
return;
|
|
848
944
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
// 明细子表值
|
|
863
|
-
if (Array.isArray(getFieldData)) {
|
|
864
|
-
var data = getFieldData.map(function(item) {
|
|
865
|
-
var obj = {};
|
|
866
|
-
for(var key in item){
|
|
867
|
-
var _controlIdMapping_controlId_children_key, _controlIdMapping_controlId, _controlIdMapping_controlId_children_key_dataBind;
|
|
868
|
-
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;
|
|
869
|
-
//未绑定字段的控件,直接抛弃
|
|
870
|
-
if (fieldCode !== "") {
|
|
871
|
-
var _controlIdMapping_controlId1;
|
|
872
|
-
if (fieldCode) {
|
|
873
|
-
obj[fieldCode] = item[key];
|
|
874
|
-
} else if ((_controlIdMapping_controlId1 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId1 === void 0 ? void 0 : _controlIdMapping_controlId1.children[key]) {
|
|
875
|
-
// 兼容一个控件需要绑定多个字段的情况
|
|
876
|
-
for(var keyChi in item[key]){
|
|
877
|
-
var _controlIdMapping_controlId_children_key1, _controlIdMapping_controlId2;
|
|
878
|
-
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];
|
|
879
|
-
}
|
|
880
|
-
}
|
|
945
|
+
var dataBindMapping1 = this.getDataBindMapping(dataCode, fieldCode);
|
|
946
|
+
if (!dataBindMapping1) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
var dataBind = dataBindMapping1.dataBind, controlId1 = dataBindMapping1.controlId;
|
|
950
|
+
var state = this.getState(controlId1, rowIndex);
|
|
951
|
+
//if (dataBind instanceof ObjectDataBind) {
|
|
952
|
+
if (!isDataBind(dataBind)) {
|
|
953
|
+
return Object.entries(dataBind).reduce(function(result, param) {
|
|
954
|
+
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
955
|
+
// objectDataBind的元素,跳过下一次赋值
|
|
956
|
+
if (dataBind.fieldCode === fieldCode) {
|
|
957
|
+
return result[key];
|
|
881
958
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
959
|
+
return result;
|
|
960
|
+
}, state);
|
|
961
|
+
} else {
|
|
962
|
+
return state;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
key: "getData",
|
|
968
|
+
value: function getData(dataCode) {
|
|
969
|
+
if (!dataCode) return;
|
|
970
|
+
var dataBindMapping = this.getDataBindMapping(dataCode);
|
|
971
|
+
var controlIdMapping = this.getControlIdMapping();
|
|
972
|
+
if (dataBindMapping) {
|
|
973
|
+
var controlId = dataBindMapping.controlId;
|
|
974
|
+
var getFieldData = this.getField(dataCode);
|
|
975
|
+
// 明细子表值
|
|
976
|
+
if (Array.isArray(getFieldData)) {
|
|
977
|
+
var data = getFieldData.map(function(item) {
|
|
978
|
+
var obj = {};
|
|
979
|
+
for(var key in item){
|
|
980
|
+
var _controlIdMapping_controlId_children_key, _controlIdMapping_controlId, _controlIdMapping_controlId_children_key_dataBind;
|
|
981
|
+
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;
|
|
900
982
|
//未绑定字段的控件,直接抛弃
|
|
901
983
|
if (fieldCode !== "") {
|
|
984
|
+
var _controlIdMapping_controlId1;
|
|
902
985
|
if (fieldCode) {
|
|
903
|
-
|
|
904
|
-
} else {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
986
|
+
obj[fieldCode] = item[key];
|
|
987
|
+
} else if ((_controlIdMapping_controlId1 = controlIdMapping[controlId]) === null || _controlIdMapping_controlId1 === void 0 ? void 0 : _controlIdMapping_controlId1.children[key]) {
|
|
988
|
+
// 兼容一个控件需要绑定多个字段的情况
|
|
989
|
+
for(var keyChi in item[key]){
|
|
990
|
+
var _controlIdMapping_controlId_children_key1, _controlIdMapping_controlId2;
|
|
991
|
+
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];
|
|
908
992
|
}
|
|
909
993
|
}
|
|
910
994
|
}
|
|
911
995
|
}
|
|
912
|
-
return
|
|
996
|
+
return obj;
|
|
913
997
|
});
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
var
|
|
918
|
-
|
|
919
|
-
|
|
998
|
+
return data;
|
|
999
|
+
} else {
|
|
1000
|
+
var _loop = function(key) {
|
|
1001
|
+
var _controlIdMapping_key, _controlIdMapping_key_dataBind, _controlIdMapping_key1, _controlIdMapping_key_dataBind1;
|
|
1002
|
+
if ((_controlIdMapping_key = controlIdMapping[key]) === null || _controlIdMapping_key === void 0 ? void 0 : (_controlIdMapping_key_dataBind = _controlIdMapping_key.dataBind) === null || _controlIdMapping_key_dataBind === void 0 ? void 0 : _controlIdMapping_key_dataBind.fieldCode) {
|
|
1003
|
+
var _controlIdMapping_key2;
|
|
1004
|
+
obj[(_controlIdMapping_key2 = controlIdMapping[key]) === null || _controlIdMapping_key2 === void 0 ? void 0 : _controlIdMapping_key2.dataBind.fieldCode] = getFieldData[key];
|
|
1005
|
+
} else if ((_controlIdMapping_key1 = controlIdMapping[key]) === null || _controlIdMapping_key1 === void 0 ? void 0 : (_controlIdMapping_key_dataBind1 = _controlIdMapping_key1.dataBind) === null || _controlIdMapping_key_dataBind1 === void 0 ? void 0 : _controlIdMapping_key_dataBind1.dataCode) {
|
|
1006
|
+
var _controlIdMapping_key3;
|
|
1007
|
+
// 明细字表只循环一层明细子表未递归
|
|
1008
|
+
obj[(_controlIdMapping_key3 = controlIdMapping[key]) === null || _controlIdMapping_key3 === void 0 ? void 0 : _controlIdMapping_key3.dataBind.dataCode] = getFieldData[key].map(function(item) {
|
|
1009
|
+
var objChi = {};
|
|
1010
|
+
for(var keyChi in item){
|
|
1011
|
+
var _controlIdMapping_key_children_keyChi;
|
|
1012
|
+
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;
|
|
1013
|
+
//未绑定字段的控件,直接抛弃
|
|
1014
|
+
if (fieldCode !== "") {
|
|
1015
|
+
if (fieldCode) {
|
|
1016
|
+
objChi[fieldCode] = item[keyChi];
|
|
1017
|
+
} else {
|
|
1018
|
+
for(var keyChi1 in item[keyChi]){
|
|
1019
|
+
var _controlIdMapping_key_children_keyChi1;
|
|
1020
|
+
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];
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return objChi;
|
|
1026
|
+
});
|
|
1027
|
+
} else if (controlIdMapping[key]) {
|
|
1028
|
+
// 兼容一个控件需要绑定多个字段的情况
|
|
1029
|
+
for(var keyChi in getFieldData[key]){
|
|
1030
|
+
var _controlIdMapping_key_dataBind_keyChi, _controlIdMapping_key4;
|
|
1031
|
+
obj[(_controlIdMapping_key_dataBind_keyChi = (_controlIdMapping_key4 = controlIdMapping[key]) === null || _controlIdMapping_key4 === void 0 ? void 0 : _controlIdMapping_key4.dataBind[keyChi]) === null || _controlIdMapping_key_dataBind_keyChi === void 0 ? void 0 : _controlIdMapping_key_dataBind_keyChi.fieldCode] = getFieldData[key][keyChi];
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
// 主表
|
|
1036
|
+
var obj = {};
|
|
1037
|
+
for(var key in getFieldData)_loop(key);
|
|
1038
|
+
return obj;
|
|
920
1039
|
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
var obj = {};
|
|
924
|
-
for(var key in getFieldData)_loop(key);
|
|
925
|
-
return obj;
|
|
1040
|
+
}
|
|
1041
|
+
return;
|
|
926
1042
|
}
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
/**
|
|
1043
|
+
},
|
|
1044
|
+
{
|
|
1045
|
+
/**
|
|
931
1046
|
* 通过dataCode和fieldCode来设置控件的值
|
|
932
1047
|
* @param dataCode 模型编码 - 如果是主表的话就是主表的模型编码,明细子表的话就是子表的模型编码
|
|
933
1048
|
* @param fieldCode 字段编码 - 控件绑定的数据项的编码
|
|
934
1049
|
* @param value 修改的值
|
|
935
1050
|
* @param rowIndex 行下标 - 如果是明细子表中的控件需要提供
|
|
936
1051
|
* @param options 触发事件携带的参数
|
|
937
|
-
* */
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
var dataBind = dataBindMapping.dataBind, controlId = dataBindMapping.controlId;
|
|
943
|
-
if (_instanceof(dataBind, ObjectDataBind)) {
|
|
944
|
-
var _JSONCopy;
|
|
945
|
-
var oldState = (_JSONCopy = JSONCopy(this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : this.getEmptyState(controlId);
|
|
946
|
-
// fieldCode不代表是key,所以需要找到对应的key
|
|
947
|
-
var newState = Object.entries(dataBind).reduce(function(result, param) {
|
|
948
|
-
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
949
|
-
// objectDataBind的元素,跳过下一次赋值
|
|
950
|
-
if (dataBind.fieldCode === fieldCode) {
|
|
951
|
-
result[key] = value;
|
|
1052
|
+
* */ key: "setField",
|
|
1053
|
+
value: function setField(dataCode, fieldCode, value, rowIndex, options) {
|
|
1054
|
+
var dataBindMapping = this.getDataBindMapping(dataCode, fieldCode);
|
|
1055
|
+
if (!dataBindMapping) {
|
|
1056
|
+
return;
|
|
952
1057
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1058
|
+
var dataBind = dataBindMapping.dataBind, controlId = dataBindMapping.controlId;
|
|
1059
|
+
// if (dataBind instanceof ObjectDataBind) {
|
|
1060
|
+
if (!isDataBind(dataBind)) {
|
|
1061
|
+
var _JSONCopy;
|
|
1062
|
+
var oldState = (_JSONCopy = JSONCopy(this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : this.getEmptyState(controlId);
|
|
1063
|
+
// fieldCode不代表是key,所以需要找到对应的key
|
|
1064
|
+
var newState = Object.entries(dataBind).reduce(function(result, param) {
|
|
1065
|
+
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
1066
|
+
// objectDataBind的元素,跳过下一次赋值
|
|
1067
|
+
if (dataBind.fieldCode === fieldCode) {
|
|
1068
|
+
result[key] = value;
|
|
1069
|
+
}
|
|
1070
|
+
return result;
|
|
1071
|
+
}, oldState);
|
|
1072
|
+
this.setState(controlId, newState, rowIndex, options);
|
|
1073
|
+
} else {
|
|
1074
|
+
this.setState(controlId, value, rowIndex, options);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
/**
|
|
961
1080
|
* 通过dataCode和 state来给一组控件赋值,并触发事件携带options
|
|
962
1081
|
* @param dataCode 需要赋值的目标模型
|
|
963
1082
|
* @param state 赋值对象,以fieldCode为key组成的对象
|
|
964
1083
|
* @param rowIndex 行下标,给明细子表赋值时指定赋值某行
|
|
965
1084
|
* @param options 触发事件携带的参数
|
|
966
|
-
* */
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
// 对象类型的值
|
|
982
|
-
if (_instanceof(dataBind, ObjectDataBind)) {
|
|
983
|
-
var _JSONCopy;
|
|
984
|
-
var oldState = (_JSONCopy = JSONCopy(_this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : _this.getEmptyState(controlId);
|
|
985
|
-
// fieldCode不代表是key,所以需要找到对应的key
|
|
986
|
-
var newState = Object.entries(dataBind).reduce(function(result, param) {
|
|
987
|
-
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
988
|
-
// objectDataBind的元素,跳过下一次赋值
|
|
989
|
-
skipKeys.push(dataBind.fieldCode);
|
|
990
|
-
var value = state[dataBind.fieldCode];
|
|
991
|
-
if (value !== undefined) {
|
|
992
|
-
result[key] = value;
|
|
1085
|
+
* */ key: "setFields",
|
|
1086
|
+
value: function setFields(dataCode, state, rowIndex, options) {
|
|
1087
|
+
var _this = this;
|
|
1088
|
+
var mapping = this.getDataBindMapping(dataCode);
|
|
1089
|
+
if (!mapping) {
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
var skipKeys = [];
|
|
1093
|
+
mapping.fields.forEach(function(item) {
|
|
1094
|
+
var dataBind = item.dataBind, controlId = item.controlId, fieldCode = item.fieldCode;
|
|
1095
|
+
if (skipKeys.includes(fieldCode)) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (!Object.hasOwnProperty.call(state, fieldCode)) {
|
|
1099
|
+
return;
|
|
993
1100
|
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1101
|
+
// 对象类型的值
|
|
1102
|
+
// if (dataBind instanceof ObjectDataBind) {
|
|
1103
|
+
if (!isDataBind(dataBind)) {
|
|
1104
|
+
var _JSONCopy;
|
|
1105
|
+
var oldState = (_JSONCopy = JSONCopy(_this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : _this.getEmptyState(controlId);
|
|
1106
|
+
// fieldCode不代表是key,所以需要找到对应的key
|
|
1107
|
+
var newState = Object.entries(dataBind).reduce(function(result, param) {
|
|
1108
|
+
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
1109
|
+
// objectDataBind的元素,跳过下一次赋值
|
|
1110
|
+
skipKeys.push(dataBind.fieldCode);
|
|
1111
|
+
var value = state[dataBind.fieldCode];
|
|
1112
|
+
if (value !== undefined) {
|
|
1113
|
+
result[key] = value;
|
|
1114
|
+
}
|
|
1115
|
+
return result;
|
|
1116
|
+
}, oldState);
|
|
1117
|
+
_this.setState(item.controlId, newState, rowIndex, options);
|
|
1118
|
+
} else {
|
|
1119
|
+
_this.setState(controlId, state[fieldCode], rowIndex, options);
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
999
1122
|
}
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
/**
|
|
1003
1126
|
* 通过dataCode来将state转化为标准的state结构
|
|
1004
1127
|
* @param dataCode 需要转换的目标模型code
|
|
1005
1128
|
* @param state 值对象,以fieldCode为key组成的对象
|
|
1006
|
-
* */
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1129
|
+
* */ key: "buildFields",
|
|
1130
|
+
value: function buildFields(dataCode, state) {
|
|
1131
|
+
var _this = this;
|
|
1132
|
+
var mapping = this.getDataBindMapping(dataCode);
|
|
1133
|
+
if (!mapping) {
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
var skipKeys = [];
|
|
1137
|
+
var result = {};
|
|
1138
|
+
mapping.fields.forEach(function(item) {
|
|
1139
|
+
var dataBind = item.dataBind, controlId = item.controlId, fieldCode = item.fieldCode;
|
|
1140
|
+
if (skipKeys.includes(fieldCode)) {
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
if (!Object.hasOwnProperty.call(state, fieldCode)) {
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
// 对象类型的值
|
|
1147
|
+
// if (dataBind instanceof ObjectDataBind) {
|
|
1148
|
+
if (!isDataBind(dataBind)) {
|
|
1149
|
+
var oldState = _this.getEmptyState(controlId);
|
|
1150
|
+
// fieldCode不代表是key,所以需要找到对应的key
|
|
1151
|
+
result[item.controlId] = Object.entries(dataBind).reduce(function(result, param) {
|
|
1152
|
+
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
1153
|
+
// objectDataBind的元素,跳过下一次赋值
|
|
1154
|
+
skipKeys.push(dataBind.fieldCode);
|
|
1155
|
+
var value = state[dataBind.fieldCode];
|
|
1156
|
+
if (value !== undefined) {
|
|
1157
|
+
result[key] = value;
|
|
1158
|
+
}
|
|
1159
|
+
return result;
|
|
1160
|
+
}, oldState);
|
|
1161
|
+
} else {
|
|
1162
|
+
result[controlId] = state[fieldCode];
|
|
1033
1163
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
} else {
|
|
1037
|
-
result[controlId] = state[fieldCode];
|
|
1164
|
+
});
|
|
1165
|
+
return result;
|
|
1038
1166
|
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
/**
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
/**
|
|
1043
1170
|
* 向Store设置一组值,并触发事件携带options
|
|
1044
1171
|
* @param dataSet
|
|
1045
1172
|
* @options 传递给关联事件中 EventPayload中的options,一般在plugin中监听使用
|
|
1046
|
-
*/
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}
|
|
1057
|
-
if (!newState[mapping.dataViewId]) {
|
|
1058
|
-
newState[mapping.dataViewId] = {};
|
|
1059
|
-
}
|
|
1060
|
-
newState[mapping.dataViewId][mapping.controlId] = [];
|
|
1061
|
-
entity.map(function(row) {
|
|
1062
|
-
var newRow = JSONCopy(_this.store.emptyState[mapping.dataViewId][mapping.controlId]);
|
|
1063
|
-
var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
|
|
1064
|
-
;
|
|
1065
|
-
Object.keys(row).map(function(fieldCode) {
|
|
1066
|
-
var _this_store_dataBindMapping_dataCode, _this_store_dataBindMapping_dataCode_fields;
|
|
1067
|
-
if (skipKey.includes(fieldCode)) {
|
|
1173
|
+
*/ key: "setData",
|
|
1174
|
+
value: function setData(dataSet, options) {
|
|
1175
|
+
var _this = this;
|
|
1176
|
+
this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
|
|
1177
|
+
var newState = this.store.defaultState;
|
|
1178
|
+
Object.keys(dataSet).map(function(dataCode) {
|
|
1179
|
+
var entity = dataSet[dataCode];
|
|
1180
|
+
if (Array.isArray(entity)) {
|
|
1181
|
+
var mapping = _this.getDataBindMapping(dataCode);
|
|
1182
|
+
if (!mapping) {
|
|
1068
1183
|
return;
|
|
1069
1184
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
});
|
|
1073
|
-
if (fieldMapping) {
|
|
1074
|
-
if (_instanceof(fieldMapping.dataBind, DataBind) && row[fieldCode] !== undefined) {
|
|
1075
|
-
newRow[fieldMapping.controlId] = row[fieldCode];
|
|
1076
|
-
} else if (_instanceof(fieldMapping.dataBind, ObjectDataBind)) {
|
|
1077
|
-
var _this_getEmptyState;
|
|
1078
|
-
var objValue = JSONCopy((_this_getEmptyState = _this.getEmptyState(fieldMapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {});
|
|
1079
|
-
Object.keys(fieldMapping.dataBind).map(function(key) {
|
|
1080
|
-
var dataBind = fieldMapping.dataBind[key];
|
|
1081
|
-
if (row[dataBind.fieldCode] !== undefined) {
|
|
1082
|
-
objValue[key] = row[dataBind.fieldCode];
|
|
1083
|
-
}
|
|
1084
|
-
skipKey.push(dataBind.fieldCode);
|
|
1085
|
-
});
|
|
1086
|
-
newRow[fieldMapping.controlId] = objValue;
|
|
1087
|
-
}
|
|
1185
|
+
if (!newState[mapping.dataViewId]) {
|
|
1186
|
+
newState[mapping.dataViewId] = {};
|
|
1088
1187
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
|
|
1095
|
-
;
|
|
1096
|
-
var emptyState = JSONCopy(_this.store.emptyState);
|
|
1097
|
-
if (!((_Object_keys = Object.keys(entity)) === null || _Object_keys === void 0 ? void 0 : _Object_keys.length)) {
|
|
1098
|
-
// newState = this.store.defaultState
|
|
1099
|
-
} else {
|
|
1100
|
-
Object.keys(entity).map(function(fieldCode) {
|
|
1101
|
-
if (skipKey.includes(fieldCode)) {
|
|
1102
|
-
return;
|
|
1188
|
+
if (!entity.length) {
|
|
1189
|
+
var _newState_mapping_dataViewId_mapping_controlId;
|
|
1190
|
+
newState[mapping.dataViewId][mapping.controlId] = (_newState_mapping_dataViewId_mapping_controlId = newState[mapping.dataViewId][mapping.controlId]) !== null && _newState_mapping_dataViewId_mapping_controlId !== void 0 ? _newState_mapping_dataViewId_mapping_controlId : [];
|
|
1191
|
+
} else {
|
|
1192
|
+
newState[mapping.dataViewId][mapping.controlId] = [];
|
|
1103
1193
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
var
|
|
1114
|
-
|
|
1115
|
-
var dataBind = mapping.dataBind[key];
|
|
1116
|
-
if (entity[dataBind.fieldCode] !== undefined) {
|
|
1117
|
-
objValue[key] = entity[dataBind.fieldCode];
|
|
1118
|
-
}
|
|
1119
|
-
skipKey.push(dataBind.fieldCode);
|
|
1194
|
+
entity.map(function(row) {
|
|
1195
|
+
var newRow = JSONCopy(_this.store.emptyState[mapping.dataViewId][mapping.controlId]);
|
|
1196
|
+
var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
|
|
1197
|
+
;
|
|
1198
|
+
Object.keys(row).map(function(fieldCode) {
|
|
1199
|
+
var _this_store_dataBindMapping_dataCode, _this_store_dataBindMapping_dataCode_fields;
|
|
1200
|
+
if (skipKey.includes(fieldCode)) {
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
var fieldMapping = (_this_store_dataBindMapping_dataCode = _this.store.dataBindMapping[dataCode]) === null || _this_store_dataBindMapping_dataCode === void 0 ? void 0 : (_this_store_dataBindMapping_dataCode_fields = _this_store_dataBindMapping_dataCode.fields) === null || _this_store_dataBindMapping_dataCode_fields === void 0 ? void 0 : _this_store_dataBindMapping_dataCode_fields.find(function(i) {
|
|
1204
|
+
return i.fieldCode === fieldCode;
|
|
1120
1205
|
});
|
|
1121
|
-
|
|
1122
|
-
|
|
1206
|
+
if (fieldMapping) {
|
|
1207
|
+
if (// fieldMapping.dataBind instanceof DataBind &&
|
|
1208
|
+
isDataBind(fieldMapping.dataBind) && row[fieldCode] !== undefined) {
|
|
1209
|
+
newRow[fieldMapping.controlId] = row[fieldCode];
|
|
1210
|
+
// } else if (fieldMapping.dataBind instanceof ObjectDataBind) {
|
|
1211
|
+
} else if (!isDataBind(fieldMapping.dataBind)) {
|
|
1212
|
+
var _this_getEmptyState;
|
|
1213
|
+
var objValue = JSONCopy((_this_getEmptyState = _this.getEmptyState(fieldMapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {});
|
|
1214
|
+
Object.keys(fieldMapping.dataBind).map(function(key) {
|
|
1215
|
+
var dataBind = fieldMapping.dataBind[key];
|
|
1216
|
+
if (row[dataBind.fieldCode] !== undefined) {
|
|
1217
|
+
objValue[key] = row[dataBind.fieldCode];
|
|
1218
|
+
}
|
|
1219
|
+
skipKey.push(dataBind.fieldCode);
|
|
1220
|
+
});
|
|
1221
|
+
newRow[fieldMapping.controlId] = objValue;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
newState[mapping.dataViewId][mapping.controlId].push(newRow);
|
|
1226
|
+
});
|
|
1227
|
+
} else if (entity) {
|
|
1228
|
+
var _Object_keys;
|
|
1229
|
+
var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
|
|
1230
|
+
;
|
|
1231
|
+
var emptyState = JSONCopy(_this.store.emptyState);
|
|
1232
|
+
if (!((_Object_keys = Object.keys(entity)) === null || _Object_keys === void 0 ? void 0 : _Object_keys.length)) {
|
|
1233
|
+
// newState = this.store.defaultState
|
|
1234
|
+
} else {
|
|
1235
|
+
Object.keys(entity).map(function(fieldCode) {
|
|
1236
|
+
if (skipKey.includes(fieldCode)) {
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
var mapping = _this.getDataBindMapping(dataCode, fieldCode);
|
|
1240
|
+
if (mapping) {
|
|
1241
|
+
if (!newState[mapping.dataViewId[0]]) {
|
|
1242
|
+
newState[mapping.dataViewId[0]] = {};
|
|
1243
|
+
}
|
|
1244
|
+
if (// mapping.dataBind instanceof DataBind &&
|
|
1245
|
+
isDataBind(mapping.dataBind) && entity[fieldCode] !== undefined) {
|
|
1246
|
+
newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode] !== undefined ? entity[fieldCode] : emptyState[mapping.dataViewId[0]][mapping.controlId];
|
|
1247
|
+
// } else if (mapping.dataBind instanceof ObjectDataBind) {
|
|
1248
|
+
} else if (!isDataBind(mapping.dataBind)) {
|
|
1249
|
+
var _this_getEmptyState;
|
|
1250
|
+
var objValue = (_this_getEmptyState = _this.getEmptyState(mapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {};
|
|
1251
|
+
Object.keys(mapping.dataBind).map(function(key) {
|
|
1252
|
+
var dataBind = mapping.dataBind[key];
|
|
1253
|
+
if (entity[dataBind.fieldCode] !== undefined) {
|
|
1254
|
+
objValue[key] = entity[dataBind.fieldCode];
|
|
1255
|
+
}
|
|
1256
|
+
skipKey.push(dataBind.fieldCode);
|
|
1257
|
+
});
|
|
1258
|
+
newState[mapping.dataViewId[0]][mapping.controlId] = objValue;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1123
1262
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
}
|
|
1263
|
+
var newMapping = _this.getDataBindMapping(dataCode);
|
|
1264
|
+
if (newMapping) {
|
|
1265
|
+
var _newMapping_fields;
|
|
1266
|
+
var mappingKeys = newMapping === null || newMapping === void 0 ? void 0 : (_newMapping_fields = newMapping.fields) === null || _newMapping_fields === void 0 ? void 0 : _newMapping_fields.map(function(item) {
|
|
1267
|
+
return item === null || item === void 0 ? void 0 : item.controlId;
|
|
1268
|
+
});
|
|
1269
|
+
var mappingValue = _this.getEmptyState(newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId);
|
|
1270
|
+
var _newState_newMapping_controlId;
|
|
1271
|
+
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 : {});
|
|
1272
|
+
mappingKeys === null || mappingKeys === void 0 ? void 0 : mappingKeys.forEach(function(key) {
|
|
1273
|
+
if (!mainStateKeys.includes(key) && key !== "uid" && newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) {
|
|
1274
|
+
if (Object.keys(newState).length) {
|
|
1275
|
+
Object.assign(newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId], _defineProperty({}, key, mappingValue[key]));
|
|
1276
|
+
} else {
|
|
1277
|
+
Object.assign(newState, _defineProperty({}, newMapping.controlId, _defineProperty({}, key, mappingValue[key])));
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
_this.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
|
|
1142
1282
|
}
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
this.debugLog("engine setData方法数据组合完成,参数为%o。", newState);
|
|
1286
|
+
this.setStates(newState, undefined, options);
|
|
1287
|
+
this.debugLog("engine setData方法执行完成。");
|
|
1146
1288
|
}
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
this.debugLog("engine setData方法执行完成。");
|
|
1151
|
-
};
|
|
1152
|
-
/**
|
|
1289
|
+
},
|
|
1290
|
+
{
|
|
1291
|
+
/**
|
|
1153
1292
|
* 获取控件的dataBind
|
|
1154
1293
|
* @param controlId
|
|
1155
|
-
* */
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1294
|
+
* */ key: "getDataBind",
|
|
1295
|
+
value: function getDataBind(controlId) {
|
|
1296
|
+
return this.store.getDataBind(controlId);
|
|
1297
|
+
}
|
|
1298
|
+
},
|
|
1299
|
+
{
|
|
1300
|
+
/**
|
|
1159
1301
|
* 获取组件实例,传入rowIndex代表获取明细表内的控件实例,rowIndex传入-1代表获取表头内的实例
|
|
1160
1302
|
* @param controlId
|
|
1161
1303
|
* @param rowIndex
|
|
1162
|
-
*/
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1304
|
+
*/ key: "getInstance",
|
|
1305
|
+
value: function getInstance(controlId, rowIndex) {
|
|
1306
|
+
var instances = this.getInstances(controlId, rowIndex === -1);
|
|
1307
|
+
if (instances.length > 0) {
|
|
1308
|
+
if (rowIndex !== undefined) {
|
|
1309
|
+
if (rowIndex === -1) {
|
|
1310
|
+
return instances[0];
|
|
1311
|
+
}
|
|
1312
|
+
return instances[rowIndex];
|
|
1313
|
+
} else {
|
|
1314
|
+
return instances[0];
|
|
1315
|
+
}
|
|
1316
|
+
} else {
|
|
1317
|
+
return undefined;
|
|
1168
1318
|
}
|
|
1169
|
-
return instances[rowIndex];
|
|
1170
|
-
} else {
|
|
1171
|
-
return instances[0];
|
|
1172
1319
|
}
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
};
|
|
1177
|
-
/**
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
/**
|
|
1178
1323
|
* 获取组件实例,明细表中的组件将会得到数组, 第二个参数为(false/不传入)则获取到的是明细表内不包含表头内实例的所有控件实例,传入true则获取到包含表头内实例的所有控件实例,表头内实例永远在下标0的位置
|
|
1179
1324
|
* @param controlId
|
|
1180
1325
|
* @param header 明细表内是否获取表头的控件
|
|
1181
|
-
*/
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
var instances = Array.from(this.runtime.instanceMap[controlId] || []);
|
|
1191
|
-
if (header) {
|
|
1192
|
-
// 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
|
|
1193
|
-
if (instances.length) {
|
|
1194
|
-
var instance = instances[0];
|
|
1195
|
-
if (this.inList(instance.id) !== undefined) {
|
|
1196
|
-
var headerInstance = this.getInstanceInSubtableHeader(instance);
|
|
1197
|
-
if (headerInstance) {
|
|
1198
|
-
instances.unshift(headerInstance);
|
|
1199
|
-
}
|
|
1326
|
+
*/ key: "getInstances",
|
|
1327
|
+
value: function getInstances(controlId) {
|
|
1328
|
+
var header = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
1329
|
+
// const cc = console
|
|
1330
|
+
// const label = '🐑 genInstances ' + controlId + ' ' + Date.now()
|
|
1331
|
+
// cc.time(label)
|
|
1332
|
+
if (controlId === undefined) {
|
|
1333
|
+
// cc.timeEnd(label)
|
|
1334
|
+
return this.runtime.flatInstances;
|
|
1200
1335
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
return
|
|
1220
|
-
});
|
|
1221
|
-
if (
|
|
1222
|
-
|
|
1336
|
+
var instances = Array.from(this.runtime.instanceMap[controlId] || []);
|
|
1337
|
+
if (header) {
|
|
1338
|
+
// 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
|
|
1339
|
+
if (instances.length) {
|
|
1340
|
+
var instance = instances[0];
|
|
1341
|
+
// if (this.inList(instance.id) === true) {
|
|
1342
|
+
if (this.inList(instance.id) !== undefined) {
|
|
1343
|
+
var headerInstance = this.getInstanceInSubtableHeader(instance);
|
|
1344
|
+
if (headerInstance) {
|
|
1345
|
+
instances.unshift(headerInstance);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
} else {
|
|
1349
|
+
var _this_getControlIdMapping;
|
|
1350
|
+
var controlIdMapping = (_this_getControlIdMapping = this.getControlIdMapping()) !== null && _this_getControlIdMapping !== void 0 ? _this_getControlIdMapping : {};
|
|
1351
|
+
var _Object_entries_find;
|
|
1352
|
+
var _ref = _slicedToArray((_Object_entries_find = Object.entries(controlIdMapping).find(function(param) {
|
|
1353
|
+
var _param = _slicedToArray(param, 2), _ = _param[0], mapping = _param[1];
|
|
1354
|
+
return mapping.children && controlId in mapping.children;
|
|
1355
|
+
})) !== null && _Object_entries_find !== void 0 ? _Object_entries_find : [], 1), subtableId = _ref[0];
|
|
1356
|
+
if (subtableId) {
|
|
1357
|
+
var subtable = this.getInstance(subtableId);
|
|
1358
|
+
// @ts-ignore
|
|
1359
|
+
var headerColumn = subtable.props.headers.find(function(column) {
|
|
1360
|
+
return column.children.find(function(item) {
|
|
1361
|
+
return item.id === controlId;
|
|
1362
|
+
});
|
|
1363
|
+
});
|
|
1364
|
+
if (headerColumn) {
|
|
1365
|
+
var headerInstance1 = headerColumn.children.find(function(item) {
|
|
1366
|
+
return item.id === controlId;
|
|
1367
|
+
});
|
|
1368
|
+
if (headerInstance1) {
|
|
1369
|
+
instances.unshift(headerInstance1);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1223
1372
|
}
|
|
1224
1373
|
}
|
|
1225
1374
|
}
|
|
1375
|
+
// @ts-ignore
|
|
1376
|
+
return instances;
|
|
1226
1377
|
}
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
key: "setInstance",
|
|
1381
|
+
value: function setInstance(instance, props, value, rowIndex) {
|
|
1382
|
+
var _this = this;
|
|
1383
|
+
try {
|
|
1384
|
+
if (typeof instance === "string" && rowIndex === -1) {
|
|
1385
|
+
//修改明细表整列属性的逻辑
|
|
1386
|
+
var instances = this.getInstances(instance, rowIndex === -1);
|
|
1387
|
+
instances.map(function(_instance) {
|
|
1388
|
+
if (_instance) {
|
|
1389
|
+
_this.debugLog("[%o]: 修改instance: %o的%o属性,修改的值为%o。", _instance.id, _instance, props, value);
|
|
1390
|
+
updateValueFromKeys(_instance.props, props, value);
|
|
1391
|
+
_this.schemaEvent("schema-change", {
|
|
1392
|
+
instance: _instance,
|
|
1393
|
+
props: props,
|
|
1394
|
+
value: value,
|
|
1395
|
+
rowIndex: rowIndex
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
} else {
|
|
1400
|
+
var _instance;
|
|
1401
|
+
if (typeof instance === "string") {
|
|
1402
|
+
_instance = this.getInstance(instance, rowIndex);
|
|
1403
|
+
} else {
|
|
1404
|
+
_instance = instance;
|
|
1405
|
+
}
|
|
1406
|
+
if (!_instance) {
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
this.debugLog("[%o]: 修改instance: %o的%o属性,修改的值为%o。", _instance.id, _instance, props, value);
|
|
1240
1410
|
updateValueFromKeys(_instance.props, props, value);
|
|
1241
|
-
|
|
1411
|
+
this.schemaEvent("schema-change", {
|
|
1242
1412
|
instance: _instance,
|
|
1243
1413
|
props: props,
|
|
1244
1414
|
value: value,
|
|
1245
1415
|
rowIndex: rowIndex
|
|
1246
1416
|
});
|
|
1247
1417
|
}
|
|
1248
|
-
})
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1418
|
+
} catch (e) {
|
|
1419
|
+
throw e;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
},
|
|
1423
|
+
{
|
|
1424
|
+
key: "getControlIdMapping",
|
|
1425
|
+
value: function getControlIdMapping() {
|
|
1426
|
+
return this.store.controlIdMapping;
|
|
1427
|
+
}
|
|
1428
|
+
},
|
|
1429
|
+
{
|
|
1430
|
+
key: "getDataBindMapping",
|
|
1431
|
+
value: function getDataBindMapping(dataCode, fieldCode) {
|
|
1432
|
+
if (!dataCode && !fieldCode) {
|
|
1433
|
+
return this.store.dataBindMapping;
|
|
1255
1434
|
}
|
|
1256
|
-
|
|
1435
|
+
var mapping = this.store.dataBindMapping[dataCode];
|
|
1436
|
+
if (!mapping) {
|
|
1437
|
+
warn("No corresponding dataCode=".concat(dataCode, " was found"));
|
|
1257
1438
|
return;
|
|
1258
1439
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
value: value,
|
|
1265
|
-
rowIndex: rowIndex
|
|
1440
|
+
if (!fieldCode) {
|
|
1441
|
+
return mapping;
|
|
1442
|
+
}
|
|
1443
|
+
var dataBindMapping = mapping.fields.find(function(item) {
|
|
1444
|
+
return item.fieldCode === fieldCode;
|
|
1266
1445
|
});
|
|
1446
|
+
if (!dataBindMapping) {
|
|
1447
|
+
warn("No corresponding fieldCode=".concat(fieldCode, " was found"));
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
return dataBindMapping;
|
|
1267
1451
|
}
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
if (!dataBindMapping) {
|
|
1291
|
-
warn("No corresponding fieldCode=".concat(fieldCode, " was found"));
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
return dataBindMapping;
|
|
1295
|
-
};
|
|
1296
|
-
_proto.getAction = function getAction() {
|
|
1297
|
-
return this.actionManager;
|
|
1298
|
-
};
|
|
1299
|
-
_proto.initDataManager = function initDataManager(callbackExecuter) {
|
|
1300
|
-
this.dataManager = new DataManager(callbackExecuter);
|
|
1301
|
-
};
|
|
1302
|
-
_proto.getDataManager = function getDataManager() {
|
|
1303
|
-
return this.dataManager;
|
|
1304
|
-
};
|
|
1305
|
-
/**
|
|
1452
|
+
},
|
|
1453
|
+
{
|
|
1454
|
+
key: "getAction",
|
|
1455
|
+
value: function getAction() {
|
|
1456
|
+
return this.actionManager;
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
{
|
|
1460
|
+
key: "initDataManager",
|
|
1461
|
+
value: function initDataManager(callbackExecuter) {
|
|
1462
|
+
this.dataManager = new DataManager(callbackExecuter);
|
|
1463
|
+
}
|
|
1464
|
+
},
|
|
1465
|
+
{
|
|
1466
|
+
key: "getDataManager",
|
|
1467
|
+
value: function getDataManager() {
|
|
1468
|
+
return this.dataManager;
|
|
1469
|
+
}
|
|
1470
|
+
},
|
|
1471
|
+
{
|
|
1472
|
+
key: "assertInstance",
|
|
1473
|
+
value: /**
|
|
1306
1474
|
* 判断控件的类型,返回当前控件的正确类型
|
|
1307
|
-
* */
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1475
|
+
* */ function assertInstance(instance, types) {
|
|
1476
|
+
return isString(types) ? instance.type === types : types.includes(instance.type);
|
|
1477
|
+
}
|
|
1478
|
+
},
|
|
1479
|
+
{
|
|
1480
|
+
key: "getInstanceRowIndex",
|
|
1481
|
+
value: /**
|
|
1311
1482
|
* 获取控件在明细子表中的行下标,
|
|
1312
1483
|
* 如果控件在表头内,则返回-1
|
|
1313
1484
|
* 如果控件在表内,则返回行下标
|
|
1314
1485
|
* 如果控件不在明细表内,则返回undefined
|
|
1315
|
-
* */
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
// @ts-ignore
|
|
1321
|
-
if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
|
|
1322
|
-
// 表头内的控件
|
|
1323
|
-
// @ts-ignore
|
|
1324
|
-
if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
|
|
1325
|
-
rowIndex = -1;
|
|
1326
|
-
} else {
|
|
1486
|
+
* */ function getInstanceRowIndex(instance) {
|
|
1487
|
+
if (!instance.parent) {
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
var rowIndex;
|
|
1327
1491
|
// @ts-ignore
|
|
1328
|
-
|
|
1329
|
-
|
|
1492
|
+
if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
|
|
1493
|
+
// 表头内的控件
|
|
1494
|
+
// @ts-ignore
|
|
1495
|
+
if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
|
|
1496
|
+
rowIndex = -1;
|
|
1497
|
+
} else {
|
|
1498
|
+
// @ts-ignore
|
|
1499
|
+
var index = instance.parent.children.findIndex(function(item) {
|
|
1500
|
+
return item === instance;
|
|
1501
|
+
});
|
|
1502
|
+
if (index > -1) {
|
|
1503
|
+
rowIndex = index;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
} else {
|
|
1507
|
+
rowIndex = this.getInstanceRowIndex(instance.parent);
|
|
1508
|
+
}
|
|
1509
|
+
return rowIndex;
|
|
1510
|
+
}
|
|
1511
|
+
},
|
|
1512
|
+
{
|
|
1513
|
+
key: "getInstanceParentControl",
|
|
1514
|
+
value: // public getInstanceRowIndex(
|
|
1515
|
+
// instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
|
|
1516
|
+
// ) {
|
|
1517
|
+
// let rowIndex: number | undefined
|
|
1518
|
+
// // @ts-ignore
|
|
1519
|
+
// if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
|
|
1520
|
+
// rowIndex = -1
|
|
1521
|
+
// }else{
|
|
1522
|
+
// const instanceList = this.runtime.instanceMap[instance.id]
|
|
1523
|
+
// if(Object.prototype.toString.call(instanceList) === '[object Array]'){
|
|
1524
|
+
// const index = instanceList.findIndex(
|
|
1525
|
+
// (item: any) => item === instance
|
|
1526
|
+
// )
|
|
1527
|
+
// if (index > -1) {
|
|
1528
|
+
// rowIndex = index
|
|
1529
|
+
// }
|
|
1530
|
+
// }
|
|
1531
|
+
// }
|
|
1532
|
+
// return rowIndex
|
|
1533
|
+
// }
|
|
1534
|
+
function getInstanceParentControl(instance, controlType) {
|
|
1535
|
+
if (!instance.parent) {
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
if (this.assertInstance(instance.parent, controlType)) {
|
|
1539
|
+
return instance.parent;
|
|
1540
|
+
}
|
|
1541
|
+
return this.getInstanceParentControl(instance.parent, controlType);
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1544
|
+
{
|
|
1545
|
+
key: "getInstanceInSubtableHeader",
|
|
1546
|
+
value: function getInstanceInSubtableHeader(instance) {
|
|
1547
|
+
var rowIndex = this.getInstanceRowIndex(instance);
|
|
1548
|
+
if (rowIndex === undefined) {
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
if (rowIndex === -1) {
|
|
1552
|
+
return instance;
|
|
1553
|
+
}
|
|
1554
|
+
var columnInstance = this.assertInstance(instance, // @ts-ignore
|
|
1555
|
+
CONTROL_TYPE.SUBTABLE_COLUMN) ? instance : this.getInstanceParentControl(instance, // @ts-ignore
|
|
1556
|
+
CONTROL_TYPE.SUBTABLE_COLUMN);
|
|
1557
|
+
if (!columnInstance) {
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
var subtable = this.getInstanceParentControl(instance, // @ts-ignore
|
|
1561
|
+
CONTROL_TYPE.SUBTABLE);
|
|
1562
|
+
// @ts-ignore
|
|
1563
|
+
var headerColumn = subtable.props.headers.find(// @ts-ignore
|
|
1564
|
+
function(column) {
|
|
1565
|
+
return column.id === columnInstance.id;
|
|
1330
1566
|
});
|
|
1331
|
-
if (
|
|
1332
|
-
|
|
1567
|
+
if (!headerColumn) {
|
|
1568
|
+
return;
|
|
1333
1569
|
}
|
|
1570
|
+
return headerColumn.children.find(// @ts-ignore
|
|
1571
|
+
function(item) {
|
|
1572
|
+
return item.id === instance.id;
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
},
|
|
1576
|
+
{
|
|
1577
|
+
key: "setControlConfig",
|
|
1578
|
+
value: function setControlConfig() {
|
|
1579
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
1580
|
+
args[_key] = arguments[_key];
|
|
1581
|
+
}
|
|
1582
|
+
var _this_runtime;
|
|
1583
|
+
return (_this_runtime = this.runtime).registerControlConfig.apply(_this_runtime, _toConsumableArray(args));
|
|
1584
|
+
}
|
|
1585
|
+
},
|
|
1586
|
+
{
|
|
1587
|
+
key: "getControlConfig",
|
|
1588
|
+
value: function getControlConfig(control) {
|
|
1589
|
+
return this.runtime.getControlConfig(control);
|
|
1590
|
+
}
|
|
1591
|
+
},
|
|
1592
|
+
{
|
|
1593
|
+
key: "inList",
|
|
1594
|
+
value: function inList(controlId) {
|
|
1595
|
+
var _this_store_controlIdMapping;
|
|
1596
|
+
var mapping = (_this_store_controlIdMapping = this.store.controlIdMapping) !== null && _this_store_controlIdMapping !== void 0 ? _this_store_controlIdMapping : {};
|
|
1597
|
+
var listKey = undefined;
|
|
1598
|
+
Object.keys(mapping).some(function(key) {
|
|
1599
|
+
var _mapping_key, _mapping_key_children;
|
|
1600
|
+
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);
|
|
1601
|
+
if (matched) {
|
|
1602
|
+
listKey = key;
|
|
1603
|
+
}
|
|
1604
|
+
return matched;
|
|
1605
|
+
});
|
|
1606
|
+
return listKey;
|
|
1334
1607
|
}
|
|
1335
|
-
} else {
|
|
1336
|
-
rowIndex = this.getInstanceRowIndex(instance.parent);
|
|
1337
|
-
}
|
|
1338
|
-
return rowIndex;
|
|
1339
|
-
};
|
|
1340
|
-
_proto.getInstanceParentControl = function getInstanceParentControl(instance, controlType) {
|
|
1341
|
-
if (!instance.parent) {
|
|
1342
|
-
return;
|
|
1343
|
-
}
|
|
1344
|
-
if (this.assertInstance(instance.parent, controlType)) {
|
|
1345
|
-
return instance.parent;
|
|
1346
|
-
}
|
|
1347
|
-
return this.getInstanceParentControl(instance.parent, controlType);
|
|
1348
|
-
};
|
|
1349
|
-
_proto.getInstanceInSubtableHeader = function getInstanceInSubtableHeader(instance) {
|
|
1350
|
-
var rowIndex = this.getInstanceRowIndex(instance);
|
|
1351
|
-
if (rowIndex === undefined) {
|
|
1352
|
-
return;
|
|
1353
|
-
}
|
|
1354
|
-
if (rowIndex === -1) {
|
|
1355
|
-
return instance;
|
|
1356
|
-
}
|
|
1357
|
-
var columnInstance = this.assertInstance(instance, // @ts-ignore
|
|
1358
|
-
CONTROL_TYPE.SUBTABLE_COLUMN) ? instance : this.getInstanceParentControl(instance, // @ts-ignore
|
|
1359
|
-
CONTROL_TYPE.SUBTABLE_COLUMN);
|
|
1360
|
-
if (!columnInstance) {
|
|
1361
|
-
return;
|
|
1362
|
-
}
|
|
1363
|
-
var subtable = this.getInstanceParentControl(instance, // @ts-ignore
|
|
1364
|
-
CONTROL_TYPE.SUBTABLE);
|
|
1365
|
-
// @ts-ignore
|
|
1366
|
-
var headerColumn = subtable.props.headers.find(// @ts-ignore
|
|
1367
|
-
function(column) {
|
|
1368
|
-
return column.id === columnInstance.id;
|
|
1369
|
-
});
|
|
1370
|
-
if (!headerColumn) {
|
|
1371
|
-
return;
|
|
1372
|
-
}
|
|
1373
|
-
return headerColumn.children.find(// @ts-ignore
|
|
1374
|
-
function(item) {
|
|
1375
|
-
return item.id === instance.id;
|
|
1376
|
-
});
|
|
1377
|
-
};
|
|
1378
|
-
_proto.setControlConfig = function setControlConfig() {
|
|
1379
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
1380
|
-
args[_key] = arguments[_key];
|
|
1381
1608
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1609
|
+
], [
|
|
1610
|
+
{
|
|
1611
|
+
key: "register",
|
|
1612
|
+
value: // 注册外部控件
|
|
1613
|
+
function register() {
|
|
1614
|
+
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
1615
|
+
arg[_key] = arguments[_key];
|
|
1616
|
+
}
|
|
1617
|
+
var _Runtime;
|
|
1618
|
+
return (_Runtime = Runtime).register.apply(_Runtime, _toConsumableArray(arg));
|
|
1619
|
+
}
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
key: "judgeControlIsRegistered",
|
|
1623
|
+
value: function judgeControlIsRegistered(control) {
|
|
1624
|
+
return Runtime.staticRegisteredTypes.has(control.Runtime.controlType);
|
|
1397
1625
|
}
|
|
1398
|
-
return matched;
|
|
1399
|
-
});
|
|
1400
|
-
return listKey;
|
|
1401
|
-
};
|
|
1402
|
-
// 注册外部控件
|
|
1403
|
-
Engine.register = function register() {
|
|
1404
|
-
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
1405
|
-
arg[_key] = arguments[_key];
|
|
1406
1626
|
}
|
|
1407
|
-
|
|
1408
|
-
return (_Runtime = Runtime).register.apply(_Runtime, _toConsumableArray(arg));
|
|
1409
|
-
};
|
|
1410
|
-
Engine.judgeControlIsRegistered = function judgeControlIsRegistered(control) {
|
|
1411
|
-
return Runtime.staticRegisteredTypes.has(control.Runtime.controlType);
|
|
1412
|
-
};
|
|
1627
|
+
]);
|
|
1413
1628
|
return Engine;
|
|
1414
1629
|
}(Watcher);
|
|
1415
1630
|
export { Engine };
|