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