@byteluck-fe/model-driven-engine 1.7.6-bete.2 → 1.7.6-bete.21

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.
@@ -341,6 +341,7 @@ import { findItem, proxyState } from "./proxyState";
341
341
  import { ActionManager } from "./ActionManager";
342
342
  import { DataManager } from "./DataManager";
343
343
  import { checkerSubtableValue, checkerValue } from "./checkerValue";
344
+ import { genSubTableRowInstanceFromHeaders } from "./SubTableSpeedUp";
344
345
  if (typeof window !== "undefined") {
345
346
  // @ts-ignore
346
347
  window.engines = {};
@@ -365,6 +366,10 @@ var Engine = /*#__PURE__*/ function(Watcher) {
365
366
  _this.__pluginsApplied = false;
366
367
  _this.actionManager = new ActionManager();
367
368
  _this._jobTasks = [];
369
+ /**
370
+ * 用于存储运行态无需proxy的数据
371
+ * from v1.7.6-beta
372
+ */ _this.rawStore = {};
368
373
  _this.createControlInstance = _this.createInstance;
369
374
  _this.$options = Object.freeze(props);
370
375
  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,
@@ -430,17 +435,21 @@ var Engine = /*#__PURE__*/ function(Watcher) {
430
435
  this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
431
436
  };
432
437
  _proto._proxyStateBeforeSetCallback = function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
433
- var _this = this;
434
438
  var cc = console;
435
- cc.time("㊗️_proxyStateBeforeSetCallback findItem");
439
+ var now = Date.now();
440
+ cc.log("㊗️_proxyStateBeforeSetCallback findItem " + key, newValue, oldValue);
441
+ cc.time("㊗️_proxyStateBeforeSetCallback findItem " + key + " " + now);
436
442
  var instance = findItem(this.runtime.flatInstances, key);
437
- cc.timeLog("㊗️_proxyStateBeforeSetCallback findItem");
443
+ cc.timeEnd("㊗️_proxyStateBeforeSetCallback findItem " + key + " " + now);
438
444
  // 找不到控件说明不是改动控件上的字段,直接通过
439
445
  if (!instance) {
440
446
  return newValue;
441
447
  }
442
448
  // @ts-ignore
443
449
  if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE)) {
450
+ if (newValue === null) {
451
+ return [];
452
+ }
444
453
  // @ts-ignore
445
454
  var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
446
455
  var formInstance = column.children[0];
@@ -449,12 +458,10 @@ var Engine = /*#__PURE__*/ function(Watcher) {
449
458
  }
450
459
  return result;
451
460
  }, {});
452
- if (newValue === null) {
453
- return [];
454
- }
461
+ // @ts-ignore
462
+ var emptyState = this.getEmptyState(instance.id);
455
463
  return newValue.map(function(row) {
456
- return(// @ts-ignore
457
- checkerSubtableValue(fieldTypeMap, row, _this.getEmptyState(instance.id)));
464
+ return checkerSubtableValue(fieldTypeMap, row, emptyState);
458
465
  });
459
466
  }
460
467
  var keys = key.split(".");
@@ -474,21 +481,20 @@ var Engine = /*#__PURE__*/ function(Watcher) {
474
481
  }
475
482
  };
