@byteluck-fe/model-driven-engine 2.7.0-alpha.1 → 2.7.0-alpha.11

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.
@@ -49,6 +49,20 @@ function _classCallCheck(instance, Constructor) {
49
49
  throw new TypeError("Cannot call a class as a function");
50
50
  }
51
51
  }
52
+ function _defineProperties(target, props) {
53
+ for(var i = 0; i < props.length; i++){
54
+ var descriptor = props[i];
55
+ descriptor.enumerable = descriptor.enumerable || false;
56
+ descriptor.configurable = true;
57
+ if ("value" in descriptor) descriptor.writable = true;
58
+ Object.defineProperty(target, descriptor.key, descriptor);
59
+ }
60
+ }
61
+ function _createClass(Constructor, protoProps, staticProps) {
62
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
63
+ if (staticProps) _defineProperties(Constructor, staticProps);
64
+ return Constructor;
65
+ }
52
66
  function _defineProperty(obj, key, value) {
53
67
  if (key in obj) {
54
68
  Object.defineProperty(obj, key, {
@@ -97,13 +111,6 @@ function _inherits(subClass, superClass) {
97
111
  });
98
112
  if (superClass) _setPrototypeOf(subClass, superClass);
99
113
  }
100
- function _instanceof(left, right) {
101
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
102
- return !!right[Symbol.hasInstance](left);
103
- } else {
104
- return left instanceof right;
105
- }
106
- }
107
114
  function _iterableToArray(iter) {
108
115
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
109
116
  }
@@ -152,30 +159,6 @@ function _objectSpread(target) {
152
159
  }
153
160
  return target;
154
161
  }
