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