476
483
  _proto._handlerArrayUpdate = function _handlerArrayUpdate(state, key, type, args, result) {
477
- var _this = this;
478
484
  var cc = console;
479
- cc.time("㊗️ _handlerArrayUpdate findItem");
485
+ cc.time("㊗️ _handlerArrayUpdate findItem" + key);
480
486
  var subtable = findItem(this.runtime.flatInstances, key);
481
- cc.timeLog("㊗️ _handlerArrayUpdate findItem");
487
+ cc.timeEnd("㊗️ _handlerArrayUpdate findItem" + key);
482
488
  if (!_instanceof(subtable, RuntimeListControl)) return;
483
489
  // 新增多行方法
484
490
  var createRows = function(len) {
485
491
  // @ts-ignore
486
492
  var newRows = [];
487
- for(var i = 0; i < len; i++){
488
- // @ts-ignore
489
- var row = _this.listControlCreateRow(subtable, "subtable-row");
490
- row && newRows.push(row);
491
- }
493
+ // for (let i = 0; i < len; i++) {
494
+ // // @ts-ignore
495
+ // const row = this.listControlCreateRow(subtable, 'subtable-row')
496
+ // row && newRows.push(row)
497
+ // }
492
498
  // @ts-ignore
493
499
  return newRows;
494
500
  };
@@ -569,32 +575,38 @@ var Engine = /*#__PURE__*/ function(Watcher) {
569
575
  };
570
576
  _proto._handlerObjectUpdate = function _handlerObjectUpdate(state, key, value, oldValue) {
571
577
  var cc = console;
572
- cc.time("㊗️_handlerObjectUpdate findItem");
578
+ var now = Date.now();
579
+ cc.log("㊗️_handlerObjectUpdate findItem " + key, value, oldValue);
580
+ cc.time("㊗️_handlerObjectUpdate findItem " + key + " " + now);
581
+ // 1. header -> instance
582
+ // 2. 如何判断应该 给 subtableInstance.children中 push
583
+ // JUTODO
584
+ // 1. 修改生成的key的规则,去除[index]
585
+ // 2. 新增一个查找 subtable上的 _rowPropsList 的对应key instance的函数A
586
+ // 3. 判断 当前的key 应该调用 A 或者是 findItem
587
+ // 4.
573
588
  var instance = findItem(this.runtime.flatInstances, key);
574
- cc.timeLog("㊗️_handlerObjectUpdate findItem");
589
+ cc.timeEnd("㊗️_handlerObjectUpdate findItem " + key + " " + now);
575
590
  if (!instance) {
576
591
  return;
577
592
  }
578
593
  var index = this.getInstanceRowIndex(instance);
579
594
  var options = eventOptionsTemp || {};
580
595
  if (_instanceof(instance, RuntimeListControl)) {
581
- var // @ts-ignore
582
- _instance_children;
583
- instance.children.length = 0;
596
+ // instance.children.length = 0
597
+ this.initSubTableRowPropsFromInstanceHeaders(instance);
584
598
  var newValue = value;
585
599
  // @ts-ignore
586
600
  var newRows = [];
587
- for(var i = 0; i < newValue.length; i++){
588
- // @ts-ignore
589
- var row = this.listControlCreateRow(instance, "subtable-row");
590
- row && newRows.push(row);
591
- }
592
- (_instance_children = instance.children).push.apply(_instance_children, _toConsumableArray(newRows));
593
- this.runtime.getFlatInstances();
594
- // 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
601
+ this.initSubTableRowPropsFromProxySetNewValue(instance, value);
595
602
  // for (let i = 0; i < newValue.length; i++) {
596
- // this.setStates(newValue[i], i, options)
603
+ // // @ts-ignore
604
+ // const row = this.listControlCreateRow(instance, 'subtable-row')
605
+ // row && newRows.push(row)
597
606
  // }
607
+ // @ts-ignore
608
+ // instance.children.push(...newRows)
609
+ this.runtime.getFlatInstances();
598
610
  this.emit("list-change", {
599
611
  instance: instance,
600
612
  value: value,
@@ -636,20 +648,21 @@ var Engine = /*#__PURE__*/ function(Watcher) {
636
648
  var row = this.runtime.createControlInstance(rowType);
637
649
  if (!row) return;
638
650
  if (_instanceof(row, RuntimeLayoutControl)) {
639
- var _row_children;
640
- var template = JSONCopy(instance.props.headers);
641
- // @ts-ignore
642
- var columns = this.createControl(template);
643
- (_row_children = row.children).push.apply(_row_children, _toConsumableArray(columns));
651
+ // const template = JSONCopy(instance.props.headers) as any
652
+ // @ts-ignore
653
+ // const columns = this.createControl(template) as unknown as any[]
654
+ // row.children.push(...columns)
644
655
  }
645
656
  return row;
646
657
  };
647
658
  _proto.listControlAddRow = function listControlAddRow(instance) {
648
659
  var // @ts-ignore
649
660
  rowType = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "subtable-row";
650
- var row = this.listControlCreateRow(instance, rowType);
651
- if (!row) return;
652
- instance.children.push(row);
661
+ // JUTODO 这似乎是个二开api
662
+ throw new Error("该api已废弃");
663
+ // const row = this.listControlCreateRow(instance, rowType)
664
+ // if (!row) return
665
+ // instance.children.push(row)
653
666
  };
654
667
  // payload应该是runtimeSchema和value,然后通过runTimeSchema去找需要修改的data里边的key
655
668
  _proto.emit = function emit(eventKey, payload) {
@@ -1030,6 +1043,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1030
1043
  var _this = this;
1031
1044
  this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
1032
1045
  var newState = {};
1046
+ // debugger
1033
1047
  Object.keys(dataSet).map(function(dataCode) {
1034
1048
  var entity = dataSet[dataCode];
1035
1049
  if (Array.isArray(entity)) {
@@ -1142,6 +1156,10 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1142
1156
  if (controlId === undefined) {
1143
1157
  return this.runtime.flatInstances;
1144
1158
  }
1159
+ var cc = console;
1160
+ var now = Date.now();
1161
+ var timeLabel = "⚠️ getInstances " + controlId + " " + header + now;
1162
+ cc.time(timeLabel);
1145
1163
  var instances = this.runtime.flatInstances.filter(// @ts-ignore
1146
1164
  function(item) {
1147
1165
  return item.id === controlId;
@@ -1182,6 +1200,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1182
1200
  }
1183
1201
  }
1184
1202
  }
1203
+ cc.timeEnd(timeLabel);
1185
1204
  return instances;
1186
1205
  };
1187
1206
  _proto.setInstance = function setInstance(instance, props, value, rowIndex) {
@@ -1322,6 +1341,27 @@ var Engine = /*#__PURE__*/ function(Watcher) {
1322
1341
  _proto.getControlConfig = function getControlConfig(control) {
1323
1342
  return this.runtime.getControlConfig(control);
1324
1343
  };
1344
+ _proto.initSubTableRowPropsFromInstanceHeaders = function initSubTableRowPropsFromInstanceHeaders(instance) {
1345
+ var cc = console;
1346
+ var now = Date.now();
1347
+ var timeLabel = "\uD83D\uDC2E initSubTableRowPropsFromInstanceHeaders " + now;
1348
+ cc.time(timeLabel);
1349
+ /**headers实际 是 SubTableColumnControl的数组 */ Object.assign(instance.rowProps, genSubTableRowInstanceFromHeaders(instance.props.headers));
1350
+ cc.timeEnd(timeLabel);
1351
+ };
1352
+ _proto.initSubTableRowPropsFromProxySetNewValue = function initSubTableRowPropsFromProxySetNewValue(instance, value) {
1353
+ var cc = console;
1354
+ var now = Date.now();
1355
+ var timeLabel = "\uD83D\uDC37 initSubTableRowPropsFromProxySetNewValue " + now;
1356
+ cc.time(timeLabel);
1357
+ value.forEach(function(item) {
1358
+ Object.assign(instance.rowProps, {
1359
+ // 这里只是做个性能测试,实际上需要merge rowProps,并且还需要一个恰当的key
1360
+ now: genSubTableRowInstanceFromHeaders(instance.props.headers)
1361
+ });
1362
+ });
1363
+ cc.timeEnd(timeLabel);
1364
+ };
1325
1365
  // 注册外部控件
1326
1366
  Engine.register = function register() {
1327
1367
  for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
@@ -0,0 +1,17 @@
1
+ // import { RuntimeSubTableColumnControl } from '@byteluck-fe/model-driven-core'
2
+ // import { RuntimeControl } from '@byteluck-fe/model-driven-core'
3
+ import cloneDeep from "lodash.clonedeep";
4
+ export function genSubTableRowInstanceFromHeaders(// headers: RuntimeSubTableColumnControl[]
5
+ headers) {
6
+ var subtableRow = headers.reduce(function(pre, cur) {
7
+ var children = cur.children;
8
+ children.forEach(function(control) {
9
+ pre[control.id] = copyPropsFromControlInstance(control);
10
+ });
11
+ return pre;
12
+ }, {});
13
+ return subtableRow;
14
+ }
15
+ function copyPropsFromControlInstance(control) {
16
+ return cloneDeep(control.props);
17
+ }
@@ -283,6 +283,10 @@ export var CalcPlugin = /*#__PURE__*/ function() {
283
283
  if (!scriptEcho || scriptEcho.length === 0) {
284
284
  return;
285
285
  }
286
+ var cc = console;
287
+ var now = Date.now();
288
+ var timeLabel = "\uD83D\uDC36 computedCalcValue " + control.id + " " + now;
289
+ cc.time(timeLabel);
286
290
  // @ts-ignore
287
291
  var scriptText = scriptEcho.reduce(function(result, current) {
288
292
  if (current.type === CALC_TOKEN_TYPE.Operator || current.type === CALC_TOKEN_TYPE.Number) {
@@ -343,6 +347,8 @@ export var CalcPlugin = /*#__PURE__*/ function() {
343
347
  rowIndex = this.engine.getInstanceRowIndex(control);
344
348
  // 控件在明细表内,但是没有行下标,说明控件被已经删除了,所以直接return
345
349
  if (rowIndex === undefined) {
350
+ cc.log(timeLabel, "------> 控件在明细表内,但是没有行下标,说明控件被已经删除了,所以直接return");
351
+ cc.timeEnd(timeLabel);
346
352
  return;
347
353
  }
348
354
  }
@@ -350,6 +356,8 @@ export var CalcPlugin = /*#__PURE__*/ function() {
350
356
  var result = !value || value === Infinity || value === -Infinity ? 0 : control.props.precision === "" ? value : Number(value.toFixed(control.props.precision));
351
357
  // 如果值没变的话,不触发修改
352
358
  if (result === (oldValue === null || oldValue === void 0 ? void 0 : oldValue.result)) {
359
+ cc.log(timeLabel, "------> 如果值没变的话,不触发修改");
360
+ cc.timeEnd(timeLabel);
353
361
  return;
354
362
  }
355
363
  var _oldValue_unit;
@@ -357,6 +365,7 @@ export var CalcPlugin = /*#__PURE__*/ function() {
357
365
  result: result,
358
366
  unit: (_oldValue_unit = oldValue === null || oldValue === void 0 ? void 0 : oldValue.unit) !== null && _oldValue_unit !== void 0 ? _oldValue_unit : ""
359
367
  }, rowIndex);
368
+ cc.timeEnd(timeLabel);
360
369
  };
361
370
  /**
362
371
  * @description 获取数字值,因为计算公式可以依赖计算公式和金额,所以需要从value中取到对应的值