155
- function ownKeys(object, enumerableOnly) {
156
- var keys = Object.keys(object);
157
- if (Object.getOwnPropertySymbols) {
158
- var symbols = Object.getOwnPropertySymbols(object);
159
- if (enumerableOnly) {
160
- symbols = symbols.filter(function(sym) {
161
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
162
- });
163
- }
164
- keys.push.apply(keys, symbols);
165
- }
166
- return keys;
167
- }
168
- function _objectSpreadProps(target, source) {
169
- source = source != null ? source : {};
170
- if (Object.getOwnPropertyDescriptors) {
171
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
172
- } else {
173
- ownKeys(Object(source)).forEach(function(key) {
174
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
175
- });
176
- }
177
- return target;
178
- }
179
162
  function _possibleConstructorReturn(self, call) {
180
163
  if (call && (_typeof(call) === "object" || typeof call === "function")) {
181
164
  return call;
@@ -238,121 +221,27 @@ function _createSuper(Derived) {
238
221
  return _possibleConstructorReturn(this, result);
239
222
  };
240
223
  }
241
- var __generator = this && this.__generator || function(thisArg, body) {
242
- var f, y, t, g, _ = {
243
- label: 0,
244
- sent: function() {
245
- if (t[0] & 1) throw t[1];
246
- return t[1];
247
- },
248
- trys: [],
249
- ops: []
250
- };
251
- return g = {
252
- next: verb(0),
253
- "throw": verb(1),
254
- "return": verb(2)
255
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
256
- return this;
257
- }), g;
258
- function verb(n) {
259
- return function(v) {
260
- return step([
261
- n,
262
- v
263
- ]);
264
- };
265
- }
266
- function step(op) {
267
- if (f) throw new TypeError("Generator is already executing.");
268
- while(_)try {
269
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
270
- if (y = 0, t) op = [
271
- op[0] & 2,
272
- t.value
273
- ];
274
- switch(op[0]){
275
- case 0:
276
- case 1:
277
- t = op;
278
- break;
279
- case 4:
280
- _.label++;
281
- return {
282
- value: op[1],
283
- done: false
284
- };
285
- case 5:
286
- _.label++;
287
- y = op[1];
288
- op = [
289
- 0
290
- ];
291
- continue;
292
- case 7:
293
- op = _.ops.pop();
294
- _.trys.pop();
295
- continue;
296
- default:
297
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
298
- _ = 0;
299
- continue;
300
- }
301
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
302
- _.label = op[1];
303
- break;
304
- }
305
- if (op[0] === 6 && _.label < t[1]) {
306
- _.label = t[1];
307
- t = op;
308
- break;
309
- }
310
- if (t && _.label < t[2]) {
311
- _.label = t[2];
312
- _.ops.push(op);
313
- break;
314
- }
315
- if (t[2]) _.ops.pop();
316
- _.trys.pop();
317
- continue;
318
- }
319
- op = body.call(thisArg, _);
320
- } catch (e) {
321
- op = [
322
- 6,
323
- e
324
- ];
325
- y = 0;
326
- } finally{
327
- f = t = 0;
328
- }
329
- if (op[0] & 5) throw op[1];
330
- return {
331
- value: op[0] ? op[1] : void 0,
332
- done: true
333
- };
334
- }
335
- };
336
- import { DataBind, ObjectDataBind, RuntimeListControl } from "@byteluck-fe/model-driven-core";
337
- import { CONTROL_BASE_TYPE, CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from "@byteluck-fe/model-driven-shared";
338
- import { Runtime } from "./Runtime";
339
- import { Store } from "./Store";
340
- import { findItem, proxyState } from "./proxyState";
341
- import { ActionManager } from "./ActionManager";
342
- import { DataManager } from "./DataManager";
343
- import { checkerSubtableValue, checkerValue } from "./checkerValue";
344
- if (typeof window !== "undefined") {
224
+ import regeneratorRuntime from "regenerator-runtime";
225
+ import { isDataBind } from '@byteluck-fe/model-driven-core';
226
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, DEFAULT_LOCALE, error, genNonDuplicateId, isString, JSONCopy, log, RulesMessage, updateValueFromKeys, warn, Watcher } from '@byteluck-fe/model-driven-shared';
227
+ import { Runtime } from './Runtime';
228
+ import { Store } from './Store';
229
+ import { findItem, proxyState } from './proxyState';
230
+ import { ActionManager } from './ActionManager';
231
+ import { DataManager } from './DataManager';
232
+ import { checkerSubtableValue, checkerValue } from './checkerValue';
233
+ if (typeof window !== 'undefined') {
345
234
  // @ts-ignore
346
235
  window.engines = {};
347
236
  }
348
237
  // setState的时候,存储options中转变量
349
238
  var eventOptionsTemp = null;
350
239
  // 当前正在注册的插件名称
351
- var applyingPluginName = "";
352
- // 整体渲染引擎 并且 提供发布订阅能力
353
- var Engine = /*#__PURE__*/ function(Watcher) {
240
+ var applyingPluginName = '';
241
+ var Engine = // 整体渲染引擎 并且 提供发布订阅能力
242
+ /*#__PURE__*/ function(Watcher1) {
354
243
  "use strict";
355
- _inherits(Engine, Watcher);
244
+ _inherits(Engine, Watcher1);
356
245
  var _super = _createSuper(Engine);
357
246
  function Engine(props) {
358
247
  _classCallCheck(this, Engine);
@@ -368,8 +257,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
368
257
  _this._jobTasks = [];
369
258
  _this.createControlInstance = _this.createInstance;
370
259
  _this.$options = Object.freeze(props);
371
- var _this_$options = _this.$options, _this_$options_autoMount = _this_$options.autoMount, autoMount = _this_$options_autoMount === void 0 ? true : _this_$options_autoMount, schema = _this_$options.schema, beforeCreateInstance = _this_$options.beforeCreateInstance, externalParams = _this_$options.externalParams, _this_$options_language = _this_$options.// fieldModel,
372
- language, language = _this_$options_language === void 0 ? DEFAULT_LOCALE : _this_$options_language, _this_$options_debug = _this_$options.debug, debug = _this_$options_debug === void 0 ? false : _this_$options_debug;
260
+ var _$options = _this.$options, _autoMount = _$options.autoMount, autoMount = _autoMount === void 0 ? true : _autoMount, schema = _$options.schema, beforeCreateInstance = _$options.beforeCreateInstance, externalParams = _$options.externalParams, _language = _$options.// fieldModel,
261
+ language, language = _language === void 0 ? DEFAULT_LOCALE : _language, _debug = _$options.debug, debug = _debug === void 0 ? false : _debug;
373
262
  RulesMessage.setLocale(language);
374
263
  _this.debug = debug;
375
264
  _this.runtime = new Runtime({
@@ -380,1036 +269,1226 @@ var Engine = /*#__PURE__*/ function(Watcher) {
380
269
  _this.store = new Store({
381
270
  instance: _this.runtime.instance
382
271
  });
383
- _this.debugLog("engine is Instantiation complete");
272
+ _this.debugLog('engine is Instantiation complete');
384
273
  // 自动执行挂载完成,也可以手动调用mount方法
385
274
  autoMount && _this.mount();
386
275
  return _this;
387
276
  }
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 [];
277
+ _createClass(Engine, [
278
+ {
279
+ key: "debugLog",
280
+ value: function debugLog() {
281
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
282
+ args[_key] = arguments[_key];
283
+ }
284
+ this.debug && log.apply(void 0, _toConsumableArray(args));
443
285
  }
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;
286
+ },
287
+ {
288
+ key: "use",
289
+ value: function use(plugin) {
290
+ if (!this.__pluginsApplied) {
291
+ this.__plugins.push(plugin);
292
+ }
293
+ return this;
294
+ }
295
+ },
296
+ {
297
+ key: "registerControl",
298
+ value: // 注册外部控件
299
+ function registerControl() {
300
+ for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
301
+ arg[_key] = arguments[_key];
302
+ }
303
+ var _runtime;
304
+ (_runtime = this.runtime).register.apply(_runtime, _toConsumableArray(arg));
305
+ return this;
306
+ }
307
+ },
308
+ {
309
+ key: "mount",
310
+ value: function mount() {
311
+ this.debugLog("engine的mount方法开始调用");
312
+ var _$options = this.$options, _plugins = _$options.plugins, plugins = _plugins === void 0 ? [] : _plugins;
313
+ this._handlerProxyState();
314
+ this.__plugins = plugins;
315
+ this.applyPlugins();
316
+ // 触发所有控件的默认值的change事件
317
+ this.setStates(this.getState());
318
+ this.debugLog("engine的mount方法调用结束");
319
+ if (this.debug && typeof window !== 'undefined') {
320
+ // @ts-ignore
321
+ window.engines[this.id] = this;
322
+ }
323
+ }
324
+ },
325
+ {
326
+ key: "destroy",
327
+ value: function destroy() {
328
+ if (this.debug && typeof window !== 'undefined') {
329
+ // @ts-ignore
330
+ delete window.engines[this.id];
331
+ }
332
+ }
333
+ },
334
+ {
335
+ key: "_handlerProxyState",
336
+ value: function _handlerProxyState() {
337
+ this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
338
+ }
339
+ },
340
+ {
341
+ key: "_proxyStateBeforeSetCallback",
342
+ value: function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
343
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
344
+ // 找不到控件说明不是改动控件上的字段,直接通过
345
+ if (!instance) {
346
+ return newValue;
450
347
  }
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
348
  // @ts-ignore
486
- var row = _this.listControlCreateRow(subtable, "subtable-row");
487
- row && newRows.push(row);
349
+ if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE)) {
350
+ var ref;
351
+ if (newValue === null) {
352
+ return [];
353
+ }
354
+ // @ts-ignore
355
+ var fieldTypeMap = instance.props.headers.reduce(function(result, column) {
356
+ var formInstance = column.children[0];
357
+ // if (formInstance && formInstance instanceof RuntimeFormControl) {
358
+ if (formInstance && formInstance.controlType === CONTROL_BASE_TYPE.FORM) {
359
+ result[formInstance.id] = formInstance.fieldType;
360
+ }
361
+ return result;
362
+ }, {});
363
+ // @ts-ignore
364
+ var emptyState = this.getEmptyState(instance.id);
365
+ return (ref = newValue) === null || ref === void 0 ? void 0 : ref.map(function(row) {
366
+ // @ts-ignore
367
+ return checkerSubtableValue(fieldTypeMap, row, emptyState);
368
+ });
369
+ }
370
+ var keys = key.split('.');
371
+ var lastKey = keys[keys.length - 1];
372
+ try {
373
+ return checkerValue(instance.fieldType, lastKey, newValue, oldValue);
374
+ } catch (e) {
375
+ warn("the id=".concat(instance.id, "'s instance setState error, %o ").concat(e, "."), newValue);
376
+ throw e;
377
+ }
488
378
  }
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();
379
+ },
380
+ {
381
+ key: "_proxyStateCallback",
382
+ value: function _proxyStateCallback(state, key, type, args, result) {
383
+ if (Array.isArray(state)) {
384
+ this._handlerArrayUpdate(state, key, type, args, result);
385
+ } else {
386
+ this._handlerObjectUpdate(state, key, type, args);
387
+ }
388
+ }
389
+ },
390
+ {
391
+ key: "_handlerArrayUpdate",
392
+ value: function _handlerArrayUpdate(state, key, type, args, result) {
393
+ var _this = this;
394
+ var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
395
+ // if (!(subtable instanceof RuntimeListControl)) return
396
+ if (!(subtable.controlType === CONTROL_BASE_TYPE.LIST)) return;
397
+ // 新增多行方法
398
+ var createRows = function(len) {
399
+ // @ts-ignore
400
+ var newRows = [];
401
+ for(var i = 0; i < len; i++){
402
+ // @ts-ignore
403
+ var row = _this.listControlCreateRow(subtable, 'subtable-row');
404
+ row && newRows.push(row);
405
+ }
406
+ // @ts-ignore
407
+ return newRows;
408
+ };
409
+ var options = eventOptionsTemp;
410
+ // @ts-ignore
411
+ var createdNewRows = [];
412
+ var createdNewRowsData = [];
413
+ var deleted = [];
414
+ if (type && args) {
415
+ // const subtableOldLength = subtable.children.length
416
+ switch(type){
417
+ case 'push':
418
+ case 'unshift':
419
+ var _children;
420
+ var newRowLengths = args.length;
421
+ createdNewRows = createRows(newRowLengths);
422
+ createdNewRowsData = args;
423
+ (_children = subtable.children)[type].apply(_children, _toConsumableArray(createdNewRows));
424
+ this.runtime.getFlatInstances();
425
+ break;
426
+ case 'splice':
427
+ if (args.length > 2) {
428
+ var // @ts-ignore
429
+ _children1;
430
+ var newRowLengths1 = args.length - 2;
431
+ var newValues = args.slice(2);
432
+ createdNewRows = createRows(newRowLengths1);
433
+ createdNewRowsData = newValues;
434
+ // 从哪儿开始
435
+ var start = args[0];
436
+ // 替换几个
437
+ var replace = args[1];
438
+ (_children1 = subtable.children)[type].apply(_children1, [
439
+ start,
440
+ replace
441
+ ].concat(_toConsumableArray(createdNewRows)));
442
+ this.runtime.getFlatInstances();
443
+ // newValues.forEach((item: any, index) => {
444
+ // let newIndex = start + index
445
+ // this.setStates(item, newIndex, options)
446
+ // })
447
+ } else {
448
+ var // @ts-ignore
449
+ _children2;
450
+ (_children2 = subtable.children)[type].apply(_children2, _toConsumableArray(args));
451
+ this.runtime.getFlatInstances();
452
+ }
453
+ break;
454
+ default:
455
+ var // @ts-ignore
456
+ _children3;
457
+ (_children3 = subtable.children)[type].apply(_children3, _toConsumableArray(args));
458
+ this.runtime.getFlatInstances();
459
+ break;
460
+ }
461
+ if (type === 'splice') {
462
+ deleted = result;
463
+ } else if ([
464
+ 'pop',
465
+ 'shift'
466
+ ].includes(type)) {
467
+ deleted = [
468
+ result
469
+ ];
535
470
  }
536
- break;
537
- default:
471
+ this.emit('list-change', {
472
+ instance: subtable,
473
+ value: this.getState(subtable.id),
474
+ options: Object.assign({}, options, {
475
+ changed: createdNewRows,
476
+ data: createdNewRowsData,
477
+ deleted: deleted !== null && deleted !== void 0 ? deleted : [],
478
+ jsonValue: JSON.stringify(this.getState(subtable.id))
479
+ })
480
+ });
481
+ // 主动清空本次任务中的options
482
+ eventOptionsTemp = null;
483
+ }
484
+ }
485
+ },
486
+ {
487
+ key: "_handlerObjectUpdate",
488
+ value: function _handlerObjectUpdate(state, key, value, oldValue) {
489
+ var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
490
+ if (!instance) {
491
+ return;
492
+ }
493
+ var index = this.getInstanceRowIndex(instance);
494
+ var options = eventOptionsTemp || {};
495
+ // if (instance instanceof RuntimeListControl) {
496
+ if (instance.controlType === CONTROL_BASE_TYPE.LIST) {
538
497
  var // @ts-ignore
539
- _subtable_children3;
540
- (_subtable_children3 = subtable.children)[type].apply(_subtable_children3, _toConsumableArray(args));
498
+ _children;
499
+ instance.children.length = 0;
500
+ var newValue = value;
501
+ // @ts-ignore
502
+ var newRows = [];
503
+ for(var i = 0; i < newValue.length; i++){
504
+ // @ts-ignore
505
+ var row = this.listControlCreateRow(instance, 'subtable-row');
506
+ row && newRows.push(row);
507
+ }
508
+ (_children = instance.children).push.apply(_children, _toConsumableArray(newRows));
541
509
  this.runtime.getFlatInstances();
542
- break;
510
+ // 这里已经能拿到控件实例,所以在这里触发setStates,触发每一行每一个控件的change事件
511
+ // for (let i = 0; i < newValue.length; i++) {
512
+ // this.setStates(newValue[i], i, options)
513
+ // }
514
+ this.emit('list-change', {
515
+ instance: instance,
516
+ value: value,
517
+ options: _objectSpread({}, options, {
518
+ // @ts-ignore
519
+ changed: newRows,
520
+ data: newValue,
521
+ deleted: oldValue !== null && oldValue !== void 0 ? oldValue : []
522
+ })
523
+ });
524
+ } else {
525
+ this.emit('change', {
526
+ instance: instance,
527
+ value: this.getState(instance.id, index),
528
+ rowIndex: index,
529
+ options: _objectSpread({}, options, {
530
+ oldValue: oldValue
531
+ })
532
+ });
533
+ }
543
534
  }
544
- if (type === "splice") {
545
- deleted = result;
546
- } else if ([
547
- "pop",
548
- "shift"
549
- ].includes(type)) {
550
- deleted = [
551
- result
552
- ];
535
+ },
536
+ {
537
+ key: "applyPlugins",
538
+ value: function applyPlugins() {
539
+ var _this = this;
540
+ if (this.__pluginsApplied) return;
541
+ this.__plugins.forEach(function(plugin) {
542
+ try {
543
+ var _pluginName;
544
+ applyingPluginName = (_pluginName = plugin.pluginName) !== null && _pluginName !== void 0 ? _pluginName : plugin.constructor.name;
545
+ plugin.apply(_this);
546
+ } catch (e) {
547
+ error("".concat(applyingPluginName, " Plugin apply Error \n ").concat(e));
548
+ } finally{
549
+ applyingPluginName = '';
550
+ }
551
+ });
552
+ this.__pluginsApplied = true;
553
553
  }
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++){
554
+ },
555
+ {
556
+ key: "listControlCreateRow",
557
+ value: function listControlCreateRow(instance, rowType) {
558
+ var row = this.runtime.createControlInstance(rowType);
559
+ if (!row) return;
560
+ // if (row instanceof RuntimeLayoutControl) {
584
561
  // @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), {
562
+ if (row.controlType === CONTROL_BASE_TYPE.LAYOUT) {
563
+ var _children;
564
+ var inst = row;
565
+ var template = JSONCopy(instance.props.headers);
598
566
  // @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 = "";
567
+ var columns = this.createControl(template);
568
+ (_children = inst.children).push.apply(_children, _toConsumableArray(columns));
569
+ }
570
+ return row;
627
571
  }
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);
572
+ },
573
+ {
574
+ key: "listControlAddRow",
575
+ value: function listControlAddRow(instance) {
576
+ var // @ts-ignore
577
+ rowType = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 'subtable-row';
578
+ var row = this.listControlCreateRow(instance, rowType);
579
+ if (!row) return;
580
+ instance.children.push(row);
581
+ }
582
+ },
583
+ {
584
+ key: "emit",
585
+ value: // payload应该是runtimeSchema和value,然后通过runTimeSchema去找需要修改的data里边的key
586
+ function emit(eventKey, payload) {
587
+ var _this = this;
588
+ var _this1 = this, _superprop_get_emit = function() {
589
+ return _get(_getPrototypeOf(Engine.prototype), "emit", _this);
590
+ };
591
+ return _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
592
+ var needWait, promiseResolver, promise, results;
593
+ return regeneratorRuntime.wrap(function _callee$(_ctx) {
594
+ while(1)switch(_ctx.prev = _ctx.next){
595
+ case 0:
596
+ if (!(eventKey === 'engine-mounted')) {
597
+ _ctx.next = 11;
598
+ break;
599
+ }
600
+ if (!_this1.isMounted) {
601
+ _ctx.next = 4;
602
+ break;
603
+ }
604
+ warn('The engine-mounted life cycle can only be triggered once');
605
+ return _ctx.abrupt("return", Promise.resolve([]));
606
+ case 4:
607
+ if (!_this1._jobTasks.length) {
608
+ _ctx.next = 10;
609
+ break;
610
+ }
611
+ console.time('engine-mounted need wait');
612
+ needWait = _toConsumableArray(_this1._jobTasks);
613
+ _ctx.next = 9;
614
+ return Promise.all(needWait);
615
+ case 9:
616
+ console.timeEnd('engine-mounted need wait');
617
+ case 10:
618
+ _this1.isMounted = true;
619
+ case 11:
620
+ ;
621
+ ;
622
+ // 如果没有挂载的话,需要记录在挂载之前触发的所有任务
623
+ if (!_this1.isMounted) {
624
+ promise = new Promise(function(resolve) {
625
+ promiseResolver = resolve;
626
+ });
627
+ _this1._jobTasks.push(promise);
628
+ }
629
+ _ctx.next = 16;
630
+ return _superprop_get_emit().call(_this1, eventKey, payload);
631
+ case 16:
632
+ results = _ctx.sent;
633
+ if (promiseResolver && promise) {
634
+ // 每一个任务完成的时候,都把自己从task中去掉
635
+ promiseResolver();
636
+ _this1._jobTasks.splice(_this1._jobTasks.indexOf(promise), 1);
637
+ }
638
+ return _ctx.abrupt("return", results);
639
+ case 19:
640
+ case "end":
641
+ return _ctx.stop();
710
642
  }
711
- return [
712
- 2,
713
- results
714
- ];
643
+ }, _callee);
644
+ }))();
645
+ }
646
+ },
647
+ {
648
+ key: "on",
649
+ value: function on(key, callback) {
650
+ if (applyingPluginName) {
651
+ callback.applyingPluginName = applyingPluginName;
715
652
  }
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
- /**
653
+ return _get(_getPrototypeOf(Engine.prototype), "on", this).call(this, key, callback);
654
+ }
655
+ },
656
+ {
657
+ key: "createControl",
658
+ value: function createControl() {
659
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
660
+ args[_key] = arguments[_key];
661
+ }
662
+ var _runtime;
663
+ return (_runtime = this.runtime).createControl.apply(_runtime, _toConsumableArray(args));
664
+ }
665
+ },
666
+ {
667
+ key: "createInstance",
668
+ value: function createInstance(type, initSchema) {
669
+ return this.runtime.createControlInstance(type, initSchema);
670
+ }
671
+ },
672
+ {
673
+ key: "schemaEvent",
674
+ value: function schemaEvent(eventKey, payload) {
675
+ this.emit(eventKey, payload);
676
+ }
677
+ },
678
+ {
679
+ key: "updateInstanceProps",
680
+ value: function updateInstanceProps(instance, props, value, rowIndex) {
681
+ return this.setInstance(instance, props, value, rowIndex);
682
+ }
683
+ },
684
+ {
685
+ key: "getAllRules",
686
+ value: function getAllRules(controlId) {
687
+ var rules = this.runtime.allRules;
688
+ if (controlId === undefined) {
689
+ return rules;
690
+ } else {
691
+ var ref, ref1;
692
+ return {
693
+ rules: (ref = rules.rules[controlId]) === null || ref === void 0 ? void 0 : ref.fields,
694
+ antdRules: (ref1 = rules.antdRules[controlId]) === null || ref1 === void 0 ? void 0 : ref1.fields
695
+ };
696
+ }
697
+ }
698
+ },
699
+ {
700
+ key: "getRules",
701
+ value: function getRules(controlId) {
702
+ if (controlId === undefined) {
703
+ return this.runtime.rules;
704
+ } else {
705
+ var ref;
706
+ return (ref = this.runtime.rules[controlId]) === null || ref === void 0 ? void 0 : ref.fields;
707
+ }
708
+ }
709
+ },
710
+ {
711
+ key: "getAntdRules",
712
+ value: function getAntdRules(controlId) {
713
+ if (controlId === undefined) {
714
+ return this.runtime.antdRules;
715
+ } else {
716
+ var ref;
717
+ return (ref = this.runtime.antdRules[controlId]) === null || ref === void 0 ? void 0 : ref.fields;
718
+ }
719
+ }
720
+ },
721
+ {
722
+ key: "getState",
723
+ value: function getState(controlId, rowIndex) {
724
+ if (controlId === undefined) {
725
+ return this.store.state;
726
+ } else {
727
+ return this.store.getState(controlId, rowIndex);
728
+ }
729
+ }
730
+ },
731
+ {
732
+ key: "getEmptyState",
733
+ value: function getEmptyState(controlId) {
734
+ if (controlId === undefined) {
735
+ return JSONCopy(this.store.emptyState);
736
+ } else {
737
+ return JSONCopy(this.store.getEmptyState(controlId));
738
+ }
739
+ }
740
+ },
741
+ {
742
+ /**
784
743
  * 设置payload的options,提供在不是使用标准api修改state的时候可以传递options,会在本次任务执行完成之后清空
785
744
  * @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
- /**
745
+ * */ key: "setPayloadOptions",
746
+ value: function setPayloadOptions(options) {
747
+ eventOptionsTemp = options;
748
+ }
749
+ },
750
+ {
751
+ key: "setState",
752
+ value: function setState(controlId, value, rowIndex, options) {
753
+ eventOptionsTemp = options;
754
+ this.debugLog('[%o]: 触发setState, 修改的值为%o, rowIndex=%o, options=%o', controlId, value, rowIndex, options);
755
+ this.store.setState(controlId, value, rowIndex);
756
+ this.debugLog('[%o]: setState完成, 修改的值为%o, rowIndex=%o', controlId, value, rowIndex);
757
+ eventOptionsTemp = null;
758
+ }
759
+ },
760
+ {
761
+ /**
797
762
  * 向Store设置一组值,明细表必须全量赋值,并触发事件(触发事件是根据组件在页面中的顺序逐个触发)
798
763
  * @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);
764
+ */ key: "setStates",
765
+ value: function setStates(states, rowIndex, options) {
766
+ var _this = this;
767
+ var newStates = states !== null && states !== void 0 ? states : {};
768
+ Object.keys(newStates).forEach(function(stateId) {
769
+ var _this2 = _this;
770
+ Object.entries(_this.store.controlIdMapping).forEach(function(param) {
771
+ var _param = _slicedToArray(param, 2), controlId = _param[0], controlIdMapping = _param[1];
772
+ if (controlIdMapping.dataView === stateId) {
773
+ // state对象是dataView包裹的
774
+ var value = newStates[stateId][controlId];
775
+ if (value !== undefined) {
776
+ _this2.setState(controlId, value, rowIndex, options);
777
+ }
778
+ } else {
779
+ // state对象是单独的,没有被dataView包裹的
780
+ if (controlId === stateId || controlIdMapping.children && controlIdMapping.children[stateId]) {
781
+ if (newStates[stateId] !== undefined) {
782
+ _this2.setState(stateId, newStates[stateId], rowIndex, options);
783
+ }
784
+ }
816
785
  }
817
- }
818
- }
819
- });
820
- });
821
- };
822
- /**
786
+ });
787
+ });
788
+ }
789
+ },
790
+ {
791
+ /**
823
792
  * 通过dataCode和fieldCode来获取控件的值
824
793
  * @param dataCode 模型编码 - 如果是主表的话就是主表的模型编码,明细子表的话就是子表的模型编码
825
794
  * @param fieldCode 字段编码 - 控件绑定的数据项的编码
826
795
  * @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];
796
+ * */ key: "getField",
797
+ value: function getField(dataCode, fieldCode, rowIndex) {
798
+ if (!fieldCode) {
799
+ var dataBindMapping = this.getDataBindMapping(dataCode);
800
+ if (dataBindMapping) {
801
+ var controlId = dataBindMapping.controlId;
802
+ return this.getState(controlId);
803
+ }
804
+ return;
848
805
  }
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
- }
806
+ var dataBindMapping1 = this.getDataBindMapping(dataCode, fieldCode);
807
+ if (!dataBindMapping1) {
808
+ return;
809
+ }
810
+ var dataBind1 = dataBindMapping1.dataBind, controlId1 = dataBindMapping1.controlId;
811
+ var state = this.getState(controlId1, rowIndex);
812
+ //if (dataBind instanceof ObjectDataBind) {
813
+ if (!isDataBind(dataBind1)) {
814
+ return Object.entries(dataBind1).reduce(function(result, param) {
815
+ var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
816
+ // objectDataBind的元素,跳过下一次赋值
817
+ if (dataBind.fieldCode === fieldCode) {
818
+ return result[key];
881
819
  }
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;
820
+ return result;
821
+ }, state);
822
+ } else {
823
+ return state;
824
+ }
825
+ }
826
+ },
827
+ {
828
+ key: "getData",
829
+ value: function getData(dataCode) {
830
+ if (!dataCode) return;
831
+ var dataBindMapping = this.getDataBindMapping(dataCode);
832
+ var controlIdMapping = this.getControlIdMapping();
833
+ if (dataBindMapping) {
834
+ var controlId = dataBindMapping.controlId;
835
+ var getFieldData = this.getField(dataCode);
836
+ // 明细子表值
837
+ if (Array.isArray(getFieldData)) {
838
+ var data = getFieldData.map(function(item) {
839
+ var obj = {};
840
+ for(var key in item){
841
+ var ref, ref2, ref3;
842
+ var fieldCode = (ref2 = (ref = controlIdMapping[controlId]) === null || ref === void 0 ? void 0 : ref.children[key]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.dataBind) === null || ref3 === void 0 ? void 0 : ref3.fieldCode;
900
843
  //未绑定字段的控件,直接抛弃
901
- if (fieldCode !== "") {
844
+ if (fieldCode !== '') {
845
+ var ref4;
902
846
  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];
847
+ obj[fieldCode] = item[key];
848
+ } else if ((ref4 = controlIdMapping[controlId]) === null || ref4 === void 0 ? void 0 : ref4.children[key]) {
849
+ // 兼容一个控件需要绑定多个字段的情况
850
+ for(var keyChi in item[key]){
851
+ var ref5, ref6;
852
+ obj[(ref6 = (ref5 = controlIdMapping[controlId]) === null || ref5 === void 0 ? void 0 : ref5.children[key]) === null || ref6 === void 0 ? void 0 : ref6.dataBind[keyChi].fieldCode] = item[key][keyChi];
908
853
  }
909
854
  }
910
855
  }
911
856
  }
912
- return objChi;
857
+ return obj;
913
858
  });
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
- }
859
+ return data;
860
+ } else {
861
+ var _loop = function(key1) {
862
+ var ref15, ref7, ref8, ref9;
863
+ if ((ref15 = controlIdMapping[key1]) === null || ref15 === void 0 ? void 0 : (ref7 = ref15.dataBind) === null || ref7 === void 0 ? void 0 : ref7.fieldCode) {
864
+ var ref10;
865
+ obj1[(ref10 = controlIdMapping[key1]) === null || ref10 === void 0 ? void 0 : ref10.dataBind.fieldCode] = getFieldData[key1];
866
+ } else if ((ref8 = controlIdMapping[key1]) === null || ref8 === void 0 ? void 0 : (ref9 = ref8.dataBind) === null || ref9 === void 0 ? void 0 : ref9.dataCode) {
867
+ var ref11;
868
+ // 明细字表只循环一层明细子表未递归
869
+ obj1[(ref11 = controlIdMapping[key1]) === null || ref11 === void 0 ? void 0 : ref11.dataBind.dataCode] = getFieldData[key1].map(function(item) {
870
+ var objChi = {};
871
+ for(var keyChi in item){
872
+ var ref;
873
+ var fieldCode = (ref = controlIdMapping[key1].children[keyChi]) === null || ref === void 0 ? void 0 : ref.dataBind.fieldCode;
874
+ //未绑定字段的控件,直接抛弃
875
+ if (fieldCode !== '') {
876
+ if (fieldCode) {
877
+ objChi[fieldCode] = item[keyChi];
878
+ } else {
879
+ for(var keyChi1 in item[keyChi]){
880
+ var ref14;
881
+ objChi[(ref14 = controlIdMapping[key1].children[keyChi]) === null || ref14 === void 0 ? void 0 : ref14.dataBind[keyChi1].fieldCode] = item[keyChi][keyChi1];
882
+ }
883
+ }
884
+ }
885
+ }
886
+ return objChi;
887
+ });
888
+ } else if (controlIdMapping[key1]) {
889
+ // 兼容一个控件需要绑定多个字段的情况
890
+ for(var keyChi2 in getFieldData[key1]){
891
+ var ref12, ref13;
892
+ obj1[(ref13 = (ref12 = controlIdMapping[key1]) === null || ref12 === void 0 ? void 0 : ref12.dataBind[keyChi2]) === null || ref13 === void 0 ? void 0 : ref13.fieldCode] = getFieldData[key1][keyChi2];
893
+ }
894
+ }
895
+ };
896
+ // 主表
897
+ var obj1 = {};
898
+ for(var key1 in getFieldData)_loop(key1);
899
+ return obj1;
920
900
  }
921
- };
922
- // 主表
923
- var obj = {};
924
- for(var key in getFieldData)_loop(key);
925
- return obj;
901
+ }
902
+ return;
926
903
  }
