@byteluck-fe/model-driven-engine 1.5.0-beta.7 → 1.7.2
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 +136 -33
- package/dist/esm/common/DataManager.js +113 -18
- package/dist/esm/common/Engine.js +191 -75
- package/dist/esm/common/OkWorker.js +5 -5
- package/dist/esm/common/Store.js +70 -11
- package/dist/esm/common/checkerValue.js +2 -2
- package/dist/esm/common/proxyState.js +9 -9
- package/dist/esm/plugins/CalcPlugin.js +22 -18
- package/dist/esm/plugins/ControlsEventPlugin.js +175 -67
- package/dist/esm/plugins/ES6ModulePlugin.js +2 -2
- package/dist/esm/plugins/LifecycleEventPlugin.js +165 -61
- package/dist/esm/plugins/StylePlugin.js +3 -3
- package/dist/esm/utils/runtimeUtils.js +2 -4
- package/dist/index.umd.js +28 -2
- package/dist/types/common/Engine.d.ts +7 -5
- package/dist/types/common/Runtime.d.ts +1 -1
- package/dist/types/common/Store.d.ts +7 -5
- package/dist/types/common/proxyState.d.ts +3 -3
- package/dist/types/plugins/ControlsEventPlugin.d.ts +1 -1
- package/dist/types/plugins/ES6ModulePlugin.d.ts +4 -4
- package/dist/types/plugins/LifecycleEventPlugin.d.ts +1 -1
- package/dist/types/plugins/StylePlugin.d.ts +1 -1
- package/package.json +5 -4
|
@@ -238,7 +238,101 @@ function _createSuper(Derived) {
|
|
|
238
238
|
return _possibleConstructorReturn(this, result);
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
|
-
|
|
241
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
242
|
+
var f, y, t, g, _ = {
|
|
243
|
+
label: 0,
|
|
244
|
+
sent: function() {
|
|
245
|
+
if (t[0] & 1) throw t[1];
|
|
246
|
+
return t[1];
|
|
247
|
+
},
|
|
248
|
+
trys: [],
|
|
249
|
+
ops: []
|
|
250
|
+
};
|
|
251
|
+
return g = {
|
|
252
|
+
next: verb(0),
|
|
253
|
+
"throw": verb(1),
|
|
254
|
+
"return": verb(2)
|
|
255
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
256
|
+
return this;
|
|
257
|
+
}), g;
|
|
258
|
+
function verb(n) {
|
|
259
|
+
return function(v) {
|
|
260
|
+
return step([
|
|
261
|
+
n,
|
|
262
|
+
v
|
|
263
|
+
]);
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function step(op) {
|
|
267
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
268
|
+
while(_)try {
|
|
269
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
270
|
+
if (y = 0, t) op = [
|
|
271
|
+
op[0] & 2,
|
|
272
|
+
t.value
|
|
273
|
+
];
|
|
274
|
+
switch(op[0]){
|
|
275
|
+
case 0:
|
|
276
|
+
case 1:
|
|
277
|
+
t = op;
|
|
278
|
+
break;
|
|
279
|
+
case 4:
|
|
280
|
+
_.label++;
|
|
281
|
+
return {
|
|
282
|
+
value: op[1],
|
|
283
|
+
done: false
|
|
284
|
+
};
|
|
285
|
+
case 5:
|
|
286
|
+
_.label++;
|
|
287
|
+
y = op[1];
|
|
288
|
+
op = [
|
|
289
|
+
0
|
|
290
|
+
];
|
|
291
|
+
continue;
|
|
292
|
+
case 7:
|
|
293
|
+
op = _.ops.pop();
|
|
294
|
+
_.trys.pop();
|
|
295
|
+
continue;
|
|
296
|
+
default:
|
|
297
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
298
|
+
_ = 0;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
302
|
+
_.label = op[1];
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
306
|
+
_.label = t[1];
|
|
307
|
+
t = op;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
if (t && _.label < t[2]) {
|
|
311
|
+
_.label = t[2];
|
|
312
|
+
_.ops.push(op);
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
if (t[2]) _.ops.pop();
|
|
316
|
+
_.trys.pop();
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
op = body.call(thisArg, _);
|
|
320
|
+
} catch (e) {
|
|
321
|
+
op = [
|
|
322
|
+
6,
|
|
323
|
+
e
|
|
324
|
+
];
|
|
325
|
+
y = 0;
|
|
326
|
+
} finally{
|
|
327
|
+
f = t = 0;
|
|
328
|
+
}
|
|
329
|
+
if (op[0] & 5) throw op[1];
|
|
330
|
+
return {
|
|
331
|
+
value: op[0] ? op[1] : void 0,
|
|
332
|
+
done: true
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
};
|
|
242
336
|
import { DataBind, ObjectDataBind, RuntimeFormControl, RuntimeLayoutControl, RuntimeListControl } from "@byteluck-fe/model-driven-core";
|
|
243
337
|
import { CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from "@byteluck-fe/model-driven-shared";
|
|
244
338
|
import { Runtime } from "./Runtime";
|
|
@@ -273,8 +367,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
273
367
|
_this._jobTasks = [];
|
|
274
368
|
_this.createControlInstance = _this.createInstance;
|
|
275
369
|
_this.$options = Object.freeze(props);
|
|
276
|
-
var
|
|
277
|
-
language, language =
|
|
370
|
+
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,
|
|
371
|
+
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;
|
|
278
372
|
RulesMessage.setLocale(language);
|
|
279
373
|
_this.debug = debug;
|
|
280
374
|
_this.runtime = new Runtime({
|
|
@@ -308,13 +402,13 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
308
402
|
for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
|
|
309
403
|
arg[_key] = arguments[_key];
|
|
310
404
|
}
|
|
311
|
-
var
|
|
312
|
-
(
|
|
405
|
+
var _this_runtime;
|
|
406
|
+
(_this_runtime = this.runtime).register.apply(_this_runtime, _toConsumableArray(arg));
|
|
313
407
|
return this;
|
|
314
408
|
};
|
|
315
409
|
_proto.mount = function mount() {
|
|
316
410
|
this.debugLog("engine的mount方法开始调用");
|
|
317
|
-
var
|
|
411
|
+
var _this_$options = this.$options, _this_$options_plugins = _this_$options.plugins, plugins = _this_$options_plugins === void 0 ? [] : _this_$options_plugins;
|
|
318
412
|
this._handlerProxyState();
|
|
319
413
|
this.__plugins = plugins;
|
|
320
414
|
this.applyPlugins();
|
|
@@ -402,17 +496,17 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
402
496
|
switch(type){
|
|
403
497
|
case "push":
|
|
404
498
|
case "unshift":
|
|
405
|
-
var
|
|
499
|
+
var _subtable_children;
|
|
406
500
|
var newRowLengths = args.length;
|
|
407
501
|
createdNewRows = createRows(newRowLengths);
|
|
408
502
|
createdNewRowsData = args;
|
|
409
|
-
(
|
|
503
|
+
(_subtable_children = subtable.children)[type].apply(_subtable_children, _toConsumableArray(createdNewRows));
|
|
410
504
|
this.runtime.getFlatInstances();
|
|
411
505
|
break;
|
|
412
506
|
case "splice":
|
|
413
507
|
if (args.length > 2) {
|
|
414
508
|
var // @ts-ignore
|
|
415
|
-
|
|
509
|
+
_subtable_children1;
|
|
416
510
|
var newRowLengths1 = args.length - 2;
|
|
417
511
|
var newValues = args.slice(2);
|
|
418
512
|
createdNewRows = createRows(newRowLengths1);
|
|
@@ -421,7 +515,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
421
515
|
var start = args[0];
|
|
422
516
|
// 替换几个
|
|
423
517
|
var replace = args[1];
|
|
424
|
-
(
|
|
518
|
+
(_subtable_children1 = subtable.children)[type].apply(_subtable_children1, [
|
|
425
519
|
start,
|
|
426
520
|
replace
|
|
427
521
|
].concat(_toConsumableArray(createdNewRows)));
|
|
@@ -432,15 +526,15 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
432
526
|
// })
|
|
433
527
|
} else {
|
|
434
528
|
var // @ts-ignore
|
|
435
|
-
|
|
436
|
-
(
|
|
529
|
+
_subtable_children2;
|
|
530
|
+
(_subtable_children2 = subtable.children)[type].apply(_subtable_children2, _toConsumableArray(args));
|
|
437
531
|
this.runtime.getFlatInstances();
|
|
438
532
|
}
|
|
439
533
|
break;
|
|
440
534
|
default:
|
|
441
535
|
var // @ts-ignore
|
|
442
|
-
|
|
443
|
-
(
|
|
536
|
+
_subtable_children3;
|
|
537
|
+
(_subtable_children3 = subtable.children)[type].apply(_subtable_children3, _toConsumableArray(args));
|
|
444
538
|
this.runtime.getFlatInstances();
|
|
445
539
|
break;
|
|
446
540
|
}
|
|
@@ -476,7 +570,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
476
570
|
var options = eventOptionsTemp || {};
|
|
477
571
|
if (_instanceof(instance, RuntimeListControl)) {
|
|
478
572
|
var // @ts-ignore
|
|
479
|
-
|
|
573
|
+
_instance_children;
|
|
480
574
|
instance.children.length = 0;
|
|
481
575
|
var newValue = value;
|
|
482
576
|
// @ts-ignore
|
|
@@ -486,7 +580,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
486
580
|
var row = this.listControlCreateRow(instance, "subtable-row");
|
|
487
581
|
row && newRows.push(row);
|
|
488
582
|
}
|
|
489
|
-
(
|
|
583
|
+
(_instance_children = instance.children).push.apply(_instance_children, _toConsumableArray(newRows));
|
|
490
584
|
this.runtime.getFlatInstances();
|
|
491
585
|
// 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
|
|
492
586
|
// for (let i = 0; i < newValue.length; i++) {
|
|
@@ -518,8 +612,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
518
612
|
if (this.__pluginsApplied) return;
|
|
519
613
|
this.__plugins.forEach(function(plugin) {
|
|
520
614
|
try {
|
|
521
|
-
var
|
|
522
|
-
applyingPluginName = (
|
|
615
|
+
var _plugin_pluginName;
|
|
616
|
+
applyingPluginName = (_plugin_pluginName = plugin.pluginName) !== null && _plugin_pluginName !== void 0 ? _plugin_pluginName : plugin.constructor.name;
|
|
523
617
|
plugin.apply(_this);
|
|
524
618
|
} catch (e) {
|
|
525
619
|
error("".concat(applyingPluginName, " Plugin apply Error \n ").concat(e));
|
|
@@ -533,11 +627,11 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
533
627
|
var row = this.runtime.createControlInstance(rowType);
|
|
534
628
|
if (!row) return;
|
|
535
629
|
if (_instanceof(row, RuntimeLayoutControl)) {
|
|
536
|
-
var
|
|
630
|
+
var _row_children;
|
|
537
631
|
var template = JSONCopy(instance.props.headers);
|
|
538
632
|
// @ts-ignore
|
|
539
633
|
var columns = this.createControl(template);
|
|
540
|
-
(
|
|
634
|
+
(_row_children = row.children).push.apply(_row_children, _toConsumableArray(columns));
|
|
541
635
|
}
|
|
542
636
|
return row;
|
|
543
637
|
};
|
|
@@ -554,37 +648,40 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
554
648
|
var _this1 = this, _superprop_get_emit = function() {
|
|
555
649
|
return _get(_getPrototypeOf(Engine.prototype), "emit", _this);
|
|
556
650
|
};
|
|
557
|
-
return _asyncToGenerator(
|
|
651
|
+
return _asyncToGenerator(function() {
|
|
558
652
|
var needWait, promiseResolver, promise, results;
|
|
559
|
-
return
|
|
560
|
-
|
|
653
|
+
return __generator(this, function(_state) {
|
|
654
|
+
switch(_state.label){
|
|
561
655
|
case 0:
|
|
562
|
-
if (!(eventKey === "engine-mounted"))
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
case 4:
|
|
573
|
-
if (!_this1._jobTasks.length) {
|
|
574
|
-
_ctx.next = 10;
|
|
575
|
-
break;
|
|
656
|
+
if (!(eventKey === "engine-mounted")) return [
|
|
657
|
+
3,
|
|
658
|
+
3
|
|
659
|
+
];
|
|
660
|
+
if (_this1.isMounted) {
|
|
661
|
+
warn("The engine-mounted life cycle can only be triggered once");
|
|
662
|
+
return [
|
|
663
|
+
2,
|
|
664
|
+
Promise.resolve([])
|
|
665
|
+
];
|
|
576
666
|
}
|
|
667
|
+
if (!_this1._jobTasks.length) return [
|
|
668
|
+
3,
|
|
669
|
+
2
|
|
670
|
+
];
|
|
577
671
|
console.time("engine-mounted need wait");
|
|
578
672
|
needWait = _toConsumableArray(_this1._jobTasks);
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
673
|
+
return [
|
|
674
|
+
4,
|
|
675
|
+
Promise.all(needWait)
|
|
676
|
+
];
|
|
677
|
+
case 1:
|
|
678
|
+
_state.sent();
|
|
582
679
|
console.timeEnd("engine-mounted need wait");
|
|
583
|
-
|
|
680
|
+
_state.label = 2;
|
|
681
|
+
case 2:
|
|
584
682
|
_this1.isMounted = true;
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
;
|
|
683
|
+
_state.label = 3;
|
|
684
|
+
case 3:
|
|
588
685
|
// 如果没有挂载的话,需要记录在挂载之前触发的所有任务
|
|
589
686
|
if (!_this1.isMounted) {
|
|
590
687
|
promise = new Promise(function(resolve) {
|
|
@@ -592,22 +689,24 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
592
689
|
});
|
|
593
690
|
_this1._jobTasks.push(promise);
|
|
594
691
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
692
|
+
return [
|
|
693
|
+
4,
|
|
694
|
+
_superprop_get_emit().call(_this1, eventKey, payload)
|
|
695
|
+
];
|
|
696
|
+
case 4:
|
|
697
|
+
results = _state.sent();
|
|
599
698
|
if (promiseResolver && promise) {
|
|
600
699
|
// 每一个任务完成的时候,都把自己从task中去掉
|
|
601
700
|
promiseResolver();
|
|
602
701
|
_this1._jobTasks.splice(_this1._jobTasks.indexOf(promise), 1);
|
|
603
702
|
}
|
|
604
|
-
return
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
703
|
+
return [
|
|
704
|
+
2,
|
|
705
|
+
results
|
|
706
|
+
];
|
|
608
707
|
}
|
|
609
|
-
}
|
|
610
|
-
})
|
|
708
|
+
});
|
|
709
|
+
})();
|
|
611
710
|
};
|
|
612
711
|
_proto.on = function on(key, callback) {
|
|
613
712
|
if (applyingPluginName) {
|
|
@@ -619,8 +718,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
619
718
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
620
719
|
args[_key] = arguments[_key];
|
|
621
720
|
}
|
|
622
|
-
var
|
|
623
|
-
return (
|
|
721
|
+
var _this_runtime;
|
|
722
|
+
return (_this_runtime = this.runtime).createControl.apply(_this_runtime, _toConsumableArray(args));
|
|
624
723
|
};
|
|
625
724
|
_proto.createInstance = function createInstance(type, initSchema) {
|
|
626
725
|
return this.runtime.createControlInstance(type, initSchema);
|
|
@@ -635,16 +734,16 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
635
734
|
if (controlId === undefined) {
|
|
636
735
|
return this.runtime.rules;
|
|
637
736
|
} else {
|
|
638
|
-
var
|
|
639
|
-
return (
|
|
737
|
+
var _this_runtime_rules_controlId;
|
|
738
|
+
return (_this_runtime_rules_controlId = this.runtime.rules[controlId]) === null || _this_runtime_rules_controlId === void 0 ? void 0 : _this_runtime_rules_controlId.fields;
|
|
640
739
|
}
|
|
641
740
|
};
|
|
642
741
|
_proto.getAntdRules = function getAntdRules(controlId) {
|
|
643
742
|
if (controlId === undefined) {
|
|
644
743
|
return this.runtime.antdRules;
|
|
645
744
|
} else {
|
|
646
|
-
var
|
|
647
|
-
return (
|
|
745
|
+
var _this_runtime_antdRules_controlId;
|
|
746
|
+
return (_this_runtime_antdRules_controlId = this.runtime.antdRules[controlId]) === null || _this_runtime_antdRules_controlId === void 0 ? void 0 : _this_runtime_antdRules_controlId.fields;
|
|
648
747
|
}
|
|
649
748
|
};
|
|
650
749
|
_proto.getState = function getState(controlId, rowIndex) {
|
|
@@ -654,6 +753,13 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
654
753
|
return this.store.getState(controlId, rowIndex);
|
|
655
754
|
}
|
|
656
755
|
};
|
|
756
|
+
_proto.getFieldCodeState = function getFieldCodeState(controlId) {
|
|
757
|
+
if (controlId === undefined) {
|
|
758
|
+
return this.store.fieldCodeState;
|
|
759
|
+
} else {
|
|
760
|
+
return this.store.getFieldCodeState(controlId);
|
|
761
|
+
}
|
|
762
|
+
};
|
|
657
763
|
_proto.getEmptyState = function getEmptyState(controlId) {
|
|
658
764
|
if (controlId === undefined) {
|
|
659
765
|
return JSONCopy(this.store.emptyState);
|
|
@@ -733,6 +839,16 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
733
839
|
return state;
|
|
734
840
|
}
|
|
735
841
|
};
|
|
842
|
+
_proto.getData = function getData(dataCode) {
|
|
843
|
+
if (dataCode) {
|
|
844
|
+
var dataBindMapping = this.getDataBindMapping(dataCode);
|
|
845
|
+
if (dataBindMapping) {
|
|
846
|
+
var controlId = dataBindMapping.controlId;
|
|
847
|
+
return this.getFieldCodeState(controlId);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return;
|
|
851
|
+
};
|
|
736
852
|
/**
|
|
737
853
|
* 通过dataCode和fieldCode来设置控件的值
|
|
738
854
|
* @param dataCode 模型编码 - 如果是主表的话就是主表的模型编码,明细子表的话就是子表的模型编码
|
|
@@ -747,8 +863,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
747
863
|
}
|
|
748
864
|
var dataBind = dataBindMapping.dataBind, controlId = dataBindMapping.controlId;
|
|
749
865
|
if (_instanceof(dataBind, ObjectDataBind)) {
|
|
750
|
-
var
|
|
751
|
-
var oldState = (
|
|
866
|
+
var _JSONCopy;
|
|
867
|
+
var oldState = (_JSONCopy = JSONCopy(this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : this.getEmptyState(controlId);
|
|
752
868
|
// fieldCode不代表是key,所以需要找到对应的key
|
|
753
869
|
var newState = Object.entries(dataBind).reduce(function(result, param) {
|
|
754
870
|
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
@@ -786,8 +902,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
786
902
|
}
|
|
787
903
|
// 对象类型的值
|
|
788
904
|
if (_instanceof(dataBind, ObjectDataBind)) {
|
|
789
|
-
var
|
|
790
|
-
var oldState = (
|
|
905
|
+
var _JSONCopy;
|
|
906
|
+
var oldState = (_JSONCopy = JSONCopy(_this.getState(controlId, rowIndex))) !== null && _JSONCopy !== void 0 ? _JSONCopy : _this.getEmptyState(controlId);
|
|
791
907
|
// fieldCode不代表是key,所以需要找到对应的key
|
|
792
908
|
var newState = Object.entries(dataBind).reduce(function(result, param) {
|
|
793
909
|
var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
|
|
@@ -865,19 +981,19 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
865
981
|
var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
|
|
866
982
|
;
|
|
867
983
|
Object.keys(row).map(function(fieldCode) {
|
|
868
|
-
var
|
|
984
|
+
var _this_store_dataBindMapping_dataCode, _this_store_dataBindMapping_dataCode_fields;
|
|
869
985
|
if (skipKey.includes(fieldCode)) {
|
|
870
986
|
return;
|
|
871
987
|
}
|
|
872
|
-
var fieldMapping = (
|
|
988
|
+
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) {
|
|
873
989
|
return i.fieldCode === fieldCode;
|
|
874
990
|
});
|
|
875
991
|
if (fieldMapping) {
|
|
876
992
|
if (_instanceof(fieldMapping.dataBind, DataBind) && row[fieldCode] !== undefined) {
|
|
877
993
|
newRow[fieldMapping.controlId] = row[fieldCode];
|
|
878
994
|
} else if (_instanceof(fieldMapping.dataBind, ObjectDataBind)) {
|
|
879
|
-
var
|
|
880
|
-
var objValue = JSONCopy((
|
|
995
|
+
var _this_getEmptyState;
|
|
996
|
+
var objValue = JSONCopy((_this_getEmptyState = _this.getEmptyState(fieldMapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {});
|
|
881
997
|
Object.keys(fieldMapping.dataBind).map(function(key) {
|
|
882
998
|
var dataBind = fieldMapping.dataBind[key];
|
|
883
999
|
if (row[dataBind.fieldCode] !== undefined) {
|
|
@@ -912,8 +1028,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
912
1028
|
if (_instanceof(mapping.dataBind, DataBind) && entity[fieldCode] !== undefined) {
|
|
913
1029
|
newState[mapping.dataViewId[0]][mapping.controlId] = entity[fieldCode];
|
|
914
1030
|
} else if (_instanceof(mapping.dataBind, ObjectDataBind)) {
|
|
915
|
-
var
|
|
916
|
-
var objValue = JSONCopy((
|
|
1031
|
+
var _this_getEmptyState;
|
|
1032
|
+
var objValue = JSONCopy((_this_getEmptyState = _this.getEmptyState(mapping.controlId)) !== null && _this_getEmptyState !== void 0 ? _this_getEmptyState : {});
|
|
917
1033
|
Object.keys(mapping.dataBind).map(function(key) {
|
|
918
1034
|
var dataBind = mapping.dataBind[key];
|
|
919
1035
|
if (entity[dataBind.fieldCode] !== undefined) {
|
|
@@ -981,11 +1097,11 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
981
1097
|
}
|
|
982
1098
|
} else {
|
|
983
1099
|
var controlIdMapping = this.getControlIdMapping();
|
|
984
|
-
var
|
|
985
|
-
var
|
|
1100
|
+
var _Object_entries_find;
|
|
1101
|
+
var _ref = _slicedToArray((_Object_entries_find = Object.entries(controlIdMapping).find(function(param) {
|
|
986
1102
|
var _param = _slicedToArray(param, 2), _ = _param[0], mapping = _param[1];
|
|
987
1103
|
return mapping.children && controlId in mapping.children;
|
|
988
|
-
})) !== null &&
|
|
1104
|
+
})) !== null && _Object_entries_find !== void 0 ? _Object_entries_find : [], 1), subtableId = _ref[0];
|
|
989
1105
|
if (subtableId) {
|
|
990
1106
|
var subtable = this.getInstance(subtableId);
|
|
991
1107
|
// @ts-ignore
|
|
@@ -1139,8 +1255,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
1139
1255
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
1140
1256
|
args[_key] = arguments[_key];
|
|
1141
1257
|
}
|
|
1142
|
-
var
|
|
1143
|
-
return (
|
|
1258
|
+
var _this_runtime;
|
|
1259
|
+
return (_this_runtime = this.runtime).registerControlConfig.apply(_this_runtime, _toConsumableArray(args));
|
|
1144
1260
|
};
|
|
1145
1261
|
_proto.getControlConfig = function getControlConfig(control) {
|
|
1146
1262
|
return this.runtime.getControlConfig(control);
|
|
@@ -18,12 +18,12 @@ var OkWorker = /*#__PURE__*/ function() {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
_proto.destroy = function destroy() {
|
|
21
|
-
var
|
|
22
|
-
(
|
|
21
|
+
var _this_worker;
|
|
22
|
+
(_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.terminate();
|
|
23
23
|
};
|
|
24
24
|
_proto.postMessage = function postMessage(message) {
|
|
25
|
-
var
|
|
26
|
-
(
|
|
25
|
+
var _this_worker;
|
|
26
|
+
(_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.postMessage(message);
|
|
27
27
|
};
|
|
28
28
|
OkWorker.createWorker = function createWorker() {
|
|
29
29
|
var blob = new Blob([
|
|
@@ -64,7 +64,7 @@ var OkWorker = /*#__PURE__*/ function() {
|
|
|
64
64
|
// return new Proxy(obj, createHandler(parentKey))
|
|
65
65
|
// }
|
|
66
66
|
_self.addEventListener("message", function(event) {
|
|
67
|
-
var
|
|
67
|
+
var _event_data = event.data, action = _event_data.action, payload = _event_data.payload, fn = _event_data.fn;
|
|
68
68
|
log(action, payload);
|
|
69
69
|
// 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
|
|
70
70
|
// data.key1 = 1
|
package/dist/esm/common/Store.js
CHANGED
|
@@ -30,9 +30,10 @@ var Store = /*#__PURE__*/ function() {
|
|
|
30
30
|
"use strict";
|
|
31
31
|
function Store(props) {
|
|
32
32
|
_classCallCheck(this, Store);
|
|
33
|
-
var
|
|
33
|
+
var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, fieldCodeState = _init.fieldCodeState;
|
|
34
34
|
this.emptyState = emptyState;
|
|
35
35
|
this.state = state;
|
|
36
|
+
this.fieldCodeState = fieldCodeState;
|
|
36
37
|
this.dataBindMapping = databindMapping;
|
|
37
38
|
this.controlIdMapping = controlidMapping;
|
|
38
39
|
}
|
|
@@ -96,8 +97,8 @@ var Store = /*#__PURE__*/ function() {
|
|
|
96
97
|
if (children !== undefined) {
|
|
97
98
|
Object.keys(children).map(function(childControlId) {
|
|
98
99
|
if (childControlId === controlId) {
|
|
99
|
-
var
|
|
100
|
-
state = (
|
|
100
|
+
var _this_state_dataViewId_subtableId_rowIndex;
|
|
101
|
+
state = (_this_state_dataViewId_subtableId_rowIndex = _this.state[dataViewId][subtableId][rowIndex]) === null || _this_state_dataViewId_subtableId_rowIndex === void 0 ? void 0 : _this_state_dataViewId_subtableId_rowIndex[controlId];
|
|
101
102
|
}
|
|
102
103
|
});
|
|
103
104
|
}
|
|
@@ -123,6 +124,25 @@ var Store = /*#__PURE__*/ function() {
|
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
};
|
|
127
|
+
_proto.getFieldCodeState = function getFieldCodeState(controlId) {
|
|
128
|
+
//qiyu 由于header的数据是后补充的,所以从state获取第一层值。
|
|
129
|
+
// const controlInfo = this.controlIdMapping[controlId]
|
|
130
|
+
var detection = this.fieldCodeState[controlId];
|
|
131
|
+
if (detection !== undefined) {
|
|
132
|
+
return this.fieldCodeState[controlId];
|
|
133
|
+
} else {
|
|
134
|
+
var controlInfo = this.controlIdMapping[controlId];
|
|
135
|
+
var dataCode = controlInfo.dataBind.dataCode;
|
|
136
|
+
if (controlInfo !== undefined) {
|
|
137
|
+
if (controlInfo.dataView === controlId) {
|
|
138
|
+
return this.fieldCodeState[controlId];
|
|
139
|
+
} else {
|
|
140
|
+
var dataCode1 = controlInfo.dataBind.dataCode;
|
|
141
|
+
return this.fieldCodeState[controlInfo.dataView][dataCode1] || this.fieldCodeState[controlInfo.dataView];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
126
146
|
_proto.getEmptyState = function getEmptyState(controlId) {
|
|
127
147
|
var _this = this;
|
|
128
148
|
var detection = this.emptyState[controlId];
|
|
@@ -173,6 +193,8 @@ var Store = /*#__PURE__*/ function() {
|
|
|
173
193
|
function init(instance) {
|
|
174
194
|
var state = {};
|
|
175
195
|
var emptyState = {};
|
|
196
|
+
var fieldCodeState = {};
|
|
197
|
+
var fieldCodeEmptyState = {};
|
|
176
198
|
var databindMapping = {};
|
|
177
199
|
var controlidMapping = {};
|
|
178
200
|
// loopFormControl(instance, (item, children) => {
|
|
@@ -182,39 +204,76 @@ function init(instance) {
|
|
|
182
204
|
var dvId = dataView.id;
|
|
183
205
|
var dataViewState = {};
|
|
184
206
|
var emptyDataViewState = {};
|
|
207
|
+
var dataViewFieldCodeState = {};
|
|
208
|
+
var emptyDataViewFieldCodeState = {};
|
|
185
209
|
// @ts-ignore
|
|
186
210
|
loopFormControl([
|
|
187
211
|
dataView
|
|
188
212
|
], function(item, children) {
|
|
189
|
-
buildState(dataViewState, emptyDataViewState, item);
|
|
213
|
+
buildState(dataViewState, emptyDataViewState, dataViewFieldCodeState, emptyDataViewFieldCodeState, item);
|
|
190
214
|
buildDataBindMapping(databindMapping, dvId, item);
|
|
191
215
|
buildControlIdMapping(controlidMapping, dvId, item);
|
|
192
216
|
});
|
|
193
217
|
state[dvId] = dataViewState;
|
|
194
218
|
emptyState[dvId] = emptyDataViewState;
|
|
219
|
+
fieldCodeState[dvId] = dataViewFieldCodeState;
|
|
220
|
+
fieldCodeEmptyState[dvId] = emptyDataViewFieldCodeState;
|
|
195
221
|
});
|
|
196
222
|
return {
|
|
197
223
|
state: state,
|
|
198
224
|
emptyState: emptyState,
|
|
199
225
|
databindMapping: databindMapping,
|
|
200
|
-
controlidMapping: controlidMapping
|
|
226
|
+
controlidMapping: controlidMapping,
|
|
227
|
+
fieldCodeState: fieldCodeState,
|
|
228
|
+
fieldCodeEmptyState: fieldCodeEmptyState
|
|
201
229
|
};
|
|
202
230
|
}
|
|
203
|
-
function buildState(dataViewState, emptyDataViewState, // @ts-ignore
|
|
231
|
+
function buildState(dataViewState, emptyDataViewState, dataViewFieldCodeState, emptyDataViewFieldCodeState, // @ts-ignore
|
|
204
232
|
item) {
|
|
205
233
|
if (_instanceof(item, RuntimeFormControl)) {
|
|
206
234
|
dataViewState[item.id] = JSONCopy(item.props.defaultValue);
|
|
207
235
|
emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
|
|
236
|
+
if (_instanceof(item.props.dataBind, ObjectDataBind)) {
|
|
237
|
+
// 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
|
|
238
|
+
Object.keys(item.props.dataBind).forEach(function(key) {
|
|
239
|
+
var dataBind = item.props.dataBind;
|
|
240
|
+
var defaultValue = item.props.defaultValue;
|
|
241
|
+
var dataBindFieldCode = dataBind[key].fieldCode;
|
|
242
|
+
dataViewFieldCodeState[dataBindFieldCode] = JSONCopy(defaultValue[key]);
|
|
243
|
+
emptyDataViewFieldCodeState[dataBindFieldCode] = JSONCopy(defaultValue[key]);
|
|
244
|
+
});
|
|
245
|
+
} else {
|
|
246
|
+
var dataBindFieldCode = item.props.dataBind.fieldCode;
|
|
247
|
+
dataViewFieldCodeState[dataBindFieldCode] = JSONCopy(item.props.defaultValue);
|
|
248
|
+
emptyDataViewFieldCodeState[dataBindFieldCode] = JSONCopy(item.props.defaultValue);
|
|
249
|
+
}
|
|
208
250
|
} else {
|
|
209
251
|
var emptyTemplate = {};
|
|
252
|
+
var emptyFieldCodeTemplate = {};
|
|
210
253
|
loopFormSchema(item.props.headers, function(headerItem) {
|
|
211
254
|
emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
|
|
255
|
+
// 处理成fieldCode
|
|
256
|
+
var headerItemFieldCode = headerItem.props.dataBind.fieldCode;
|
|
257
|
+
if (_instanceof(headerItem.props.dataBind, ObjectDataBind)) {
|
|
258
|
+
// 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
|
|
259
|
+
Object.keys(headerItem.props.dataBind).forEach(function(key) {
|
|
260
|
+
emptyFieldCodeTemplate[headerItem.props.dataBind[key].fieldCode] = JSONCopy(headerItem.props.defaultValue[key]);
|
|
261
|
+
});
|
|
262
|
+
} else {
|
|
263
|
+
emptyFieldCodeTemplate[headerItemFieldCode] = JSONCopy(headerItem.props.defaultValue);
|
|
264
|
+
}
|
|
212
265
|
});
|
|
213
|
-
var
|
|
214
|
-
dataViewState[item.id] = new Array((
|
|
266
|
+
var _item_props_defaultRows;
|
|
267
|
+
dataViewState[item.id] = new Array((_item_props_defaultRows = item.props.defaultRows) !== null && _item_props_defaultRows !== void 0 ? _item_props_defaultRows : 1).fill(0).map(function() {
|
|
215
268
|
return JSONCopy(emptyTemplate);
|
|
216
269
|
});
|
|
217
270
|
emptyDataViewState[item.id] = emptyTemplate;
|
|
271
|
+
var dataBindFieldCode1 = item.props.datasourceBind.dataCode;
|
|
272
|
+
var _item_props_defaultRows1;
|
|
273
|
+
dataViewFieldCodeState[dataBindFieldCode1] = new Array((_item_props_defaultRows1 = item.props.defaultRows) !== null && _item_props_defaultRows1 !== void 0 ? _item_props_defaultRows1 : 1).fill(0).map(function() {
|
|
274
|
+
return JSONCopy(emptyFieldCodeTemplate);
|
|
275
|
+
});
|
|
276
|
+
emptyDataViewFieldCodeState[dataBindFieldCode1] = emptyFieldCodeTemplate;
|
|
218
277
|
}
|
|
219
278
|
}
|
|
220
279
|
function buildDataBindMapping(data, dataViewId, // @ts-ignore
|
|
@@ -320,9 +379,9 @@ item) {
|
|
|
320
379
|
options: []
|
|
321
380
|
};
|
|
322
381
|
loopFormSchema(item.props.headers, function(formControl) {
|
|
323
|
-
var
|
|
324
|
-
var
|
|
325
|
-
Object.assign((
|
|
382
|
+
var _data_item_id;
|
|
383
|
+
var _data_item_id_children;
|
|
384
|
+
Object.assign((_data_item_id_children = (_data_item_id = data[item.id]) === null || _data_item_id === void 0 ? void 0 : _data_item_id.children) !== null && _data_item_id_children !== void 0 ? _data_item_id_children : {}, _defineProperty({}, formControl.id, {
|
|
326
385
|
dataBind: formControl.props.dataBind
|
|
327
386
|
}));
|
|
328
387
|
});
|
|
@@ -520,8 +520,8 @@ function getFieldTypeFromKey(key) {
|
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
522
|
export function checkerValue(fieldType, key, value, oldValue) {
|
|
523
|
-
var
|
|
524
|
-
var getCheckerFieldType = (
|
|
523
|
+
var _getFieldTypeFromKey;
|
|
524
|
+
var getCheckerFieldType = (_getFieldTypeFromKey = getFieldTypeFromKey(key)) !== null && _getFieldTypeFromKey !== void 0 ? _getFieldTypeFromKey : fieldType;
|
|
525
525
|
var checker = ValueCheckerFactory.getValueChecker(getCheckerFieldType);
|
|
526
526
|
if (!checker || checker.validate(value)) {
|
|
527
527
|
return value;
|