927
- }
928
- return;
929
- };
930
- /**
904
+ },
905
+ {
906
+ /**
931
907
  * 通过dataCode和fieldCode来设置控件的值
932
908
  * @param dataCode 模型编码 - 如果是主表的话就是主表的模型编码,明细子表的话就是子表的模型编码
933
909
  * @param fieldCode 字段编码 - 控件绑定的数据项的编码
934
910
  * @param value 修改的值
935
911
  * @param rowIndex 行下标 - 如果是明细子表中的控件需要提供
936
912
  * @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;
913
+ * */ key: "setField",
914
+ value: function setField(dataCode, fieldCode, value, rowIndex, options) {
915
+ var dataBindMapping = this.getDataBindMapping(dataCode, fieldCode);
916
+ if (!dataBindMapping) {
917
+ return;
952
918
  }
953
- return result;
954
- }, oldState);
955
- this.setState(controlId, newState, rowIndex, options);
956
- } else {
957
- this.setState(controlId, value, rowIndex, options);
958
- }
959
- };
960
- /**
919
+ var dataBind2 = dataBindMapping.dataBind, controlId = dataBindMapping.controlId;
920
+ // if (dataBind instanceof ObjectDataBind) {
921
+ if (!isDataBind(dataBind2)) {
922
+ var ref;
923
+ var oldState = (ref = JSONCopy(this.getState(controlId, rowIndex))) !== null && ref !== void 0 ? ref : this.getEmptyState(controlId);
924
+ // fieldCode不代表是key,所以需要找到对应的key
925
+ var newState = Object.entries(dataBind2).reduce(function(result, param) {
926
+ var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
927
+ // objectDataBind的元素,跳过下一次赋值
928
+ if (dataBind.fieldCode === fieldCode) {
929
+ result[key] = value;
930
+ }
931
+ return result;
932
+ }, oldState);
933
+ this.setState(controlId, newState, rowIndex, options);
934
+ } else {
935
+ this.setState(controlId, value, rowIndex, options);
936
+ }
937
+ }
938
+ },
939
+ {
940
+ /**
961
941
  * 通过dataCode和 state来给一组控件赋值,并触发事件携带options
962
942
  * @param dataCode 需要赋值的目标模型
963
943
  * @param state 赋值对象,以fieldCode为key组成的对象
964
944
  * @param rowIndex 行下标,给明细子表赋值时指定赋值某行
965
945
  * @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;
946
+ * */ key: "setFields",
947
+ value: function setFields(dataCode, state, rowIndex, options) {
948
+ var _this = this;
949
+ var mapping = this.getDataBindMapping(dataCode);
950
+ if (!mapping) {
951
+ return;
952
+ }
953
+ var skipKeys = [];
954
+ mapping.fields.forEach(function(item) {
955
+ var dataBind3 = item.dataBind, controlId = item.controlId, fieldCode = item.fieldCode;
956
+ if (skipKeys.includes(fieldCode)) {
957
+ return;
993
958
  }
994
- return result;
995
- }, oldState);
996
- _this.setState(item.controlId, newState, rowIndex, options);
997
- } else {
998
- _this.setState(controlId, state[fieldCode], rowIndex, options);
959
+ if (!Object.hasOwnProperty.call(state, fieldCode)) {
960
+ return;
961
+ }
962
+ // 对象类型的值
963
+ // if (dataBind instanceof ObjectDataBind) {
964
+ if (!isDataBind(dataBind3)) {
965
+ var ref;
966
+ var oldState = (ref = JSONCopy(_this.getState(controlId, rowIndex))) !== null && ref !== void 0 ? ref : _this.getEmptyState(controlId);
967
+ // fieldCode不代表是key,所以需要找到对应的key
968
+ var newState = Object.entries(dataBind3).reduce(function(result, param) {
969
+ var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
970
+ // objectDataBind的元素,跳过下一次赋值
971
+ skipKeys.push(dataBind.fieldCode);
972
+ var value = state[dataBind.fieldCode];
973
+ if (value !== undefined) {
974
+ result[key] = value;
975
+ }
976
+ return result;
977
+ }, oldState);
978
+ _this.setState(item.controlId, newState, rowIndex, options);
979
+ } else {
980
+ _this.setState(controlId, state[fieldCode], rowIndex, options);
981
+ }
982
+ });
999
983
  }
1000
- });
1001
- };
1002
- /**
984
+ },
985
+ {
986
+ /**
1003
987
  * 通过dataCode来将state转化为标准的state结构
1004
988
  * @param dataCode 需要转换的目标模型code
1005
989
  * @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;
990
+ * */ key: "buildFields",
991
+ value: function buildFields(dataCode, state) {
992
+ var _this = this;
993
+ var mapping = this.getDataBindMapping(dataCode);
994
+ if (!mapping) {
995
+ return;
996
+ }
997
+ var skipKeys = [];
998
+ var result1 = {};
999
+ mapping.fields.forEach(function(item) {
1000
+ var dataBind4 = item.dataBind, controlId = item.controlId, fieldCode = item.fieldCode;
1001
+ if (skipKeys.includes(fieldCode)) {
1002
+ return;
1033
1003
  }
1034
- return result;
1035
- }, oldState);
1036
- } else {
1037
- result[controlId] = state[fieldCode];
1004
+ if (!Object.hasOwnProperty.call(state, fieldCode)) {
1005
+ return;
1006
+ }
1007
+ // 对象类型的值
1008
+ // if (dataBind instanceof ObjectDataBind) {
1009
+ if (!isDataBind(dataBind4)) {
1010
+ var oldState = _this.getEmptyState(controlId);
1011
+ // fieldCode不代表是key,所以需要找到对应的key
1012
+ result1[item.controlId] = Object.entries(dataBind4).reduce(function(result, param) {
1013
+ var _param = _slicedToArray(param, 2), key = _param[0], dataBind = _param[1];
1014
+ // objectDataBind的元素,跳过下一次赋值
1015
+ skipKeys.push(dataBind.fieldCode);
1016
+ var value = state[dataBind.fieldCode];
1017
+ if (value !== undefined) {
1018
+ result[key] = value;
1019
+ }
1020
+ return result;
1021
+ }, oldState);
1022
+ } else {
1023
+ result1[controlId] = state[fieldCode];
1024
+ }
1025
+ });
1026
+ return result1;
1038
1027
  }
1039
- });
1040
- return result;
1041
- };
1042
- /**
1028
+ },
1029
+ {
1030
+ /**
1043
1031
  * 向Store设置一组值,并触发事件携带options
1044
1032
  * @param dataSet
1045
1033
  * @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)) {
1034
+ */ key: "setData",
1035
+ value: function setData(dataSet, options) {
1036
+ var _this6 = this;
1037
+ this.debugLog("engine setData方法执行,参数为%o,%o。", dataSet, options);
1038
+ var newState = this.store.defaultState;
1039
+ Object.keys(dataSet).map(function(dataCode) {
1040
+ var entity = dataSet[dataCode];
1041
+ if (Array.isArray(entity)) {
1042
+ var _this4 = _this6;
1043
+ var mapping = _this6.getDataBindMapping(dataCode);
1044
+ if (!mapping) {
1068
1045
  return;
1069
1046
  }
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
- }
1047
+ if (!newState[mapping.dataViewId]) {
1048
+ newState[mapping.dataViewId] = {};
1088
1049
  }
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;
1050
+ if (!entity.length) {
1051
+ var _controlId;
1052
+ newState[mapping.dataViewId][mapping.controlId] = (_controlId = newState[mapping.dataViewId][mapping.controlId]) !== null && _controlId !== void 0 ? _controlId : [];
1053
+ } else {
1054
+ newState[mapping.dataViewId][mapping.controlId] = [];
1103
1055
  }
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);
1056
+ entity.map(function(row) {
1057
+ var _this = _this4;
1058
+ var newRow = JSONCopy(_this4.store.emptyState[mapping.dataViewId][mapping.controlId]);
1059
+ var skipKey = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1060
+ ;
1061
+ Object.keys(row).map(function(fieldCode) {
1062
+ var ref, ref18;
1063
+ if (skipKey.includes(fieldCode)) {
1064
+ return;
1065
+ }
1066
+ var fieldMapping = (ref = _this.store.dataBindMapping[dataCode]) === null || ref === void 0 ? void 0 : (ref18 = ref.fields) === null || ref18 === void 0 ? void 0 : ref18.find(function(i) {
1067
+ return i.fieldCode === fieldCode;
1120
1068
  });
1121
- newState[mapping.dataViewId[0]][mapping.controlId] = objValue;
1122
- }
1069
+ if (fieldMapping) {
1070
+ if (// fieldMapping.dataBind instanceof DataBind &&
1071
+ isDataBind(fieldMapping.dataBind) && row[fieldCode] !== undefined) {
1072
+ newRow[fieldMapping.controlId] = row[fieldCode];
1073
+ // } else if (fieldMapping.dataBind instanceof ObjectDataBind) {
1074
+ } else if (!isDataBind(fieldMapping.dataBind)) {
1075
+ var ref19;
1076
+ var objValue = JSONCopy((ref19 = _this.getEmptyState(fieldMapping.controlId)) !== null && ref19 !== void 0 ? ref19 : {});
1077
+ Object.keys(fieldMapping.dataBind).map(function(key) {
1078
+ var dataBind = fieldMapping.dataBind[key];
1079
+ if (row[dataBind.fieldCode] !== undefined) {
1080
+ objValue[key] = row[dataBind.fieldCode];
1081
+ }
1082
+ skipKey.push(dataBind.fieldCode);
1083
+ });
1084
+ newRow[fieldMapping.controlId] = objValue;
1085
+ }
1086
+ }
1087
+ });
1088
+ newState[mapping.dataViewId][mapping.controlId].push(newRow);
1089
+ });
1090
+ } else if (entity) {
1091
+ var ref20;
1092
+ var skipKey1 = [] //qiyu ObjectDataBind中会提前将相关key拿出来赋值,为了避免重复赋值,设置了此变量
1093
+ ;
1094
+ var emptyState = JSONCopy(_this6.store.emptyState);
1095
+ if (!((ref20 = Object.keys(entity)) === null || ref20 === void 0 ? void 0 : ref20.length)) {
1096
+ // newState = this.store.defaultState
1097
+ } else {
1098
+ var _this3 = _this6;
1099
+ Object.keys(entity).map(function(fieldCode) {
1100
+ if (skipKey1.includes(fieldCode)) {
1101
+ return;
1102
+ }
1103
+ var mapping = _this3.getDataBindMapping(dataCode, fieldCode);
1104
+ if (mapping) {
1105
+ if (!newState[mapping.dataViewId[0]]) {
1106
+ newState[mapping.dataViewId[0]] = {};
1107
+ }
1108
+ if (// mapping.dataBind instanceof DataBind &&
1109
+ isDataBind(mapping.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 (mapping.dataBind instanceof ObjectDataBind) {
1112
+ } else if (!isDataBind(mapping.dataBind)) {
1113
+ var ref;
1114
+ var objValue = (ref = _this3.getEmptyState(mapping.controlId)) !== null && ref !== void 0 ? ref : {};
1115
+ Object.keys(mapping.dataBind).map(function(key) {
1116
+ var dataBind = mapping.dataBind[key];
1117
+ if (entity[dataBind.fieldCode] !== undefined) {
1118
+ objValue[key] = entity[dataBind.fieldCode];
1119
+ }
1120
+ skipKey1.push(dataBind.fieldCode);
1121
+ });
1122
+ newState[mapping.dataViewId[0]][mapping.controlId] = objValue;
1123
+ }
1124
+ }
1125
+ });
1123
1126
  }
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
- }
1127
+ var newMapping = _this6.getDataBindMapping(dataCode);
1128
+ if (newMapping) {
1129
+ var ref16;
1130
+ var mappingKeys = newMapping === null || newMapping === void 0 ? void 0 : (ref16 = newMapping.fields) === null || ref16 === void 0 ? void 0 : ref16.map(function(item) {
1131
+ return item === null || item === void 0 ? void 0 : item.controlId;
1132
+ });
1133
+ var mappingValue = _this6.getEmptyState(newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId);
1134
+ var ref17;
1135
+ var mainStateKeys = Object.keys((ref17 = newState === null || newState === void 0 ? void 0 : newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) !== null && ref17 !== void 0 ? ref17 : {});
1136
+ mappingKeys === null || mappingKeys === void 0 ? void 0 : mappingKeys.forEach(function(key) {
1137
+ if (!mainStateKeys.includes(key) && key !== 'uid' && newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId]) {
1138
+ if (Object.keys(newState).length) {
1139
+ Object.assign(newState[newMapping === null || newMapping === void 0 ? void 0 : newMapping.controlId], _defineProperty({}, key, mappingValue[key]));
1140
+ } else {
1141
+ Object.assign(newState, _defineProperty({}, newMapping.controlId, _defineProperty({}, key, mappingValue[key])));
1142
+ }
1143
+ }
1144
+ });
1145
+ _this6.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
1142
1146
  }
1143
- });
1144
- _this.debugLog("engine setData方法默认值及表单数据组合完成,参数为%o。", newState);
1145
- }
1147
+ }
1148
+ });
1149
+ this.debugLog("engine setData方法数据组合完成,参数为%o。", newState);
1150
+ this.setStates(newState, undefined, options);
1151
+ this.debugLog("engine setData方法执行完成。");
1146
1152
  }
1147
- });
1148
- this.debugLog("engine setData方法数据组合完成,参数为%o。", newState);
1149
- this.setStates(newState, undefined, options);
1150
- this.debugLog("engine setData方法执行完成。");
1151
- };
1152
- /**
1153
+ },
1154
+ {
1155
+ /**
1153
1156
  * 获取控件的dataBind
1154
1157
  * @param controlId
1155
- * */ _proto.getDataBind = function getDataBind(controlId) {
1156
- return this.store.getDataBind(controlId);
1157
- };
1158
- /**
1158
+ * */ key: "getDataBind",
1159
+ value: function getDataBind(controlId) {
1160
+ return this.store.getDataBind(controlId);
1161
+ }
1162
+ },
1163
+ {
1164
+ /**
1159
1165
  * 获取组件实例,传入rowIndex代表获取明细表内的控件实例,rowIndex传入-1代表获取表头内的实例
1160
1166
  * @param controlId
1161
1167
  * @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];
1168
+ */ key: "getInstance",
1169
+ value: function getInstance(controlId, rowIndex) {
1170
+ var instances = this.getInstances(controlId, rowIndex === -1);
1171
+ if (instances.length > 0) {
1172
+ if (rowIndex !== undefined) {
1173
+ if (rowIndex === -1) {
1174
+ return instances[0];
1175
+ }
1176
+ return instances[rowIndex];
1177
+ } else {
1178
+ return instances[0];
1179
+ }
1180
+ } else {
1181
+ return undefined;
1168
1182
  }
1169
- return instances[rowIndex];
1170
- } else {
1171
- return instances[0];
1172
1183
  }
1173
- } else {
1174
- return undefined;
1175
- }
1176
- };
1177
- /**
1184
+ },
1185
+ {
1186
+ /**
1178
1187
  * 获取组件实例,明细表中的组件将会得到数组, 第二个参数为(false/不传入)则获取到的是明细表内不包含表头内实例的所有控件实例,传入true则获取到包含表头内实例的所有控件实例,表头内实例永远在下标0的位置
1179
1188
  * @param controlId
1180
1189
  * @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
- }
1190
+ */ key: "getInstances",
1191
+ value: function getInstances(controlId) {
1192
+ var header = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1193
+ // const cc = console
1194
+ // const label = '🐑 genInstances ' + controlId + ' ' + Date.now()
1195
+ // cc.time(label)
1196
+ if (controlId === undefined) {
1197
+ // cc.timeEnd(label)
1198
+ return this.runtime.flatInstances;
1200
1199
  }
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);
1200
+ var instances = Array.from(this.runtime.instanceMap[controlId] || []);
1201
+ if (header) {
1202
+ // 如果能从flatInstances里边取到,就通过getInstanceInSubtableHeader方法取,取不到则换一种方式
1203
+ if (instances.length) {
1204
+ var instance = instances[0];
1205
+ // if (this.inList(instance.id) === true) {
1206
+ if (this.inList(instance.id) !== undefined) {
1207
+ var headerInstance = this.getInstanceInSubtableHeader(instance);
1208
+ if (headerInstance) {
1209
+ instances.unshift(headerInstance);
1210
+ }
1211
+ }
1212
+ } else {
1213
+ var ref;
1214
+ var controlIdMapping = (ref = this.getControlIdMapping()) !== null && ref !== void 0 ? ref : {};
1215
+ var ref21;
1216
+ var ref22 = _slicedToArray((ref21 = Object.entries(controlIdMapping).find(function(param) {
1217
+ var _param = _slicedToArray(param, 2), _ = _param[0], mapping = _param[1];
1218
+ return mapping.children && controlId in mapping.children;
1219
+ })) !== null && ref21 !== void 0 ? ref21 : [], 1), subtableId = ref22[0];
1220
+ if (subtableId) {
1221
+ var subtable = this.getInstance(subtableId);
1222
+ // @ts-ignore
1223
+ var headerColumn = subtable.props.headers.find(function(column) {
1224
+ return column.children.find(function(item) {
1225
+ return item.id === controlId;
1226
+ });
1227
+ });
1228
+ if (headerColumn) {
1229
+ var headerInstance1 = headerColumn.children.find(function(item) {
1230
+ return item.id === controlId;
1231
+ });
1232
+ if (headerInstance1) {
1233
+ instances.unshift(headerInstance1);
1234
+ }
1235
+ }
1223
1236
  }
1224
1237
  }
1225
1238
  }
1239
+ // @ts-ignore
1240
+ return instances;
1226
1241
  }
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);
1240
- updateValueFromKeys(_instance.props, props, value);
1241
- _this.schemaEvent("schema-change", {
1242
- instance: _instance,
1242
+ },
1243
+ {
1244
+ key: "setInstance",
1245
+ value: function setInstance(instance, props, value, rowIndex) {
1246
+ try {
1247
+ if (typeof instance === 'string' && rowIndex === -1) {
1248
+ var _this = this;
1249
+ //修改明细表整列属性的逻辑
1250
+ var instances = this.getInstances(instance, rowIndex === -1);
1251
+ instances.map(function(_instance) {
1252
+ if (_instance) {
1253
+ _this.debugLog("[%o]: 修改instance: %o的%o属性,修改的值为%o。", _instance.id, _instance, props, value);
1254
+ updateValueFromKeys(_instance.props, props, value);
1255
+ _this.schemaEvent('schema-change', {
1256
+ instance: _instance,
1257
+ props: props,
1258
+ value: value,
1259
+ rowIndex: rowIndex
1260
+ });
1261
+ }
1262
+ });
1263
+ } else {
1264
+ var _instance1;
1265
+ if (typeof instance === 'string') {
1266
+ _instance1 = this.getInstance(instance, rowIndex);
1267
+ } else {
1268
+ _instance1 = instance;
1269
+ }
1270
+ if (!_instance1) {
1271
+ return;
1272
+ }
1273
+ this.debugLog("[%o]: 修改instance: %o的%o属性,修改的值为%o。", _instance1.id, _instance1, props, value);
1274
+ updateValueFromKeys(_instance1.props, props, value);
1275
+ this.schemaEvent('schema-change', {
1276
+ instance: _instance1,
1243
1277
  props: props,
1244
1278
  value: value,
1245
1279
  rowIndex: rowIndex
1246
1280
  });
1247
1281
  }
1248
- });
1249
- } else {
1250
- var _instance;
1251
- if (typeof instance === "string") {
1252
- _instance = this.getInstance(instance, rowIndex);
1253
- } else {
1254
- _instance = instance;
1282
+ } catch (e) {
1283
+ throw e;
1284
+ }
1285
+ }
1286
+ },
1287
+ {
1288
+ key: "getControlIdMapping",
1289
+ value: function getControlIdMapping() {
1290
+ return this.store.controlIdMapping;
1291
+ }
1292
+ },
1293
+ {
1294
+ key: "getDataBindMapping",
1295
+ value: function getDataBindMapping(dataCode, fieldCode) {
1296
+ if (!dataCode && !fieldCode) {
1297
+ return this.store.dataBindMapping;
1255
1298
  }
1256
- if (!_instance) {
1299
+ var mapping = this.store.dataBindMapping[dataCode];
1300
+ if (!mapping) {
1301
+ warn("No corresponding dataCode=".concat(dataCode, " was found"));
1257
1302
  return;
1258
1303
  }
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
1304
+ if (!fieldCode) {
1305
+ return mapping;
1306
+ }
1307
+ var dataBindMapping = mapping.fields.find(function(item) {
1308
+ return item.fieldCode === fieldCode;
1266
1309
  });
1310
+ if (!dataBindMapping) {
1311
+ warn("No corresponding fieldCode=".concat(fieldCode, " was found"));
1312
+ return;
1313
+ }
1314
+ return dataBindMapping;
1267
1315
  }
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
- /**
1316
+ },
1317
+ {
1318
+ key: "getAction",
1319
+ value: function getAction() {
1320
+ return this.actionManager;
1321
+ }
1322
+ },
1323
+ {
1324
+ key: "initDataManager",
1325
+ value: function initDataManager(callbackExecuter) {
1326
+ this.dataManager = new DataManager(callbackExecuter);
1327
+ }
1328
+ },
1329
+ {
1330
+ key: "getDataManager",
1331
+ value: function getDataManager() {
1332
+ return this.dataManager;
1333
+ }
1334
+ },
1335
+ {
1336
+ key: "assertInstance",
1337
+ value: /**
1306
1338
  * 判断控件的类型,返回当前控件的正确类型
1307
- * */ _proto.assertInstance = function assertInstance(instance, types) {
1308
- return isString(types) ? instance.type === types : types.includes(instance.type);
1309
- };
1310
- /**
1339
+ * */ function assertInstance(instance, types) {
1340
+ return isString(types) ? instance.type === types : types.includes(instance.type);
1341
+ }
1342
+ },
1343
+ {
1344
+ key: "getInstanceRowIndex",
1345
+ value: /**
1311
1346
  * 获取控件在明细子表中的行下标,
1312
1347
  * 如果控件在表头内,则返回-1
1313
1348
  * 如果控件在表内,则返回行下标
1314
1349
  * 如果控件不在明细表内,则返回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 {
1350
+ * */ function getInstanceRowIndex(instance) {
1351
+ if (!instance.parent) {
1352
+ return;
1353
+ }
1354
+ var rowIndex;
1327
1355
  // @ts-ignore
1328
- var index = instance.parent.children.findIndex(function(item) {
1329
- return item === instance;
1356
+ if (this.assertInstance(instance.parent, CONTROL_TYPE.SUBTABLE)) {
1357
+ // 表头内的控件
1358
+ // @ts-ignore
1359
+ if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1360
+ rowIndex = -1;
1361
+ } else {
1362
+ // @ts-ignore
1363
+ var index = instance.parent.children.findIndex(function(item) {
1364
+ return item === instance;
1365
+ });
1366
+ if (index > -1) {
1367
+ rowIndex = index;
1368
+ }
1369
+ }
1370
+ } else {
1371
+ rowIndex = this.getInstanceRowIndex(instance.parent);
1372
+ }
1373
+ return rowIndex;
1374
+ }
1375
+ },
1376
+ {
1377
+ key: "getInstanceParentControl",
1378
+ value: // public getInstanceRowIndex(
1379
+ // instance: ControlRuntimeInstance<ControlsKeys> | RuntimeControl
1380
+ // ) {
1381
+ // let rowIndex: number | undefined
1382
+ // // @ts-ignore
1383
+ // if (this.assertInstance(instance, CONTROL_TYPE.SUBTABLE_COLUMN)) {
1384
+ // rowIndex = -1
1385
+ // }else{
1386
+ // const instanceList = this.runtime.instanceMap[instance.id]
1387
+ // if(Object.prototype.toString.call(instanceList) === '[object Array]'){
1388
+ // const index = instanceList.findIndex(
1389
+ // (item: any) => item === instance
1390
+ // )
1391
+ // if (index > -1) {
1392
+ // rowIndex = index
1393
+ // }
1394
+ // }
1395
+ // }
1396
+ // return rowIndex
1397
+ // }
1398
+ function getInstanceParentControl(instance, controlType) {
1399
+ if (!instance.parent) {
1400
+ return;
1401
+ }
1402
+ if (this.assertInstance(instance.parent, controlType)) {
1403
+ return instance.parent;
1404
+ }
1405
+ return this.getInstanceParentControl(instance.parent, controlType);
1406
+ }
1407
+ },
1408
+ {
1409
+ key: "getInstanceInSubtableHeader",
1410
+ value: function getInstanceInSubtableHeader(instance) {
1411
+ var rowIndex = this.getInstanceRowIndex(instance);
1412
+ if (rowIndex === undefined) {
1413
+ return;
1414
+ }
1415
+ if (rowIndex === -1) {
1416
+ return instance;
1417
+ }
1418
+ var columnInstance = this.assertInstance(instance, // @ts-ignore
1419
+ CONTROL_TYPE.SUBTABLE_COLUMN) ? instance : this.getInstanceParentControl(instance, // @ts-ignore
1420
+ CONTROL_TYPE.SUBTABLE_COLUMN);
1421
+ if (!columnInstance) {
1422
+ return;
1423
+ }
1424
+ var subtable = this.getInstanceParentControl(instance, // @ts-ignore
1425
+ CONTROL_TYPE.SUBTABLE);
1426
+ // @ts-ignore
1427
+ var headerColumn = subtable.props.headers.find(// @ts-ignore
1428
+ function(column) {
1429
+ return column.id === columnInstance.id;
1330
1430
  });
1331
- if (index > -1) {
1332
- rowIndex = index;
1431
+ if (!headerColumn) {
1432
+ return;
1333
1433
  }
1434
+ return headerColumn.children.find(// @ts-ignore
1435
+ function(item) {
1436
+ return item.id === instance.id;
1437
+ });
1438
+ }
1439
+ },
1440
+ {
1441
+ key: "setControlConfig",
1442
+ value: function setControlConfig() {
1443
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1444
+ args[_key] = arguments[_key];
1445
+ }
1446
+ var _runtime;
1447
+ return (_runtime = this.runtime).registerControlConfig.apply(_runtime, _toConsumableArray(args));
1448
+ }
1449
+ },
1450
+ {
1451
+ key: "getControlConfig",
1452
+ value: function getControlConfig(control) {
1453
+ return this.runtime.getControlConfig(control);
1454
+ }
1455
+ },
1456
+ {
1457
+ key: "inList",
1458
+ value: function inList(controlId) {
1459
+ var _controlIdMapping;
1460
+ var mapping = (_controlIdMapping = this.store.controlIdMapping) !== null && _controlIdMapping !== void 0 ? _controlIdMapping : {};
1461
+ var listKey = undefined;
1462
+ Object.keys(mapping).some(function(key) {
1463
+ var ref, ref23;
1464
+ var matched = (ref = mapping[key]) === null || ref === void 0 ? void 0 : (ref23 = ref.children) === null || ref23 === void 0 ? void 0 : ref23.hasOwnProperty(controlId);
1465
+ if (matched) {
1466
+ listKey = key;
1467
+ }
1468
+ return matched;
1469
+ });
1470
+ return listKey;
1334
1471
  }
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
1472
  }
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;
1473
+ ], [
1474
+ {
1475
+ key: "register",
1476
+ value: // 注册外部控件
1477
+ function register() {
1478
+ for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++){
1479
+ arg[_key] = arguments[_key];
1480
+ }
1481
+ var _Runtime;
1482
+ return (_Runtime = Runtime).register.apply(_Runtime, _toConsumableArray(arg));
1483
+ }
1484
+ },
1485
+ {
1486
+ key: "judgeControlIsRegistered",
1487
+ value: function judgeControlIsRegistered(control) {
1488
+ return Runtime.staticRegisteredTypes.has(control.Runtime.controlType);
1397
1489
  }
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
1490
  }
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
- };
1491
+ ]);
1413
1492
  return Engine;
1414
1493
  }(Watcher);
1415
1494
  export { Engine };