devfab 1.2.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/devfab.js CHANGED
@@ -326,130 +326,276 @@
326
326
  }
327
327
  }
328
328
 
329
- var _excluded$1 = ["component", "children", "render"];
330
- var isInit = false;
331
- var components = {}; // 组件
332
- var renderFactory = null;
333
- function _initComponent(name, comp) {
334
- if (!name) {
335
- return;
329
+ function QueryString(_url) {
330
+ this.pathname = '';
331
+ this.query = {};
332
+ var url = _url;
333
+ this.init = function () {
334
+ if (!url) {
335
+ url = location.search;
336
+ }
337
+ var index1 = url.indexOf('?');
338
+ var index2 = url.indexOf('#');
339
+ if (index1 >= 0) {
340
+ this.pathname = url.substr(0, index1);
341
+ url = index2 < 0 ? url.substr(index1 + 1) : url.substring(index1 + 1, index2);
342
+ if (url.length > 0) {
343
+ url = url.replace(/\+/g, ' ');
344
+ var params = url.split('&');
345
+ for (var i = 0, len = params.length; i < len; i++) {
346
+ var param = params[i] || '';
347
+ if (param) {
348
+ var index = param.indexOf('=');
349
+ var key = '';
350
+ var value = '';
351
+ if (index < 0) {
352
+ key = window.decode(param);
353
+ value = key;
354
+ } else {
355
+ key = window.decode(param.substr(0, index));
356
+ value = window.decode(param.substr(index + 1));
357
+ }
358
+ this.query[key] = value;
359
+ }
360
+ }
361
+ }
362
+ } else {
363
+ this.pathname = url;
364
+ }
365
+ };
366
+ this.set = function (key, value) {
367
+ this.query[key] = value;
368
+ };
369
+ this.get = function (key) {
370
+ return this.query[key];
371
+ };
372
+ this.del = function (key) {
373
+ delete this.query[key];
374
+ };
375
+ this.has = function (key) {
376
+ return this.query[key] != null;
377
+ };
378
+ this.toStr = function () {
379
+ var items = ['?'];
380
+ for (var key in this.query) {
381
+ items.push(encodeURIComponent(key));
382
+ items.push('=');
383
+ items.push(encodeURIComponent(this.query[key]));
384
+ items.push('&');
385
+ }
386
+ if (items.length === 1) {
387
+ return '';
388
+ }
389
+ items.splice(items.length - 1, 1);
390
+ return items.join('');
391
+ };
392
+ this.init();
393
+ }
394
+ String.prototype['equalsIgnoreCase'] = function (str) {
395
+ if (str == null) {
396
+ return false;
336
397
  }
337
- if (typeof name === 'string') {
338
- if (components[name]) {
339
- console.log("[warning] Component ".concat(name, " is exist!"));
340
- return;
398
+ return this.toLowerCase() === str.toLowerCase();
399
+ };
400
+ function _appendUrl(restUrl, params) {
401
+ if (!params) {
402
+ return restUrl;
403
+ }
404
+ var queryStr = [];
405
+ var queryUrl = new QueryString(restUrl);
406
+ for (var attr in params) {
407
+ if (queryUrl.get(attr)) {
408
+ continue;
341
409
  }
342
- components[name] = comp;
343
- return;
410
+ queryStr.push("".concat(attr, "=").concat(params[attr]));
344
411
  }
345
- Object.assign(components, name);
346
- }
347
- function _getComponent(name) {
348
- return components[name];
349
- }
350
- function clearComponents() {
351
- components = {};
352
- }
353
- function _initRenderFactory(fn) {
354
- renderFactory = fn;
412
+ if (!queryStr.length) {
413
+ return restUrl;
414
+ }
415
+ var queryString = queryStr.join('&');
416
+ return restUrl.indexOf('?') >= 0 ? "".concat(restUrl, "&").concat(queryString) : "".concat(restUrl, "?").concat(queryString);
355
417
  }
356
- function renderComponent(config, extraConfig) {
357
- if (!Array.isArray(config)) {
358
- return;
418
+ var hasValue = function hasValue(value) {
419
+ return value !== undefined && value !== null && value !== '';
420
+ };
421
+
422
+ /**
423
+ * 按「规范名 → 别名列表」取一个字段。
424
+ *
425
+ * const TABLE_FIELDS = { height: ['height', 'cHeight'] }
426
+ * pick(props, 'height', TABLE_FIELDS) // → props.height ?? props.cHeight
427
+ *
428
+ * `spec` 里没写这个规范名时,直接按规范名取(`pick(col, 'field')`)。
429
+ * 规范名自己也要列在别名数组里 —— 这样「已写规范名的对象」优先命中,别名兜底。
430
+ */
431
+ function pick(source, name, _spec) {
432
+ if (!source) {
433
+ return undefined;
359
434
  }
360
- var _component = [];
361
- config.forEach(function (item, i) {
362
- var _com = item.component,
363
- _children = item.children,
364
- _render = item.render,
365
- _props = _objectWithoutProperties(item, _excluded$1);
366
- var component = _getComponent(_com);
367
- if (!component && typeof _render !== 'function') {
368
- console.log("[warning] Component ".concat(_com, " is not registered!"));
369
- }
370
- var children = renderComponent(_children, extraConfig);
371
- var node = {
372
- component: component,
373
- children: children
374
- };
375
- _props.index = i;
376
- var props = Object.assign({}, extraConfig === null || extraConfig === void 0 ? void 0 : extraConfig.props, _props);
377
- if (typeof _render === 'function') {
378
- _component.push(_render({
379
- node: node,
380
- props: props
381
- }));
382
- } else if (typeof renderFactory === 'function') {
383
- _component.push(renderFactory({
384
- node: node,
385
- props: props
386
- }));
387
- } else {
388
- Object.assign(node, props);
389
- _component.push(node);
435
+ var spec = _spec;
436
+ if (typeof name === 'string' && Array.isArray(spec)) {
437
+ spec = _defineProperty({}, name, _spec);
438
+ }
439
+ var keys = spec && spec[name];
440
+ if (!keys) {
441
+ return hasValue(source[name]) ? source[name] : undefined;
442
+ }
443
+ for (var i = 0; i < keys.length; i++) {
444
+ var value = source[keys[i]];
445
+ if (hasValue(value)) {
446
+ return value;
390
447
  }
391
- });
392
- return _component;
393
- }
394
- var Builder = /*#__PURE__*/function () {
395
- function Builder() {
396
- _classCallCheck(this, Builder);
397
448
  }
398
- return _createClass(Builder, [{
449
+ return undefined;
450
+ }
451
+
452
+ var _excluded$1 = ["children", "render"];
453
+ var BaseBuilder = /*#__PURE__*/function () {
454
+ function BaseBuilder() {
455
+ _classCallCheck(this, BaseBuilder);
456
+ _defineProperty(this, "_config", {
457
+ componentField: ['component']
458
+ });
459
+ _defineProperty(this, "_components", {});
460
+ _defineProperty(this, "_renderFactory", null);
461
+ } //
462
+ return _createClass(BaseBuilder, [{
399
463
  key: "init",
400
- value: function init(fn) {
401
- if (isInit) {
464
+ value: function init(_config, _components, _renderFactory) {
465
+ this._initConfig(_config);
466
+ this._initComponent(_components);
467
+ this._initRenderFactory(_renderFactory);
468
+ }
469
+ }, {
470
+ key: "_initConfig",
471
+ value: function _initConfig(_config) {
472
+ this._config = Object.assign(this._config, _config);
473
+ }
474
+ }, {
475
+ key: "_initComponent",
476
+ value: function _initComponent(name, comp) {
477
+ if (!name) {
402
478
  return;
479
+ } else if (typeof name === 'string') {
480
+ if (this._components[name]) {
481
+ console.log("[warning] Component ".concat(name, " is exist!"));
482
+ return;
483
+ }
484
+ this._components[name] = comp;
485
+ } else if (typeof name === 'function') {
486
+ Object.assign(this._components, name === null || name === void 0 ? void 0 : name());
487
+ } else if (_typeof(name) === 'object') {
488
+ Object.assign(this._components, name);
403
489
  }
404
- if (typeof fn === 'function') {
405
- fn();
490
+ }
491
+ }, {
492
+ key: "_getComponent",
493
+ value: function _getComponent(name) {
494
+ return this._components[name];
495
+ }
496
+ }, {
497
+ key: "_clearComponents",
498
+ value: function _clearComponents() {
499
+ this._components = {};
500
+ }
501
+ }, {
502
+ key: "_initRenderFactory",
503
+ value: function _initRenderFactory(fn) {
504
+ this._renderFactory = fn;
505
+ }
506
+ }, {
507
+ key: "_renderComponent",
508
+ value: function _renderComponent(config, extraConfig) {
509
+ var _this = this;
510
+ if (!Array.isArray(config)) {
511
+ return;
406
512
  }
407
- isInit = true;
513
+ var _component = [];
514
+ config.forEach(function (_item, i) {
515
+ var item = _objectSpread2({}, _item);
516
+ var _com = pick(item, 'component', _this._config.componentField);
517
+ var _children = item.children,
518
+ _render = item.render,
519
+ _props = _objectWithoutProperties(item, _excluded$1);
520
+ var component = _this._getComponent(_com);
521
+ if (!component && typeof _render !== 'function') {
522
+ console.log("[warning] Component ".concat(_com, " is not registered!"));
523
+ }
524
+ var children = _this._renderComponent(_children, extraConfig);
525
+ var node = {
526
+ component: component,
527
+ children: children
528
+ };
529
+ _props.index = i;
530
+ var props = Object.assign({}, extraConfig === null || extraConfig === void 0 ? void 0 : extraConfig.props, {
531
+ meta: _props
532
+ });
533
+ if (typeof _render === 'function') {
534
+ _component.push(_render({
535
+ node: node,
536
+ props: props
537
+ }));
538
+ } else if (typeof _this._renderFactory === 'function') {
539
+ _component.push(_this._renderFactory({
540
+ node: node,
541
+ props: props
542
+ }));
543
+ } else {
544
+ Object.assign(node, props);
545
+ _component.push(node);
546
+ }
547
+ });
548
+ return _component;
408
549
  }
409
550
  }, {
551
+ key: "clear",
552
+ value: function clear() {
553
+ this._clearComponents();
554
+ this._renderFactory = null;
555
+ }
556
+ }]);
557
+ }();
558
+ var Builder = /*#__PURE__*/function (_BaseBuilder2) {
559
+ function Builder() {
560
+ _classCallCheck(this, Builder);
561
+ return _callSuper(this, Builder, arguments);
562
+ }
563
+ _inherits(Builder, _BaseBuilder2);
564
+ return _createClass(Builder, [{
410
565
  key: "initComponent",
411
566
  value: function initComponent(name, comp) {
412
- _initComponent(name, comp);
567
+ this._initComponent(name, comp);
413
568
  }
414
569
  }, {
415
570
  key: "getComponents",
416
571
  value: function getComponents() {
417
- return _objectSpread2({}, components);
572
+ return _objectSpread2({}, this._components);
418
573
  }
419
574
  }, {
420
575
  key: "getComponent",
421
576
  value: function getComponent(name) {
422
- return _getComponent(name);
577
+ return this._getComponent(name);
423
578
  }
424
579
  }, {
425
580
  key: "hasComponent",
426
581
  value: function hasComponent(name) {
427
- return !!_getComponent(name);
582
+ return !!this._getComponent(name);
428
583
  }
429
584
  }, {
430
585
  key: "initRenderFactory",
431
586
  value: function initRenderFactory(fn) {
432
- _initRenderFactory(fn);
433
- }
434
- }, {
435
- key: "initRequest",
436
- value: function initRequest() {
437
- //
587
+ this._initRenderFactory(fn);
438
588
  }
439
589
  }, {
440
590
  key: "render",
441
591
  value: function render(config, extraConfig) {
442
- return renderComponent(config, extraConfig);
443
- }
444
- }, {
445
- key: "clear",
446
- value: function clear() {
447
- clearComponents();
448
- renderFactory = null;
449
- isInit = false;
592
+ return this._renderComponent(config, extraConfig);
450
593
  }
451
594
  }]);
452
- }();
595
+ }(BaseBuilder);
596
+ Builder.create = function (args) {
597
+ return new Builder(args);
598
+ };
453
599
 
454
600
  var CacheUtil = /*#__PURE__*/function () {
455
601
  function CacheUtil(args) {
@@ -459,23 +605,23 @@
459
605
  return _createClass(CacheUtil, [{
460
606
  key: "_init",
461
607
  value: function _init(args) {
462
- this.cache = Object.assign({}, args);
608
+ this._data = Object.assign({}, args);
463
609
  }
464
610
  }, {
465
611
  key: "set",
466
612
  value: function set(key, value) {
467
- this.cache[key] = value;
613
+ this._data[key] = value;
468
614
  }
469
615
  }, {
470
616
  key: "get",
471
617
  value: function get(key) {
472
- var _this$cache;
473
- return (_this$cache = this.cache) === null || _this$cache === void 0 ? void 0 : _this$cache[key];
618
+ var _this$_data;
619
+ return (_this$_data = this._data) === null || _this$_data === void 0 ? void 0 : _this$_data[key];
474
620
  }
475
621
  }, {
476
622
  key: "clear",
477
623
  value: function clear(key) {
478
- delete this.cache[key];
624
+ delete this._data[key];
479
625
  }
480
626
  }]);
481
627
  }();
@@ -490,13 +636,13 @@
490
636
  value: function _init(args) {
491
637
  var _args$__ASYNC_EXECUTE;
492
638
  this.__ASYNC_EXECUTE__ = (_args$__ASYNC_EXECUTE = args === null || args === void 0 ? void 0 : args.__ASYNC_EXECUTE__) !== null && _args$__ASYNC_EXECUTE !== void 0 ? _args$__ASYNC_EXECUTE : true;
493
- this.events = new Map();
494
- this.firstevents = new Map();
639
+ this._events = new Map();
640
+ this._firstevents = new Map();
495
641
  }
496
642
  }, {
497
643
  key: "on",
498
644
  value: function on(name, callback, context) {
499
- var fnList = this.events.get(name);
645
+ var fnList = this._events.get(name);
500
646
  if (!Array.isArray(fnList)) {
501
647
  fnList = [];
502
648
  }
@@ -504,12 +650,12 @@
504
650
  callback: callback,
505
651
  context: context
506
652
  });
507
- this.events.set(name, fnList);
653
+ this._events.set(name, fnList);
508
654
  }
509
655
  }, {
510
656
  key: "onFirst",
511
657
  value: function onFirst(name, callback, context) {
512
- var fnList = this.firstevents.get(name);
658
+ var fnList = this._firstevents.get(name);
513
659
  if (!Array.isArray(fnList)) {
514
660
  fnList = [];
515
661
  }
@@ -517,7 +663,7 @@
517
663
  callback: callback,
518
664
  context: context
519
665
  });
520
- this.firstevents.set(name, fnList);
666
+ this._firstevents.set(name, fnList);
521
667
  }
522
668
  }, {
523
669
  key: "execute",
@@ -525,8 +671,8 @@
525
671
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
526
672
  args[_key - 1] = arguments[_key];
527
673
  }
528
- var events = this.events.get(name);
529
- var firstevents = this.firstevents.get(name);
674
+ var events = this._events.get(name);
675
+ var firstevents = this._firstevents.get(name);
530
676
  if (!events && !firstevents) {
531
677
  return true;
532
678
  }
@@ -544,8 +690,8 @@
544
690
  }, {
545
691
  key: "un",
546
692
  value: function un(name, callback) {
547
- this._unEvents(name, callback, this.events);
548
- this._unEvents(name, callback, this.firstevents);
693
+ this._unEvents(name, callback, this._events);
694
+ this._unEvents(name, callback, this._firstevents);
549
695
  }
550
696
  }, {
551
697
  key: "_unEvents",
@@ -568,12 +714,12 @@
568
714
  }, {
569
715
  key: "hasEvent",
570
716
  value: function hasEvent(name) {
571
- var _this$events$get, _this$firstevents$get;
717
+ var _this$_events$get, _this$_firstevents$ge;
572
718
  if (!name) {
573
719
  return 0;
574
720
  }
575
- var eventsLen = ((_this$events$get = this.events.get(name)) === null || _this$events$get === void 0 ? void 0 : _this$events$get.length) || 0;
576
- var firsteventsLen = ((_this$firstevents$get = this.firstevents.get(name)) === null || _this$firstevents$get === void 0 ? void 0 : _this$firstevents$get.length) || 0;
721
+ var eventsLen = ((_this$_events$get = this._events.get(name)) === null || _this$_events$get === void 0 ? void 0 : _this$_events$get.length) || 0;
722
+ var firsteventsLen = ((_this$_firstevents$ge = this._firstevents.get(name)) === null || _this$_firstevents$ge === void 0 ? void 0 : _this$_firstevents$ge.length) || 0;
577
723
  return eventsLen + firsteventsLen;
578
724
  }
579
725
  }, {
@@ -666,8 +812,8 @@
666
812
  }, {
667
813
  key: "_asyncPromiseExecute",
668
814
  value: function _asyncPromiseExecute(name, resolve, reject, args) {
669
- var events = this.events.get(name);
670
- var firstevents = this.firstevents.get(name);
815
+ var events = this._events.get(name);
816
+ var firstevents = this._firstevents.get(name);
671
817
  if ((Array.isArray(events) ? !events.length : !events) && (Array.isArray(firstevents) ? !firstevents.length : !firstevents)) {
672
818
  return resolve === null || resolve === void 0 ? void 0 : resolve();
673
819
  }
@@ -726,9 +872,9 @@
726
872
  var returnData = this.execute.apply(this, args);
727
873
  if (returnData instanceof Promise) {
728
874
  var self = this;
729
- /**
730
- * 背景参考下面的else注释,当第二次命中这里的时候,会在promise执行的时候直接then了,因为没有重新走一遍判定,这里直接执行了callback
731
- * 解决方案:想着是想办法把then里的代码作为callback传进去最后在执行,但是没想到方案
875
+ /**
876
+ * 背景参考下面的else注释,当第二次命中这里的时候,会在promise执行的时候直接then了,因为没有重新走一遍判定,这里直接执行了callback
877
+ * 解决方案:想着是想办法把then里的代码作为callback传进去最后在执行,但是没想到方案
732
878
  */
733
879
  returnData.then(function () {
734
880
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
@@ -741,9 +887,9 @@
741
887
  }
742
888
  });
743
889
  } else {
744
- /*
745
- 这里是因为历史代码没有考虑promise得情况 导致直接使用!returnData做结果判定,但是undefined也会命中false 导致后续执行阻断,不做callback了,所以会有问题,加了下面代码还是有问题,因为如果命中了promise得话没有返回值
746
- 导致命中不了returnData === false 导致阻断,所以上面execute里promise的时候将整个results返回,但是加了还有另外的问题,就是如果有两个分开的promise 会导致第一次好使,第二次命中了上面的if
890
+ /*
891
+ 这里是因为历史代码没有考虑promise得情况 导致直接使用!returnData做结果判定,但是undefined也会命中false 导致后续执行阻断,不做callback了,所以会有问题,加了下面代码还是有问题,因为如果命中了promise得话没有返回值
892
+ 导致命中不了returnData === false 导致阻断,所以上面execute里promise的时候将整个results返回,但是加了还有另外的问题,就是如果有两个分开的promise 会导致第一次好使,第二次命中了上面的if
747
893
  */
748
894
  // if (window.__ASYNC_EXECUTE__ ? returnData === false : !returnData) {
749
895
  if (!returnData) {
@@ -808,102 +954,12 @@
808
954
  }, {
809
955
  key: "clearEvents",
810
956
  value: function clearEvents() {
811
- this.events.clear();
812
- this.firstevents.clear();
957
+ this._events.clear();
958
+ this._firstevents.clear();
813
959
  }
814
960
  }]);
815
961
  }();
816
962
 
817
- function QueryString(_url) {
818
- this.pathname = '';
819
- this.query = {};
820
- var url = _url;
821
- this.init = function () {
822
- if (!url) {
823
- url = location.search;
824
- }
825
- var index1 = url.indexOf('?');
826
- var index2 = url.indexOf('#');
827
- if (index1 >= 0) {
828
- this.pathname = url.substr(0, index1);
829
- url = index2 < 0 ? url.substr(index1 + 1) : url.substring(index1 + 1, index2);
830
- if (url.length > 0) {
831
- url = url.replace(/\+/g, ' ');
832
- var params = url.split('&');
833
- for (var i = 0, len = params.length; i < len; i++) {
834
- var param = params[i] || '';
835
- if (param) {
836
- var index = param.indexOf('=');
837
- var key = '';
838
- var value = '';
839
- if (index < 0) {
840
- key = window.decode(param);
841
- value = key;
842
- } else {
843
- key = window.decode(param.substr(0, index));
844
- value = window.decode(param.substr(index + 1));
845
- }
846
- this.query[key] = value;
847
- }
848
- }
849
- }
850
- } else {
851
- this.pathname = url;
852
- }
853
- };
854
- this.set = function (key, value) {
855
- this.query[key] = value;
856
- };
857
- this.get = function (key) {
858
- return this.query[key];
859
- };
860
- this.del = function (key) {
861
- delete this.query[key];
862
- };
863
- this.has = function (key) {
864
- return this.query[key] != null;
865
- };
866
- this.toStr = function () {
867
- var items = ['?'];
868
- for (var key in this.query) {
869
- items.push(encodeURIComponent(key));
870
- items.push('=');
871
- items.push(encodeURIComponent(this.query[key]));
872
- items.push('&');
873
- }
874
- if (items.length === 1) {
875
- return '';
876
- }
877
- items.splice(items.length - 1, 1);
878
- return items.join('');
879
- };
880
- this.init();
881
- }
882
- String.prototype['equalsIgnoreCase'] = function (str) {
883
- if (str == null) {
884
- return false;
885
- }
886
- return this.toLowerCase() === str.toLowerCase();
887
- };
888
- function _appendUrl(restUrl, params) {
889
- if (!params) {
890
- return restUrl;
891
- }
892
- var queryStr = [];
893
- var queryUrl = new QueryString(restUrl);
894
- for (var attr in params) {
895
- if (queryUrl.get(attr)) {
896
- continue;
897
- }
898
- queryStr.push("".concat(attr, "=").concat(params[attr]));
899
- }
900
- if (!queryStr.length) {
901
- return restUrl;
902
- }
903
- var queryString = queryStr.join('&');
904
- return restUrl.indexOf('?') >= 0 ? "".concat(restUrl, "&").concat(queryString) : "".concat(restUrl, "?").concat(queryString);
905
- }
906
-
907
963
  var _excluded = ["onBeforeRequest", "_onAfterRequest"],
908
964
  _excluded2 = ["_onBeforeRequest", "onAfterRequest"];
909
965
  function _getUrl(_url, params) {
@@ -1248,7 +1304,7 @@
1248
1304
  return ajax(url, options);
1249
1305
  };
1250
1306
 
1251
- var BaseModel = /*#__PURE__*/function () {
1307
+ var BaseModel$1 = /*#__PURE__*/function () {
1252
1308
  function BaseModel(args) {
1253
1309
  _classCallCheck(this, BaseModel);
1254
1310
  this._init(args);
@@ -1424,11 +1480,11 @@
1424
1480
  components.splice(index, 1);
1425
1481
  }
1426
1482
 
1427
- /**
1428
- * 统一的「写属性 + 通知组件」逻辑。
1429
- * 组件实现了 setXxx(如 setValue)就直接调;没实现则退回 setState({ [name]: value })。
1430
- * 原实现里只有 setVisible / setDisabled 有这层兜底,setValue 漏了,
1431
- * 导致模型改值永远传不到受控组件上。
1483
+ /**
1484
+ * 统一的「写属性 + 通知组件」逻辑。
1485
+ * 组件实现了 setXxx(如 setValue)就直接调;没实现则退回 setState({ [name]: value })。
1486
+ * 原实现里只有 setVisible / setDisabled 有这层兜底,setValue 漏了,
1487
+ * 导致模型改值永远传不到受控组件上。
1432
1488
  */
1433
1489
  }, {
1434
1490
  key: "_applyState",
@@ -1667,67 +1723,27 @@
1667
1723
  }]);
1668
1724
  }();
1669
1725
 
1670
- var FilterModel = /*#__PURE__*/function (_BaseModel) {
1671
- function FilterModel() {
1672
- _classCallCheck(this, FilterModel);
1673
- return _callSuper(this, FilterModel, arguments);
1726
+ var SimpleModel$1 = /*#__PURE__*/function (_BaseModel) {
1727
+ function SimpleModel() {
1728
+ var _this;
1729
+ _classCallCheck(this, SimpleModel);
1730
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1731
+ args[_key] = arguments[_key];
1732
+ }
1733
+ _this = _callSuper(this, SimpleModel, [].concat(args));
1734
+ _defineProperty(_this, "modelType", 'SimpleModel');
1735
+ return _this;
1674
1736
  }
1675
- _inherits(FilterModel, _BaseModel);
1676
- return _createClass(FilterModel, [{
1677
- key: "mounted",
1678
- value: function mounted() {
1679
- var _this = this;
1680
- var _conditions = this.get('conditions');
1681
- var params = {};
1682
- _conditions.forEach(function (r) {
1683
- _this.get(r.name);
1684
- params[r.name] = r.defaultValue;
1685
- });
1686
- this._set_data('params', params);
1737
+ _inherits(SimpleModel, _BaseModel);
1738
+ return _createClass(SimpleModel, [{
1739
+ key: "getDisabled",
1740
+ value: function getDisabled() {
1741
+ return this.getState('disabled');
1687
1742
  }
1688
1743
  }, {
1689
- key: "unmounted",
1690
- value: function unmounted() {
1691
- this._set_data('params', {});
1692
- this._set_data('conditions', []);
1693
- }
1694
- }, {
1695
- key: "getParams",
1696
- value: function getParams() {
1697
- var _this2 = this;
1698
- var params = {};
1699
- var conditions = this.get('conditions');
1700
- conditions.forEach(function (r) {
1701
- var model = _this2.get(r.name);
1702
- params[r.name] = model === null || model === void 0 ? void 0 : model.getValue();
1703
- });
1704
- this._set_data('params', params);
1705
- return params;
1706
- }
1707
- }, {
1708
- key: "search",
1709
- value: function search() {
1710
- var params = this.getParams();
1711
- this.execute('search', params);
1712
- }
1713
- }]);
1714
- }(BaseModel);
1715
-
1716
- var SimpleModel = /*#__PURE__*/function (_BaseModel) {
1717
- function SimpleModel(args) {
1718
- _classCallCheck(this, SimpleModel);
1719
- return _callSuper(this, SimpleModel, [args]);
1720
- }
1721
- _inherits(SimpleModel, _BaseModel);
1722
- return _createClass(SimpleModel, [{
1723
- key: "getDisabled",
1724
- value: function getDisabled() {
1725
- return this.getState('disabled');
1726
- }
1727
- }, {
1728
- key: "setDisabled",
1729
- value: function setDisabled(v) {
1730
- return this.setState('disabled', !!v);
1744
+ key: "setDisabled",
1745
+ value: function setDisabled(value, ctrlName) {
1746
+ this._applyState('disabled', value, ctrlName);
1731
1747
  }
1732
1748
  }, {
1733
1749
  key: "getReadonly",
@@ -1736,36 +1752,14 @@
1736
1752
  }
1737
1753
  }, {
1738
1754
  key: "setReadonly",
1739
- value: function setReadonly(v) {
1740
- this.setState('readonly', !!v);
1755
+ value: function setReadonly(value, ctrlName) {
1756
+ this._applyState('readonly', value, ctrlName);
1741
1757
  }
1742
1758
  }]);
1743
- }(BaseModel);
1759
+ }(BaseModel$1);
1744
1760
 
1745
- var DataStates = {
1746
- Unchanged: '',
1747
- Insert: 'Insert',
1748
- Update: 'Update',
1749
- Delete: 'Delete'
1750
- };
1751
1761
  var DEFAULT_PAGE_SIZE = 20;
1752
1762
  var isArray = Array.isArray;
1753
- var isEmpty = function isEmpty(value) {
1754
- return value === undefined || value === null || value === '';
1755
- };
1756
- var isEmptyObject = function isEmptyObject(value) {
1757
- return !value || Object.keys(value).length === 0;
1758
- };
1759
- function cloneDeep(value) {
1760
- if (isArray(value)) return value.map(cloneDeep);
1761
- if (value instanceof Date) return new Date(value.getTime());
1762
- if (value && _typeof(value) === 'object') {
1763
- var result = {};
1764
- for (var key in value) result[key] = cloneDeep(value[key]);
1765
- return result;
1766
- }
1767
- return value;
1768
- }
1769
1763
 
1770
1764
  // ---------------- 列:数组 ↔ object map 归一 ----------------
1771
1765
 
@@ -1783,12 +1777,10 @@
1783
1777
  });
1784
1778
  list.forEach(function (column, index) {
1785
1779
  if (!column) return;
1786
- var field = column.field || column.cCaption || column.cFieldName || "col_".concat(index);
1780
+ var field = column.field || column.cFieldName || column.cName || "col_".concat(index);
1787
1781
  map[field] = _objectSpread2(_objectSpread2({}, column), {}, {
1788
1782
  field: field,
1789
- // 中台里列有 fieldName / cCaption 两套命名,这里都兜住
1790
- fieldName: column.fieldName || field,
1791
- cCaption: column.cCaption || field,
1783
+ label: column.label || column.title || column.cCaption || field,
1792
1784
  index: column.index === undefined ? index : column.index
1793
1785
  });
1794
1786
  });
@@ -1810,29 +1802,17 @@
1810
1802
  return [];
1811
1803
  }
1812
1804
 
1813
- /** 给行补内部 id(没有主键时用 rowId_ 前缀,与中台一致) */
1814
- function setIds() {
1815
- var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1816
- var idFlag = this.getIdFlag();
1817
- var keyField = this.getRowKeyField();
1818
- var seq = this._get_data('rowIdSeq') || 0;
1819
- rows.forEach(function (row) {
1820
- if (!row || row[idFlag] !== undefined) return;
1821
- var key = row[keyField];
1822
- if (key !== undefined && key !== null && key !== '') {
1823
- row[idFlag] = String(key);
1824
- } else {
1825
- seq += 1;
1826
- row[idFlag] = "rowId_".concat(seq);
1827
- }
1828
- });
1829
- this._set_data('rowIdSeq', seq);
1830
- return rows;
1831
- }
1832
-
1833
1805
  // ---------------- 初始状态 ----------------
1834
1806
 
1835
1807
  function createDefaultProps() {
1808
+ var innerUsedAttrs = {
1809
+ id: '_id',
1810
+ selected: '_selected',
1811
+ status: '_status',
1812
+ pageIndex: 'pageNo',
1813
+ pageSize: 'pageSize',
1814
+ pageCount: 'total'
1815
+ };
1836
1816
  return {
1837
1817
  columns: {},
1838
1818
  dataSource: [],
@@ -1841,23 +1821,16 @@
1841
1821
  dataSourceMode: 'local',
1842
1822
  columnMode: 'local',
1843
1823
  editMode: 'cell',
1824
+ rowKeyField: 'id',
1844
1825
  cellState: {},
1845
1826
  rowState: {},
1846
- showCheckBox: true,
1827
+ showCheckBox: false,
1847
1828
  multiple: true,
1848
1829
  showRowNo: true,
1849
1830
  // 默认显示序号
1850
1831
  pagination: true,
1851
- pageInfo: {
1852
- pageIndex: 1,
1853
- pageSize: DEFAULT_PAGE_SIZE,
1854
- pageCount: 0
1855
- },
1856
- innerUsedAttrs: {
1857
- id: '_id',
1858
- selected: '_selected',
1859
- status: '_status'
1860
- },
1832
+ pageInfo: _defineProperty(_defineProperty(_defineProperty({}, innerUsedAttrs.pageIndex, 1), innerUsedAttrs.pageSize, DEFAULT_PAGE_SIZE), innerUsedAttrs.pageCount, 0),
1833
+ innerUsedAttrs: innerUsedAttrs,
1861
1834
  multiRowModel: false,
1862
1835
  // 表格多行模型
1863
1836
  editRowModels: {},
@@ -1869,19 +1842,9 @@
1869
1842
  defaultRowDatas: new Map()
1870
1843
  };
1871
1844
  }
1872
-
1873
- /**
1874
- * 取数配置:中台叫 proxyConfig({ load: fn|url }),这里兼容三种写法
1875
- * - `proxyConfig: { load }`
1876
- * - `dataSource: fn`(旧写法)
1877
- * - `cUrl: '/xxx'`
1878
- */
1879
1845
  function resolveProxyConfig() {
1880
1846
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1881
1847
  var proxy = _objectSpread2({}, props.proxyConfig || {});
1882
- if (typeof props.dataSource === 'function') proxy.load = proxy.load || props.dataSource;
1883
- if (typeof props.cUrl === 'string') proxy.load = proxy.load || props.cUrl;
1884
- if (!proxy.load && typeof props.url === 'string') proxy.load = props.url;
1885
1848
  return proxy;
1886
1849
  }
1887
1850
  function _getData(proxyConfig, queryParams, callback) {
@@ -1894,16 +1857,16 @@
1894
1857
  var proxy = _this.setProxy({
1895
1858
  queryData: proxyConfig
1896
1859
  });
1897
- var defaultParams = {
1898
- page: {
1899
- pageSize: _this.getPageSize(),
1900
- pageIndex: _this.getPageIndex()
1901
- }
1860
+ var pageIndexField = _this._get_data('innerUsedAttrs').pageIndex;
1861
+ var pageSizeField = _this._get_data('innerUsedAttrs').pageSize;
1862
+ var currentPageInfo = {
1863
+ page: _defineProperty(_defineProperty({}, pageSizeField, _this.getPageSize()), pageIndexField, _this.getPageIndex())
1902
1864
  };
1903
- var params = Object.assign(defaultParams, queryParams);
1865
+ var params = Object.assign(queryParams, currentPageInfo);
1904
1866
  _this.setCache('proxyCache', {
1905
1867
  proxyConfig: proxyConfig,
1906
- params: params
1868
+ params: params,
1869
+ callback: callback
1907
1870
  });
1908
1871
  _this.getRootParent();
1909
1872
  var queryDataCallback = function queryDataCallback(err, result, callBackMsg, errorDetail) {
@@ -1913,6 +1876,7 @@
1913
1876
  this._set_data('dataSourceMode', 'remote'); // 处理请求过程中被修改
1914
1877
  result = Object.assign({}, result);
1915
1878
  var data = resolveRowsData(result);
1879
+ this.execute('afterQueryData', result);
1916
1880
  callback === null || callback === void 0 || callback.call(this, data);
1917
1881
  };
1918
1882
  if (_this.execute('beforeQueryData', params) === false) return;
@@ -1922,7 +1886,7 @@
1922
1886
  }
1923
1887
  function _setData(data) {
1924
1888
  if (!this.execute('beforeSetDataSource', data)) return;
1925
- var rowKeyField = this._get_data('rowKeyField');
1889
+ var rowKeyField = this.getRowKeyField();
1926
1890
  var keyMap = {};
1927
1891
  data.forEach(function (item) {
1928
1892
  keyMap[item[rowKeyField]] = item;
@@ -1935,37 +1899,35 @@
1935
1899
 
1936
1900
  // ============================================================
1937
1901
 
1938
- var GridModel = /*#__PURE__*/function (_BaseModel) {
1902
+ var GridModel$1 = /*#__PURE__*/function (_BaseModel) {
1939
1903
  function GridModel() {
1940
1904
  var _this2;
1941
1905
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1942
1906
  _classCallCheck(this, GridModel);
1943
1907
  var data = _objectSpread2(_objectSpread2({}, createDefaultProps()), props);
1944
1908
  // `dataSource: fn` 是旧写法,含义是「取数函数」而不是「数据」,这里统一收敛掉
1945
- if (!isArray(data.dataSource)) data.dataSource = [];
1946
- if (!isArray(data.rows)) data.rows = [];
1909
+ if (!isArray(data.dataSource)) {
1910
+ data.dataSource = [];
1911
+ }
1912
+ if (!isArray(data.rows)) {
1913
+ data.rows = [];
1914
+ }
1947
1915
  var proxyConfig = resolveProxyConfig(props);
1948
1916
  data.proxyConfig = proxyConfig;
1949
1917
  // 有取数配置就是服务端分页,否则按静态数据在前端分页
1950
- data.dataSourceMode = props.dataSourceMode || (proxyConfig.load ? 'remote' : 'local');
1951
- // 静态数据:cData / data 数组
1952
- var seed = props.cData || (isArray(props.data) ? props.data : null);
1918
+ data.dataSourceMode = props.dataSourceMode || data.dataSourceMode;
1953
1919
  _this2 = _callSuper(this, GridModel, [data]);
1954
1920
  _defineProperty(_this2, "modelType", 'GridModel');
1955
- _this2.initPageInfo(props.cPage || props.page);
1956
1921
  _this2.initColumns(data.columns);
1957
- _this2.initRowState();
1922
+ _this2.initPageInfo(props.cPage || props.page);
1958
1923
  _this2.afterInit();
1959
- if (seed) _this2.setDataSource(seed);
1960
1924
  return _this2;
1961
1925
  }
1962
-
1963
- // 中台在 afterInit 里做主子表/行模型初始化,我们这里只留一个扩展点给业务继承
1964
1926
  _inherits(GridModel, _BaseModel);
1965
1927
  return _createClass(GridModel, [{
1966
1928
  key: "afterInit",
1967
1929
  value: function afterInit() {
1968
- if (this._get_data('parentRelation') === 'single') this._set_data('defaultSelectedRowIndexes', true);
1930
+ this.execute('afterInit');
1969
1931
  }
1970
1932
  }, {
1971
1933
  key: "initColumns",
@@ -1979,65 +1941,25 @@
1979
1941
  value: function initPageInfo() {
1980
1942
  var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1981
1943
  var pageInfo = _objectSpread2({}, this.getPageInfo());
1982
- pageInfo.pageIndex = page.pageNo || page.pageIndex || pageInfo.pageIndex || 1;
1983
- pageInfo.pageSize = page.pageSize || pageInfo.pageSize || DEFAULT_PAGE_SIZE;
1984
- // 中台习惯:不分页时把 pageSize 记成 -1
1985
- if (this.get('pagination') === false) pageInfo.pageSize = -1;
1986
- this.applyPageInfo(pageInfo);
1987
- }
1988
-
1989
- // 与 dataSource 同序的行状态,先铺平
1990
- }, {
1991
- key: "initRowState",
1992
- value: function initRowState() {
1993
- var _this3 = this;
1994
- var source = this._get_data('dataSource');
1995
- this._set_data('rowsDataState', (isArray(source) ? source : []).map(function (row) {
1996
- return (row === null || row === void 0 ? void 0 : row[_this3.getStatusFlag()]) || DataStates.Unchanged;
1997
- }), true);
1944
+ var pageIndexField = this._get_data('innerUsedAttrs').pageIndex;
1945
+ var pageSizeField = this._get_data('innerUsedAttrs').pageSize;
1946
+ pageInfo[pageIndexField] = page.pageNo || page.pageIndex || pageInfo.pageIndex || 1;
1947
+ pageInfo[pageSizeField] = page.pageSize || pageInfo.pageSize || DEFAULT_PAGE_SIZE;
1948
+ if (this.get('pagination') === false) pageInfo[pageIndexField] = -1;
1949
+ this._set_data('pageInfo', pageInfo);
1998
1950
  }
1999
1951
 
2000
1952
  /* ========================= 内部字段 / 开关 ========================= */
2001
- }, {
2002
- key: "getInnerUsedAttrs",
2003
- value: function getInnerUsedAttrs() {
2004
- return this._get_data('innerUsedAttrs');
2005
- }
2006
- }, {
2007
- key: "getIdFlag",
2008
- value: function getIdFlag() {
2009
- return this.getInnerUsedAttrs().id;
2010
- }
2011
- }, {
2012
- key: "getSelectedFlag",
2013
- value: function getSelectedFlag() {
2014
- return this.getInnerUsedAttrs().selected;
2015
- }
2016
- }, {
2017
- key: "getStatusFlag",
2018
- value: function getStatusFlag() {
2019
- return this.getInnerUsedAttrs().status;
2020
- }
2021
1953
  }, {
2022
1954
  key: "getRowKeyField",
2023
1955
  value: function getRowKeyField() {
2024
1956
  return this._get_data('rowKeyField') || 'id';
2025
1957
  }
2026
- }, {
2027
- key: "getProxyConfig",
2028
- value: function getProxyConfig() {
2029
- return this._get_data('proxyConfig') || {};
2030
- }
2031
1958
  }, {
2032
1959
  key: "isRemote",
2033
1960
  value: function isRemote() {
2034
1961
  return this._get_data('dataSourceMode') === 'remote';
2035
1962
  }
2036
- }, {
2037
- key: "isPagination",
2038
- value: function isPagination() {
2039
- return !!this.get('pagination') && this.getPageSize() !== -1;
2040
- }
2041
1963
  }, {
2042
1964
  key: "getReadOnly",
2043
1965
  value: function getReadOnly() {
@@ -2048,6 +1970,20 @@
2048
1970
  value: function setReadOnly(readOnly) {
2049
1971
  this._applyState('readOnly', !!readOnly);
2050
1972
  }
1973
+ }, {
1974
+ key: "setShowCheckbox",
1975
+ value: function setShowCheckbox(value) {
1976
+ this._applyState('showCheckBox', !!value);
1977
+ // this._set_data('showCheckBox', value)
1978
+ // this.doPropertyChange('setShowCheckbox', value)
1979
+ }
1980
+ }, {
1981
+ key: "setShowRowNo",
1982
+ value: function setShowRowNo(value) {
1983
+ this._applyState('showRowNo', !!value);
1984
+ // this._set_data('showRowNo', value)
1985
+ // this.doPropertyChange('setShowRowNo', value)
1986
+ }
2051
1987
  }, {
2052
1988
  key: "getParams",
2053
1989
  value: function getParams() {
@@ -2059,118 +1995,21 @@
2059
1995
  this._set_data('params', params || {});
2060
1996
  }
2061
1997
  }, {
2062
- key: "setMeta",
2063
- value: function setMeta(meta) {
2064
- this._set_data('meta', meta);
2065
- }
2066
-
2067
- /* ============================= 列 ============================= */
2068
-
2069
- /** 与中台一致:返回 object map(深拷贝),而不是数组 */
2070
- }, {
2071
- key: "getColumns",
2072
- value: function getColumns(fields) {
2073
- var columns = this._get_data('columns') || {};
2074
- var result = {};
2075
- var keys = fields ? isArray(fields) ? fields : [fields] : Object.getOwnPropertyNames(columns);
2076
- keys.forEach(function (key) {
2077
- if (!columns[key]) return;
2078
- result[key] = _objectSpread2(_objectSpread2({}, columns[key]), {}, {
2079
- fieldName: columns[key].fieldName || key
2080
- });
2081
- });
2082
- return result;
2083
- }
2084
- }, {
2085
- key: "getColumn",
2086
- value: function getColumn(field) {
2087
- var _this$_get_data;
2088
- var column = (_this$_get_data = this._get_data('columns')) === null || _this$_get_data === void 0 ? void 0 : _this$_get_data[field];
2089
- return column ? _objectSpread2(_objectSpread2({}, column), {}, {
2090
- fieldName: column.fieldName || field
2091
- }) : undefined;
2092
- }
2093
- }, {
2094
- key: "hasColumn",
2095
- value: function hasColumn(field) {
2096
- return !!(this._get_data('columns') || {})[field];
2097
- }
2098
- }, {
2099
- key: "getColumnList",
2100
- value: function getColumnList(fields) {
2101
- var columns = this.getColumns(fields);
2102
- return Object.keys(columns).sort(function (a, b) {
2103
- return (columns[a].index || 0) - (columns[b].index || 0);
2104
- }).map(function (key) {
2105
- return columns[key];
2106
- });
2107
- }
2108
- }, {
2109
- key: "getVisibleColumns",
2110
- value: function getVisibleColumns(fields) {
2111
- return this.getColumnList(fields).filter(function (column) {
2112
- return column.bHidden !== true && column.bShowIt !== false;
2113
- });
2114
- }
2115
- }, {
2116
- key: "setColumns",
2117
- value: function setColumns(columns) {
2118
- if (!columns) return;
2119
- this._applyState('columns', normalizeColumns(columns));
2120
- }
2121
- }, {
2122
- key: "setColumnMode",
2123
- value: function setColumnMode(mode) {
2124
- this._set_data('columnMode', mode === 'remote' ? 'remote' : 'local', true);
2125
- }
2126
- }, {
2127
- key: "addColumns",
2128
- value: function addColumns(columns) {
2129
- var map = normalizeColumns(columns);
2130
- this._applyState('columns', _objectSpread2(_objectSpread2({}, this._get_data('columns') || {}), map));
2131
- }
2132
- }, {
2133
- key: "resetColumns",
2134
- value: function resetColumns(columns) {
2135
- this.setColumns(columns || this.get('cColumns'));
2136
- }
2137
- }, {
2138
- key: "getColumnState",
2139
- value: function getColumnState(rowIndex, field, name) {
2140
- var _this$_get_data2;
2141
- var rowKey = this.getRowKey(rowIndex);
2142
- return rowKey ? (((_this$_get_data2 = this._get_data('cellState')) === null || _this$_get_data2 === void 0 || (_this$_get_data2 = _this$_get_data2[rowKey]) === null || _this$_get_data2 === void 0 ? void 0 : _this$_get_data2[field]) || {})[name] : undefined;
2143
- }
2144
- }, {
2145
- key: "setColumnState",
2146
- value: function setColumnState(rowIndex, field, name, value) {
2147
- this.setCellState(rowIndex, field, name, value);
2148
- }
2149
- }, {
2150
- key: "setColumnStates",
2151
- value: function setColumnStates() {
2152
- var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2153
- this.setCellStates(states.map(function (item) {
2154
- return _objectSpread2(_objectSpread2({}, item), {}, {
2155
- cellName: item.cellName || item.columnName
2156
- });
2157
- }));
1998
+ key: "getInnerUsedAttrs",
1999
+ value: function getInnerUsedAttrs() {
2000
+ return this._get_data('innerUsedAttrs');
2158
2001
  }
2159
2002
  }, {
2160
- key: "setColumnValue",
2161
- value: function setColumnValue(field, name, value) {
2162
- var columns = this._get_data('columns') || {};
2163
- if (!columns[field]) return;
2164
- this._applyState('columns', _objectSpread2(_objectSpread2({}, columns), {}, _defineProperty({}, field, _objectSpread2(_objectSpread2({}, columns[field]), {}, _defineProperty({}, name, value)))));
2003
+ key: "get",
2004
+ value: function get() {
2005
+ return this.getInnerUsedAttrs().id;
2165
2006
  }
2166
2007
 
2167
- /* ============================ 取数 ============================ */
2168
-
2169
2008
  /* ======================= 数据写入 ======================= */
2170
2009
  }, {
2171
2010
  key: "setDataSource",
2172
2011
  value: function setDataSource(proxyConfig) {
2173
- var _this4 = this;
2012
+ var _this3 = this;
2174
2013
  var queryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2175
2014
  var callback = arguments.length > 2 ? arguments[2] : undefined;
2176
2015
  if (this._get_data('dataSourceMode') === 'local') {
@@ -2178,28 +2017,27 @@
2178
2017
  _setData(data);
2179
2018
  } else {
2180
2019
  if (!this.execute('beforeProxyLoad', queryParams)) return;
2181
- var pageInfo = this._get_data('pageInfo');
2182
- pageInfo.pageIndex = 1;
2183
- this._set_data('proxyConfig', proxyConfig);
2184
- this._set_data('queryParams', queryParams);
2185
- this._set_data('loadDataCallback', callback);
2020
+ this.setPageIndex(1);
2186
2021
  _getData.call(this, proxyConfig, queryParams, function (data) {
2187
- _setData.call(_this4, data);
2188
- callback === null || callback === void 0 || callback.call(_this4);
2022
+ _setData.call(_this3, data);
2023
+ callback === null || callback === void 0 || callback.call(_this3);
2189
2024
  });
2190
2025
  }
2191
2026
  }
2192
2027
  }, {
2193
2028
  key: "reload",
2194
2029
  value: function reload() {
2195
- var _this5 = this;
2196
- this.getProxy();
2197
- var proxyConfig = this._get_data('proxyConfig');
2198
- var queryParams = this._get_data('queryParams');
2199
- var callback = this._get_data('loadDataCallback');
2030
+ var _this4 = this;
2031
+ var proxyCache = this.getCache('proxyCache');
2032
+ if (!proxyCache) {
2033
+ console.log('[GridModel] proxyConfig is null');
2034
+ return;
2035
+ }
2036
+ var proxyConfig = proxyCache.proxyConfig,
2037
+ queryParams = proxyCache.params,
2038
+ callback = proxyCache.callback;
2200
2039
  _getData.call(this, proxyConfig, queryParams, function (data) {
2201
- _setData.call(_this5, data);
2202
- callback === null || callback === void 0 || callback.call(_this5);
2040
+ callback === null || callback === void 0 || callback.call(_this4, data);
2203
2041
  });
2204
2042
  }
2205
2043
 
@@ -2222,763 +2060,18 @@
2222
2060
  key: "getData",
2223
2061
  value: function getData(view, realRows) {
2224
2062
  var rows = view || realRows ? this._get_data('rows') : this._get_data('dataSource');
2225
- return this.collectRows(rows, view);
2063
+ return rows;
2226
2064
  }
2227
2065
  }, {
2228
2066
  key: "getAllData",
2229
2067
  value: function getAllData() {
2230
2068
  return this.getData(true);
2231
2069
  }
2232
- }, {
2233
- key: "getPageData",
2234
- value: function getPageData() {
2235
- return this.getData(true);
2236
- }
2237
-
2238
- /** 有效数据:全量里剔除 Delete 状态的行 */
2239
- }, {
2240
- key: "getEffeData",
2241
- value: function getEffeData() {
2242
- var source = this._get_data('dataSource') || [];
2243
- var rowsDataState = this._get_data('rowsDataState') || [];
2244
- return this.collectRows(source.filter(function (row, index) {
2245
- return rowsDataState[index] !== DataStates.Delete;
2246
- }), false);
2247
- }
2248
-
2249
- /** 当前页行(浅引用),isCopy=true 时返回深拷贝 */
2250
- }, {
2251
- key: "getRows",
2252
- value: function getRows(isCopy) {
2253
- var rows = this._get_data('rows') || [];
2254
- return isCopy === false ? rows : rows.map(function (row) {
2255
- return cloneDeep(row);
2256
- });
2257
- }
2258
- }, {
2259
- key: "collectRows",
2260
- value: function collectRows(rows, view) {
2261
- var columns = this._get_data('columns') || {};
2262
- var statusFlag = this.getStatusFlag();
2263
- var selectedFlag = this.getSelectedFlag();
2264
- return (rows || []).map(function (rowData) {
2265
- var row = {};
2266
- for (var attr in rowData) {
2267
- var _columns$attr;
2268
- // 视图数据不带 _status;提交数据不带 _selected
2269
- if (view && attr === statusFlag) continue;
2270
- if (!view && attr === selectedFlag) continue;
2271
- if (((_columns$attr = columns[attr]) === null || _columns$attr === void 0 ? void 0 : _columns$attr.needCollect) === false) continue;
2272
- row[attr] = rowData[attr];
2273
- }
2274
- return row;
2275
- });
2276
- }
2277
-
2278
- /** 展示文案副本(中台会把它推给组件;我们只作为工具方法保留) */
2279
- }, {
2280
- key: "getShowRows",
2281
- value: function getShowRows(rows) {
2282
- return (rows || this._get_data('rows') || []).map(function (row) {
2283
- return _objectSpread2({}, row);
2284
- });
2285
- }
2286
- }, {
2287
- key: "getRow",
2288
- value: function getRow(rowIndex, needGrandSon) {
2289
- var _this$_get_data3;
2290
- var row = (_this$_get_data3 = this._get_data('rows')) === null || _this$_get_data3 === void 0 ? void 0 : _this$_get_data3[rowIndex];
2291
- if (!row) return undefined;
2292
- return needGrandSon === false ? row : cloneDeep(row);
2293
- }
2294
- }, {
2295
- key: "getRowIndex",
2296
- value: function getRowIndex(row) {
2297
- if (!row) return -1;
2298
- var rows = this._get_data('rows') || [];
2299
- var rowKeyField = this.getRowKeyField();
2300
- if (row[rowKeyField] !== undefined) {
2301
- return rows.findIndex(function (item) {
2302
- return item[rowKeyField] === row[rowKeyField];
2303
- });
2304
- }
2305
- return rows.indexOf(row);
2306
- }
2307
- }, {
2308
- key: "getRowIndexByRowId",
2309
- value: function getRowIndexByRowId(rowId) {
2310
- var _this6 = this;
2311
- var rows = this._get_data('rows') || [];
2312
- return rows.findIndex(function (row) {
2313
- return (row === null || row === void 0 ? void 0 : row[_this6.getIdFlag()]) === rowId;
2314
- });
2315
- }
2316
- }, {
2317
- key: "getDataSourceIndexByRowId",
2318
- value: function getDataSourceIndexByRowId(rowId) {
2319
- var _this7 = this;
2320
- return (this._get_data('dataSource') || []).findIndex(function (row) {
2321
- return (row === null || row === void 0 ? void 0 : row[_this7.getIdFlag()]) === rowId;
2322
- });
2323
- }
2324
- }, {
2325
- key: "getRowKey",
2326
- value: function getRowKey(rowIndex) {
2327
- var _this$_get_data$rowIn, _this$_get_data4;
2328
- return (_this$_get_data$rowIn = (_this$_get_data4 = this._get_data('rows')) === null || _this$_get_data4 === void 0 || (_this$_get_data4 = _this$_get_data4[rowIndex]) === null || _this$_get_data4 === void 0 ? void 0 : _this$_get_data4[this.getIdFlag()]) !== null && _this$_get_data$rowIn !== void 0 ? _this$_get_data$rowIn : rowIndex;
2329
- }
2330
- }, {
2331
- key: "getRowKeys",
2332
- value: function getRowKeys(rowData) {
2333
- var list = rowData === undefined ? this.getRows() : isArray(rowData) ? rowData : [rowData];
2334
- var keyField = this.getRowKeyField();
2335
- return list.filter(function (row) {
2336
- return row && row[keyField] !== undefined;
2337
- }).map(function (row) {
2338
- return row[keyField];
2339
- });
2340
- }
2341
- }, {
2342
- key: "getRowsByIndexes",
2343
- value: function getRowsByIndexes(rowIndexes) {
2344
- var rows = this._get_data('rows') || [];
2345
- return (isArray(rowIndexes) ? rowIndexes : [rowIndexes]).map(function (index) {
2346
- return rows[index];
2347
- }).filter(Boolean);
2348
- }
2349
-
2350
- /* ==================== 单元格值 / 单元格状态 ==================== */
2351
- }, {
2352
- key: "getCellValue",
2353
- value: function getCellValue(rowIndex, cellName) {
2354
- var _this$_get_data5;
2355
- var row = rowIndex >= 0 ? (_this$_get_data5 = this._get_data('rows')) === null || _this$_get_data5 === void 0 ? void 0 : _this$_get_data5[rowIndex] : null;
2356
- if (!row || !cellName) return undefined;
2357
- return row[cellName];
2358
- }
2359
- }, {
2360
- key: "setCellValue",
2361
- value: function setCellValue(rowIndex, cellName, value) {
2362
- var rows = this._get_data('rows') || [];
2363
- var row = rows[rowIndex];
2364
- if (!row || !cellName) return;
2365
- var oldValue = row[cellName];
2366
- if (oldValue === value) return;
2367
- var data = {
2368
- rowIndex: rowIndex,
2369
- rowId: row[this.getIdFlag()],
2370
- cellName: cellName,
2371
- value: value,
2372
- oldValue: oldValue
2373
- };
2374
- if (!this.execute('beforeCellValueChange', data)) return;
2375
- row[cellName] = data.value;
2376
- this.markRowState(rowIndex, DataStates.Update);
2377
- this.execute('afterCellValueChange', data);
2378
- this.doPropertyChange('setCellValue', data);
2379
- }
2380
- }, {
2381
- key: "setCellValues",
2382
- value: function setCellValues() {
2383
- var _this8 = this;
2384
- var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2385
- if (!isArray(values)) return;
2386
- values.forEach(function (item) {
2387
- return _this8.setCellValue(item.rowIndex, item.cellName || item.field, item.value);
2388
- });
2389
- }
2390
- }, {
2391
- key: "getCellState",
2392
- value: function getCellState(rowIndex, cellName, name) {
2393
- var _this$_get_data6;
2394
- var rowKey = this.getRowKey(rowIndex);
2395
- var cell = rowKey ? (_this$_get_data6 = this._get_data('cellState')) === null || _this$_get_data6 === void 0 || (_this$_get_data6 = _this$_get_data6[rowKey]) === null || _this$_get_data6 === void 0 ? void 0 : _this$_get_data6[cellName] : null;
2396
- if (!cell) return undefined;
2397
- return cell[name];
2398
- }
2399
- }, {
2400
- key: "setCellState",
2401
- value: function setCellState(rowIndex, cellName, name, value) {
2402
- var _this$_get_data7;
2403
- var rowId = (_this$_get_data7 = this._get_data('rows')) === null || _this$_get_data7 === void 0 || (_this$_get_data7 = _this$_get_data7[rowIndex]) === null || _this$_get_data7 === void 0 ? void 0 : _this$_get_data7[this.getIdFlag()];
2404
- var rowKey = rowId || rowIndex;
2405
- if (isEmpty(rowKey)) return;
2406
- var oldValue = this.getCellState(rowIndex, cellName, name);
2407
- if (oldValue === value) return;
2408
- var data = {
2409
- rowIndex: rowIndex,
2410
- rowId: rowId,
2411
- cellName: cellName,
2412
- propertyName: name,
2413
- value: value,
2414
- oldValue: oldValue
2415
- };
2416
- if (!this.execute('beforeCellStateChange', data)) return;
2417
- var cellState = _objectSpread2({}, this._get_data('cellState') || {});
2418
- cellState[rowKey] = _objectSpread2({}, cellState[rowKey] || {});
2419
- cellState[rowKey][cellName] = _objectSpread2(_objectSpread2({}, cellState[rowKey][cellName] || {}), {}, _defineProperty({}, name, value));
2420
- this._applyState('cellState', cellState);
2421
- this.execute('afterCellStateChange', data);
2422
- }
2423
- }, {
2424
- key: "setCellStates",
2425
- value: function setCellStates() {
2426
- var _this9 = this;
2427
- var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2428
- if (!isArray(states)) return;
2429
- states.forEach(function (item) {
2430
- return _this9.setCellState(item.rowIndex, item.cellName, item.propertyName || item.name, item.value);
2431
- });
2432
- }
2433
-
2434
- /* ==================== 行状态 / 脏数据 ==================== */
2435
-
2436
- /** 行数据状态(Insert / Update / Delete / 空),rowIndex 是 rows 的下标 */
2437
- }, {
2438
- key: "getRowDataState",
2439
- value: function getRowDataState(rowIndex) {
2440
- var _this$_get_data8;
2441
- var indexInDS = this.getDataSourceIndexByRow(rowIndex);
2442
- return (_this$_get_data8 = this._get_data('rowsDataState')) === null || _this$_get_data8 === void 0 ? void 0 : _this$_get_data8[indexInDS];
2443
- }
2444
- }, {
2445
- key: "getDataSourceIndexByRow",
2446
- value: function getDataSourceIndexByRow(rowIndex) {
2447
- var _this0 = this;
2448
- var rows = this._get_data('rows') || [];
2449
- var row = rows[rowIndex];
2450
- if (!row) return -1;
2451
- var source = this._get_data('dataSource') || [];
2452
- var index = source.indexOf(row);
2453
- if (index > -1) return index;
2454
- // 本地分页时 rows 是切片,引用一致;远程模式下 rows 与 dataSource 同源
2455
- return source.findIndex(function (item) {
2456
- return (item === null || item === void 0 ? void 0 : item[_this0.getIdFlag()]) === (row === null || row === void 0 ? void 0 : row[_this0.getIdFlag()]);
2457
- });
2458
- }
2459
- }, {
2460
- key: "setRowDataState",
2461
- value: function setRowDataState(rowIndex, dataState) {
2462
- var indexInDS = this.getDataSourceIndexByRow(rowIndex);
2463
- if (indexInDS < 0) return;
2464
- var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2465
- rowsDataState[indexInDS] = dataState;
2466
- this._set_data('rowsDataState', rowsDataState, true);
2467
- }
2468
-
2469
- // 只在「原状态是 Unchanged」时置为 Update,避免把 Insert 覆盖成 Update
2470
- }, {
2471
- key: "markRowState",
2472
- value: function markRowState(rowIndex, dataState) {
2473
- var current = this.getRowDataState(rowIndex);
2474
- if (current === DataStates.Insert || current === dataState) return;
2475
- this.setRowDataState(rowIndex, dataState);
2476
- }
2477
-
2478
- /** 单元格编辑由组件回灌时用:传行对象或行下标都可以 */
2479
- }, {
2480
- key: "markRowUpdate",
2481
- value: function markRowUpdate(rowOrIndex) {
2482
- var rowIndex = typeof rowOrIndex === 'number' ? rowOrIndex : this.getRowIndex(rowOrIndex);
2483
- if (rowIndex < 0) return;
2484
- this.markRowState(rowIndex, DataStates.Update);
2485
- }
2486
- }, {
2487
- key: "getRowState",
2488
- value: function getRowState(rowIndex, name) {
2489
- var _this$_get_data9;
2490
- var rowKey = this.getRowKey(rowIndex);
2491
- var row = rowKey ? (_this$_get_data9 = this._get_data('rowState')) === null || _this$_get_data9 === void 0 ? void 0 : _this$_get_data9[rowKey] : null;
2492
- if (!row || !name) return undefined;
2493
- return row[name];
2494
- }
2495
- }, {
2496
- key: "setRowState",
2497
- value: function setRowState(rowIndex, name, value) {
2498
- var _this$_get_data0;
2499
- var row = (_this$_get_data0 = this._get_data('rows')) === null || _this$_get_data0 === void 0 ? void 0 : _this$_get_data0[rowIndex];
2500
- if (!row || !name) return;
2501
- var rowKey = this.getRowKey(rowIndex);
2502
- var oldValue = this.getRowState(rowIndex, name);
2503
- if (oldValue === value) return;
2504
- var data = {
2505
- rowIndex: rowIndex,
2506
- rowId: row[this.getIdFlag()],
2507
- propertyName: name,
2508
- value: value,
2509
- oldValue: oldValue
2510
- };
2511
- if (!this.execute('beforeRowStateChange', data)) return;
2512
- var rowState = _objectSpread2({}, this._get_data('rowState') || {});
2513
- rowState[rowKey] = _objectSpread2(_objectSpread2({}, rowState[rowKey] || {}), {}, _defineProperty({}, name, value));
2514
- this._applyState('rowState', rowState);
2515
- this.execute('afterRowStateChange', data);
2516
- }
2517
- }, {
2518
- key: "setRowStates",
2519
- value: function setRowStates() {
2520
- var _this1 = this;
2521
- var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2522
- if (!isArray(states)) return;
2523
- states.forEach(function (item) {
2524
- return _this1.setRowState(item.rowIndex, item.propertyName || item.name, item.value);
2525
- });
2526
- }
2527
-
2528
- /** 收集增删改过的行,用于提交;没有脏数据时返回 undefined(中台同款) */
2529
- }, {
2530
- key: "getDirtyData",
2531
- value: function getDirtyData(necessary) {
2532
- var _this10 = this;
2533
- var source = this._get_data('dataSource') || [];
2534
- var rowsDataState = this._get_data('rowsDataState') || [];
2535
- var data = [];
2536
- source.forEach(function (row, index) {
2537
- var dataState = rowsDataState[index];
2538
- if (!dataState) return;
2539
- var item = cloneDeep(row);
2540
- item[_this10.getStatusFlag()] = dataState;
2541
- data.push(item);
2542
- });
2543
- return data.length ? data : undefined;
2544
- }
2545
- }, {
2546
- key: "getDirtyRowIndexes",
2547
- value: function getDirtyRowIndexes() {
2548
- var _this11 = this;
2549
- var rows = this._get_data('rows') || [];
2550
- return rows.map(function (row, index) {
2551
- return index;
2552
- }).filter(function (index) {
2553
- return !!_this11.getRowDataState(index);
2554
- });
2555
- }
2556
- }, {
2557
- key: "isDirty",
2558
- value: function isDirty() {
2559
- return !!this.getDirtyData();
2560
- }
2561
-
2562
- // 备份 / 还原未提交的数据(取消编辑时用)
2563
- }, {
2564
- key: "backupState",
2565
- value: function backupState() {
2566
- this._set_data('backupData', {
2567
- dataSource: cloneDeep(this._get_data('dataSource') || []),
2568
- rowsDataState: _toConsumableArray(this._get_data('rowsDataState') || [])
2569
- });
2570
- }
2571
- }, {
2572
- key: "restoreState",
2573
- value: function restoreState() {
2574
- var backup = this._get_data('backupData');
2575
- if (!backup) return;
2576
- this._set_data('dataSource', backup.dataSource, true);
2577
- this._set_data('rowsDataState', _toConsumableArray(backup.rowsDataState), true);
2578
- this.showPage();
2579
- }
2580
-
2581
- /* ======================= 增删改行 ======================= */
2582
-
2583
- /** 中台签名:insertRow(rowIndex, rowData, needCheckDefault, isCopy, extendParams) */
2584
- }, {
2585
- key: "insertRow",
2586
- value: function insertRow(rowIndex) {
2587
- var rowData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2588
- var isCopy = arguments.length > 3 ? arguments[3] : undefined;
2589
- var rows = this._get_data('rows') || [];
2590
- var index = Math.min(rows.length, Math.max(0, rowIndex === undefined ? rows.length : rowIndex));
2591
- var data = {
2592
- index: index,
2593
- row: _objectSpread2({}, rowData),
2594
- isCopy: isCopy
2595
- };
2596
- if (!this.execute('beforeInsertRow', data)) return;
2597
- var row = data.row;
2598
- delete row[this.getIdFlag()];
2599
- setIds.call(this, [row]);
2600
- var source = this._get_data('dataSource') || [];
2601
- var indexInDS = index < rows.length ? this.getDataSourceIndexByRow(index) : source.length;
2602
- source.splice(indexInDS < 0 ? source.length : indexInDS, 0, row);
2603
- var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2604
- rowsDataState.splice(indexInDS < 0 ? rowsDataState.length : indexInDS, 0, DataStates.Insert);
2605
- rows.splice(index, 0, row);
2606
- this._set_data('rowsDataState', rowsDataState, true);
2607
- this.setRows(rows);
2608
- this.execute('afterInsertRow', _objectSpread2(_objectSpread2({}, data), {}, {
2609
- rowIndex: index
2610
- }));
2611
- return row;
2612
- }
2613
- }, {
2614
- key: "insertRows",
2615
- value: function insertRows(rowIndex) {
2616
- var _this12 = this;
2617
- var rowsData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
2618
- var result = [];
2619
- (isArray(rowsData) ? rowsData : [rowsData]).forEach(function (rowData, offset) {
2620
- result.push(_this12.insertRow(rowIndex + offset, rowData));
2621
- });
2622
- return result;
2623
- }
2624
- }, {
2625
- key: "appendRow",
2626
- value: function appendRow() {
2627
- var rowData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2628
- return this.insertRow(this.getRowsCount(), rowData);
2629
- }
2630
- }, {
2631
- key: "updateRow",
2632
- value: function updateRow(rowIndex) {
2633
- var _this$_get_data1;
2634
- var rowData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2635
- var row = (_this$_get_data1 = this._get_data('rows')) === null || _this$_get_data1 === void 0 ? void 0 : _this$_get_data1[rowIndex];
2636
- if (!row) return;
2637
- if (!this.execute('beforeUpdateRow', {
2638
- index: rowIndex,
2639
- row: rowData
2640
- })) return;
2641
- Object.assign(row, rowData);
2642
- this.markRowState(rowIndex, DataStates.Update);
2643
- this.setRows(this._get_data('rows'));
2644
- this.execute('afterUpdateRow', {
2645
- index: rowIndex,
2646
- row: row
2647
- });
2648
- }
2649
- }, {
2650
- key: "updateRows",
2651
- value: function updateRows() {
2652
- var _this13 = this;
2653
- var rowsData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2654
- rowsData.forEach(function (item) {
2655
- var _item$rowIndex;
2656
- return _this13.updateRow((_item$rowIndex = item.rowIndex) !== null && _item$rowIndex !== void 0 ? _item$rowIndex : item.index, item.rowData || item.row);
2657
- });
2658
- }
2659
-
2660
- /** 删除行:有 id 的行标 Delete 保留占位,本地新增未保存的行直接丢弃(中台同款) */
2661
- }, {
2662
- key: "deleteRows",
2663
- value: function deleteRows(rowIndexes) {
2664
- var _this14 = this;
2665
- var indexes = (isArray(rowIndexes) ? rowIndexes : [rowIndexes]).filter(function (index) {
2666
- return index >= 0 && index < _this14.getRowsCount();
2667
- }).sort(function (a, b) {
2668
- return a - b;
2669
- });
2670
- if (!indexes.length) return;
2671
- var rowsToDelete = this.getRowsByIndexes(indexes);
2672
- if (!this.execute('beforeDeleteRows', rowsToDelete, indexes)) return;
2673
- var source = this._get_data('dataSource') || [];
2674
- var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2675
- var deletedIds = new Set();
2676
- // 本地新增的行不需要保留占位,直接从数据源里抹掉
2677
- var discardIds = new Set();
2678
- rowsToDelete.forEach(function (row) {
2679
- var index = source.indexOf(row);
2680
- if (index < 0) return;
2681
- var key = row[_this14.getIdFlag()];
2682
- deletedIds.add(key);
2683
- if (rowsDataState[index] === DataStates.Insert) discardIds.add(key);
2684
- });
2685
- var keptSource = [];
2686
- var keptState = [];
2687
- source.forEach(function (row, index) {
2688
- var key = row[_this14.getIdFlag()];
2689
- if (!deletedIds.has(key)) {
2690
- keptSource.push(row);
2691
- keptState.push(rowsDataState[index]);
2692
- return;
2693
- }
2694
- if (discardIds.has(key)) return;
2695
- keptSource.push(row);
2696
- keptState.push(DataStates.Delete);
2697
- });
2698
- this._set_data('dataSource', keptSource, true);
2699
- this._set_data('rowsDataState', keptState, true);
2700
- // 本地模式下重新切片即可,删除行会自然消失在当前页
2701
- this.showPage();
2702
- this.execute('afterDeleteRows', {
2703
- rowIndexes: indexes,
2704
- rows: rowsToDelete
2705
- });
2706
- }
2707
- }, {
2708
- key: "deleteAllRows",
2709
- value: function deleteAllRows() {
2710
- this.deleteRows(this.getRows().map(function (row, index) {
2711
- return index;
2712
- }));
2713
- }
2714
2070
  }, {
2715
2071
  key: "clear",
2716
2072
  value: function clear() {
2717
2073
  this._set_data('dataSource', [], true);
2718
2074
  this._set_data('rows', [], true);
2719
- this._set_data('rowsDataState', [], true);
2720
- this.clearSelection();
2721
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
2722
- recordCount: 0,
2723
- pageIndex: 1
2724
- }));
2725
- this.setDataSourceView();
2726
- }
2727
-
2728
- /* ======================= 选中 ======================= */
2729
-
2730
- /**
2731
- * 选中行
2732
- * @param {Number|Array} rowIndexes rows 下标
2733
- * @param {Boolean} all true = 替换选择(先清掉其他选中),默认 false = 追加
2734
- */
2735
- }, {
2736
- key: "select",
2737
- value: function select(rowIndexes, all) {
2738
- var _this15 = this;
2739
- if (rowIndexes == null && all !== true) return;
2740
- if (all === true) this.unselectAll({
2741
- silent: true
2742
- });
2743
- var indexes = all === true ? this.getRows().map(function (row, index) {
2744
- return index;
2745
- }) : isArray(rowIndexes) ? rowIndexes : [rowIndexes];
2746
- indexes = indexes.filter(function (index) {
2747
- return index >= 0 && index < _this15.getRowsCount();
2748
- });
2749
- var rows = this._get_data('rows') || [];
2750
- var selectedFlag = this.getSelectedFlag();
2751
- var changed = indexes.filter(function (index) {
2752
- return !rows[index][selectedFlag];
2753
- });
2754
- if (!changed.length) {
2755
- if (all === true) this.flushSelection();
2756
- return;
2757
- }
2758
- var data = {
2759
- rowIndexes: changed,
2760
- rows: changed.map(function (index) {
2761
- return rows[index];
2762
- })
2763
- };
2764
- if (!this.execute('beforeSelect', data)) return;
2765
- changed.forEach(function (index) {
2766
- rows[index][selectedFlag] = true;
2767
- _this15.cacheSelectedRow(rows[index], true);
2768
- });
2769
- this.flushSelection();
2770
- }
2771
- }, {
2772
- key: "unselect",
2773
- value: function unselect(rowIndexes) {
2774
- var _this16 = this;
2775
- if (rowIndexes == null) return;
2776
- var indexes = isArray(rowIndexes) ? rowIndexes : [rowIndexes];
2777
- var rows = this._get_data('rows') || [];
2778
- var selectedFlag = this.getSelectedFlag();
2779
- var changed = indexes.filter(function (index) {
2780
- var _rows$index;
2781
- return (_rows$index = rows[index]) === null || _rows$index === void 0 ? void 0 : _rows$index[selectedFlag];
2782
- });
2783
- if (!changed.length) return;
2784
- if (!this.execute('beforeUnselect', changed)) return;
2785
- changed.forEach(function (index) {
2786
- rows[index][selectedFlag] = false;
2787
- _this16.cacheSelectedRow(rows[index], false);
2788
- });
2789
- this.flushSelection();
2790
- }
2791
- }, {
2792
- key: "selectAll",
2793
- value: function selectAll() {
2794
- var _this17 = this;
2795
- var rows = this._get_data('rows') || [];
2796
- var selectedFlag = this.getSelectedFlag();
2797
- rows.forEach(function (row) {
2798
- row[selectedFlag] = true;
2799
- _this17.cacheSelectedRow(row, true);
2800
- });
2801
- this.flushSelection();
2802
- }
2803
-
2804
- /**
2805
- * 清空选中
2806
- * @param {Object} options onlyPage=true 只清当前页(其他页的跨页缓存保留);silent=true 不下发视图
2807
- *
2808
- * 注意要清 **dataSource** 上的行:`_selected` 记在行对象上,
2809
- * 而本地分页时当前页的 rows 只是 dataSource 的切片,只清 rows 会让翻页回来的行「带着选中复活」。
2810
- */
2811
- }, {
2812
- key: "unselectAll",
2813
- value: function unselectAll() {
2814
- var _this18 = this;
2815
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2816
- var selectedFlag = this.getSelectedFlag();
2817
- var targets = options.onlyPage ? this._get_data('rows') : this._get_data('dataSource');
2818
- (targets || []).forEach(function (row) {
2819
- row[selectedFlag] = false;
2820
- });
2821
- if (options.onlyPage) {
2822
- (this._get_data('rows') || []).forEach(function (row) {
2823
- return _this18.cacheSelectedRow(row, false);
2824
- });
2825
- } else {
2826
- this._set_data('selectedKeys', [], true);
2827
- this._set_data('selectedRowsMap', {}, true);
2828
- this._set_data('selectedKeysSet', new Set(), true);
2829
- }
2830
- if (!options.silent) this.flushSelection();
2831
- }
2832
- }, {
2833
- key: "clearSelection",
2834
- value: function clearSelection() {
2835
- this.unselectAll();
2836
- }
2837
-
2838
- /**
2839
- * 以传入的行集合作为**当前页**的选中结果(表格选中变化回灌的入口)。
2840
- * 其他页的跨页选中缓存不受影响 —— 表格的勾选状态只覆盖当前页,
2841
- * 若在这里清空缓存,翻页就会把之前选的行丢掉。
2842
- */
2843
- }, {
2844
- key: "setSelectedRows",
2845
- value: function setSelectedRows() {
2846
- var _this19 = this;
2847
- var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2848
- var list = isArray(rows) ? rows : [];
2849
- var keyField = this.getRowKeyField();
2850
- var keys = new Set(list.map(function (row) {
2851
- var _row$keyField;
2852
- return String((_row$keyField = row === null || row === void 0 ? void 0 : row[keyField]) !== null && _row$keyField !== void 0 ? _row$keyField : row);
2853
- }));
2854
- var currentRows = this._get_data('rows') || [];
2855
- var selectedFlag = this.getSelectedFlag();
2856
- currentRows.forEach(function (row) {
2857
- var selected = keys.has(String(row[keyField]));
2858
- if (selected !== !!row[selectedFlag]) {
2859
- row[selectedFlag] = selected;
2860
- _this19.cacheSelectedRow(row, selected);
2861
- }
2862
- });
2863
- this.flushSelection();
2864
- }
2865
-
2866
- /** 全量替换选中(含清掉其他页的缓存) */
2867
- }, {
2868
- key: "setSelection",
2869
- value: function setSelection() {
2870
- var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2871
- this.unselectAll({
2872
- silent: true
2873
- });
2874
- this.setSelectedRows(rows);
2875
- }
2876
- }, {
2877
- key: "getSelectedRows",
2878
- value: function getSelectedRows(rowIndexes) {
2879
- var rows = this._get_data('rows') || [];
2880
- var selectedFlag = this.getSelectedFlag();
2881
- var keys = rowIndexes && new Set(isArray(rowIndexes) ? rowIndexes : [rowIndexes]);
2882
- return rows.filter(function (row, index) {
2883
- return row[selectedFlag] && (!keys || keys.has(index));
2884
- });
2885
- }
2886
- }, {
2887
- key: "getSelectedRowIndexes",
2888
- value: function getSelectedRowIndexes() {
2889
- var rows = this._get_data('rows') || [];
2890
- var selectedFlag = this.getSelectedFlag();
2891
- var indexes = [];
2892
- rows.forEach(function (row, index) {
2893
- if (row[selectedFlag]) indexes.push(index);
2894
- });
2895
- return indexes;
2896
- }
2897
- }, {
2898
- key: "getSelectedKeys",
2899
- value: function getSelectedKeys() {
2900
- return this._get_data('selectedKeys') || [];
2901
- }
2902
-
2903
- /** 跨页选中的全部行(按选中顺序) */
2904
- }, {
2905
- key: "getAllCacheSelectedRows",
2906
- value: function getAllCacheSelectedRows() {
2907
- var keys = this._get_data('selectedKeys') || [];
2908
- var rowsMap = this._get_data('selectedRowsMap') || {};
2909
- return keys.map(function (key) {
2910
- return rowsMap[key];
2911
- }).filter(Boolean);
2912
- }
2913
- }, {
2914
- key: "selectByKeys",
2915
- value: function selectByKeys(keys) {
2916
- var selected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2917
- var rowKeyField = this.getRowKeyField();
2918
- var list = isArray(keys) ? keys : [keys];
2919
- var rows = this._get_data('rows') || [];
2920
- var indexes = [];
2921
- list.forEach(function (key) {
2922
- var index = rows.findIndex(function (row) {
2923
- return String(row[rowKeyField]) === String(key);
2924
- });
2925
- if (index > -1) indexes.push(index);
2926
- });
2927
- if (!indexes.length) return;
2928
- selected ? this.select(indexes) : this.unselect(indexes);
2929
- }
2930
- }, {
2931
- key: "getSelectedNodes",
2932
- value: function getSelectedNodes() {
2933
- return this.getAllCacheSelectedRows();
2934
- }
2935
- }, {
2936
- key: "cacheSelectedRow",
2937
- value: function cacheSelectedRow(row, selected) {
2938
- var key = String(row === null || row === void 0 ? void 0 : row[this.getRowKeyField()]);
2939
- var keys = (this._get_data('selectedKeys') || []).filter(function (item) {
2940
- return item !== key;
2941
- });
2942
- var rowsMap = _objectSpread2({}, this._get_data('selectedRowsMap') || {});
2943
- if (selected) keys.push(key);
2944
- if (selected) rowsMap[key] = row;else delete rowsMap[key];
2945
- this._set_data('selectedKeys', keys, true);
2946
- this._set_data('selectedRowsMap', rowsMap, true);
2947
- this._set_data('selectedKeysSet', new Set(keys), true);
2948
- }
2949
-
2950
- // 选中变化统一在这里下发视图(组件侧用同步开关挡住回灌死循环)
2951
- }, {
2952
- key: "flushSelection",
2953
- value: function flushSelection() {
2954
- this._applyState('selectedRows', this.getSelectedRows());
2955
- this.execute('selectionChange', {
2956
- value: this.getSelectedRows(),
2957
- keys: this.getSelectedKeys(),
2958
- indexes: this.getSelectedRowIndexes()
2959
- });
2960
- }
2961
-
2962
- // 重新取数后把跨页选中的标记补回当前页的行上
2963
- }, {
2964
- key: "restoreSelectedFlags",
2965
- value: function restoreSelectedFlags() {
2966
- if (!this.get('cacheSelectedRows')) return;
2967
- var keysSet = this._get_data('selectedKeysSet') || new Set();
2968
- if (!keysSet.size) return;
2969
- var rowKeyField = this.getRowKeyField();
2970
- var selectedFlag = this.getSelectedFlag();
2971
- (this.getRows() || []).forEach(function (row) {
2972
- row[selectedFlag] = keysSet.has(String(row[rowKeyField]));
2973
- });
2974
- }
2975
-
2976
- /* ======================= 分页 ======================= */
2977
- }, {
2978
- key: "setPagination",
2979
- value: function setPagination(value) {
2980
- this._applyState('pagination', !!value);
2981
- this.showPage();
2982
2075
  }
2983
2076
  }, {
2984
2077
  key: "getPageInfo",
@@ -2988,192 +2081,64 @@
2988
2081
  }, {
2989
2082
  key: "getPageIndex",
2990
2083
  value: function getPageIndex() {
2991
- return this.getPageInfo().pageIndex;
2084
+ var pageIndexField = this._get_data('innerUsedAttrs').pageIndex;
2085
+ return this.getPageInfo()[pageIndexField];
2992
2086
  }
2993
2087
  }, {
2994
2088
  key: "getPageSize",
2995
2089
  value: function getPageSize() {
2996
- return this.getPageInfo().pageSize;
2090
+ var pageSizeField = this._get_data('innerUsedAttrs').pageSize;
2091
+ return this.getPageInfo()[pageSizeField];
2997
2092
  }
2998
2093
  }, {
2999
2094
  key: "getTotalCount",
3000
2095
  value: function getTotalCount() {
3001
- return this.getPageInfo().recordCount;
2096
+ var totalField = this._get_data('innerUsedAttrs').pageCount;
2097
+ return this.getPageInfo()[totalField];
3002
2098
  }
3003
2099
  }, {
3004
2100
  key: "setPageInfo",
3005
2101
  value: function setPageInfo(pageInfo) {
3006
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), pageInfo), {
3007
- refresh: true
3008
- });
2102
+ var _pageInfo = this.getPageInfo();
2103
+ this._set_data('pageInfo', _objectSpread2(_objectSpread2({}, _pageInfo), pageInfo));
2104
+ this.reload();
3009
2105
  }
3010
2106
  }, {
3011
2107
  key: "setPageIndex",
3012
2108
  value: function setPageIndex(pageIndex) {
3013
- var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3014
2109
  if (typeof pageIndex !== 'number') return;
3015
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3016
- pageIndex: Math.max(1, pageIndex)
3017
- }), {
3018
- refresh: refresh
3019
- });
2110
+ var pageIndexField = this._get_data('innerUsedAttrs').pageIndex;
2111
+ this._get_data('innerUsedAttrs').pageSize;
2112
+ this._set_data('pageInfo', _objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, _defineProperty({}, pageIndexField, Math.max(1, pageIndex))));
3020
2113
  }
3021
2114
  }, {
3022
2115
  key: "setPageSize",
3023
2116
  value: function setPageSize(pageSize) {
3024
- var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3025
2117
  if (typeof pageSize !== 'number') return;
3026
- // 与中台一致:pageSize = -1 表示不分页
3027
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3028
- pageSize: Math.max(-1, pageSize),
3029
- pageIndex: 1
3030
- }), {
3031
- refresh: refresh
3032
- });
3033
- }
3034
- }, {
3035
- key: "setRecordCount",
3036
- value: function setRecordCount(recordCount) {
3037
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3038
- recordCount: recordCount || 0
3039
- }));
3040
- }
3041
-
3042
- /**
3043
- * 统一的分页写入:算 pageCount / 记录 begin~end、切片、下发视图
3044
- * @param {Object} options silent=true 时不通知视图(组件自己的翻页动作走这里)
3045
- */
3046
- }, {
3047
- key: "applyPageInfo",
3048
- value: function applyPageInfo(pageInfo) {
3049
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3050
- var next = _objectSpread2({}, pageInfo || {});
3051
- var pageSize = next.pageSize === -1 ? -1 : next.pageSize || DEFAULT_PAGE_SIZE;
3052
- var recordCount = next.recordCount || 0;
3053
- // recordCount 还没取到时不要按 pageCount 夹 pageIndex,否则「跳第 N 页」会被压回第 1 页
3054
- var known = recordCount > 0;
3055
- next.pageSize = pageSize;
3056
- next.recordCount = recordCount;
3057
- next.pageCount = pageSize > 0 ? Math.max(1, Math.ceil(recordCount / pageSize)) : 1;
3058
- next.pageIndex = pageSize > 0 ? Math.max(1, known ? Math.min(next.pageIndex || 1, next.pageCount) : next.pageIndex || 1) : 1;
3059
- next.beginPageIndex = pageSize > 0 ? (next.pageIndex - 1) * pageSize + 1 : 1;
3060
- next.endPageIndex = pageSize > 0 ? Math.min(next.pageIndex * pageSize, recordCount) : recordCount;
3061
- this._set_data('pageInfo', next, true);
3062
- if (options.silent) return next;
3063
- this._applyState('pageInfo', next);
3064
- if (!this.isRemote()) this.showPage();
3065
- if (options.refresh && this.isRemote()) this.refresh();
3066
- return next;
3067
- }
3068
-
3069
- /** 本地分页:按 pageInfo 从 dataSource 切出当前页 rows */
3070
- }, {
3071
- key: "showPage",
3072
- value: function showPage() {
3073
- var source = this._get_data('dataSource') || [];
3074
- if (this.isRemote() || !this.isPagination()) {
3075
- this.setRows(source);
3076
- return;
3077
- }
3078
- var _this$getPageInfo = this.getPageInfo(),
3079
- pageIndex = _this$getPageInfo.pageIndex,
3080
- pageSize = _this$getPageInfo.pageSize;
3081
- var start = (pageIndex - 1) * pageSize;
3082
- this.setRows(source.slice(start, start + pageSize));
2118
+ // pageSize = -1 表示不分页
2119
+ var pageIndexField = this._get_data('innerUsedAttrs').pageIndex;
2120
+ var pageSizeField = this._get_data('innerUsedAttrs').pageSize;
2121
+ this._set_data('pageInfo', _objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, _defineProperty(_defineProperty({}, pageSizeField, Math.max(-1, pageSize)), pageIndexField, 1)));
3083
2122
  }
3084
-
3085
- /** 只换当前页 rows(中台 setRows) */
3086
- }, {
3087
- key: "setRows",
3088
- value: function setRows(rows) {
3089
- var list = isArray(rows) ? rows : [];
3090
- this._set_data('rows', list, true);
3091
- this.setRowsIdMap();
3092
- // 注意:这里推的是原始行对象,而不是中台的 getShowRows() 展示副本 —— 否则
3093
- // 选中回灌、单元格编辑会落到副本上,模型与视图的数据对不上
3094
- this._applyState('data', list);
3095
- }
3096
- }, {
3097
- key: "setDataSourceView",
3098
- value: function setDataSourceView() {
3099
- this._applyState('data', this._get_data('rows') || []);
3100
- }
3101
- }, {
3102
- key: "setRowsIdMap",
3103
- value: function setRowsIdMap() {
3104
- var _this20 = this;
3105
- var map = {};
3106
- (this._get_data('rows') || []).forEach(function (row) {
3107
- if ((row === null || row === void 0 ? void 0 : row[_this20.getIdFlag()]) !== undefined) map[row[_this20.getIdFlag()]] = row;
3108
- });
3109
- this._set_data('rowsIdMap', map);
3110
- }
3111
- }, {
3112
- key: "getRowIdMap",
3113
- value: function getRowIdMap() {
3114
- return this._get_data('rowsIdMap') || {};
3115
- }
3116
-
3117
- /* ======================= 校验 ======================= */
3118
-
3119
- /**
3120
- * 必输校验(中台会把校验委托给 editRowModel,我们这层没有行模型,只做列级必输)
3121
- * @returns {Boolean} 通过返回 true,不通过返回 false,并把消息推给视图(validate 事件)
3122
- */
3123
2123
  }, {
3124
- key: "validate",
3125
- value: function validate(cancel, paramsRowsIndex) {
3126
- var _this21 = this;
3127
- if (cancel) {
3128
- this.doPropertyChange('validate', {
3129
- type: '',
3130
- message: '',
3131
- errors: []
3132
- });
3133
- this._set_data('validateErrors', []);
3134
- return false;
3135
- }
3136
- this.deleteNotModifiedRows();
3137
- var columns = this._get_data('columns') || {};
3138
- var rows = paramsRowsIndex ? this.getRowsByIndexes(paramsRowsIndex) : this.getRows();
3139
- var errors = [];
3140
- rows.forEach(function (row, index) {
3141
- for (var field in columns) {
3142
- var column = columns[field];
3143
- if (!_this21.isRequiredColumn(column)) continue;
3144
- var value = row[field];
3145
- var empty = isEmpty(value) || isArray(value) && !value.length || isEmptyObject(value);
3146
- if (!empty) continue;
3147
- var caption = column.cShowCaption || column.cCaption || column.cCaption || column.title || field;
3148
- errors.push({
3149
- rowIndex: index,
3150
- rowId: row[_this21.getIdFlag()],
3151
- cellName: field,
3152
- message: "".concat(caption, "\u4E0D\u80FD\u4E3A\u7A7A")
3153
- });
3154
- _this21.setCellState(index, field, 'msg', '不能为空');
3155
- }
3156
- });
3157
- this._set_data('validateErrors', errors);
3158
- var message = errors.length ? errors[0].message : '';
3159
- this.doPropertyChange('validate', {
3160
- type: errors.length ? 'error' : '',
3161
- message: message,
3162
- errors: errors
3163
- });
3164
- this.execute('afterValidate', {
3165
- valid: !errors.length,
3166
- errors: errors
3167
- });
3168
- return !errors.length;
2124
+ key: "setTotalCount",
2125
+ value: function setTotalCount(total) {
2126
+ var totalField = this._get_data('innerUsedAttrs').pageCount;
2127
+ this.getPageInfo()[totalField] = total;
3169
2128
  }
3170
2129
  }]);
3171
- }(BaseModel);
2130
+ }(BaseModel$1);
3172
2131
 
3173
- var ViewModel = /*#__PURE__*/function (_BaseModel) {
2132
+ var ViewModel$1 = /*#__PURE__*/function (_BaseModel) {
3174
2133
  function ViewModel() {
2134
+ var _this;
3175
2135
  _classCallCheck(this, ViewModel);
3176
- return _callSuper(this, ViewModel, arguments);
2136
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2137
+ args[_key] = arguments[_key];
2138
+ }
2139
+ _this = _callSuper(this, ViewModel, [].concat(args));
2140
+ _defineProperty(_this, "modelType", 'ViewModel');
2141
+ return _this;
3177
2142
  }
3178
2143
  _inherits(ViewModel, _BaseModel);
3179
2144
  return _createClass(ViewModel, [{
@@ -3189,7 +2154,7 @@
3189
2154
  }, {
3190
2155
  key: "set",
3191
2156
  value: function set(propertyName, value) {
3192
- if (value instanceof BaseModel) {
2157
+ if (value instanceof BaseModel$1) {
3193
2158
  value.setParent(this);
3194
2159
  value.setName(propertyName);
3195
2160
  }
@@ -3215,12 +2180,12 @@
3215
2180
  }, {
3216
2181
  key: "getData",
3217
2182
  value: function getData() {
3218
- var _this = this;
2183
+ var _this2 = this;
3219
2184
  var propertyNames = this._get_data('propertyNames') || [];
3220
2185
  var data = {};
3221
2186
  propertyNames.forEach(function (propertyName) {
3222
- var property = _this.get(propertyName);
3223
- if (property instanceof BaseModel && property._get_data('needCollect') !== false) {
2187
+ var property = _this2.get(propertyName);
2188
+ if (property instanceof BaseModel$1 && property._get_data('needCollect') !== false) {
3224
2189
  var _property$getData;
3225
2190
  data[propertyName] = (_property$getData = property.getData) === null || _property$getData === void 0 ? void 0 : _property$getData.call(property);
3226
2191
  }
@@ -3235,13 +2200,13 @@
3235
2200
  }, {
3236
2201
  key: "getAllData",
3237
2202
  value: function getAllData(withOutGrid) {
3238
- var _this2 = this;
2203
+ var _this3 = this;
3239
2204
  var propertyNames = this._get_data('propertyNames') || [];
3240
2205
  var rawData = {};
3241
2206
  propertyNames.forEach(function (propertyName) {
3242
2207
  var _property$getData2;
3243
- var property = _this2.get(propertyName);
3244
- if (!(property instanceof BaseModel) || property._get_data('needCollect') === false) {
2208
+ var property = _this3.get(propertyName);
2209
+ if (!(property instanceof BaseModel$1) || property._get_data('needCollect') === false) {
3245
2210
  return;
3246
2211
  }
3247
2212
  if (withOutGrid && property._get_data('isGrid')) {
@@ -3276,11 +2241,11 @@
3276
2241
  }, {
3277
2242
  key: "clear",
3278
2243
  value: function clear(useDefault) {
3279
- var _this3 = this;
2244
+ var _this4 = this;
3280
2245
  var propertyNames = this._get_data('propertyNames') || [];
3281
2246
  propertyNames.forEach(function (propertyName) {
3282
- var property = _this3.get(propertyName);
3283
- if (property instanceof BaseModel && property._get_data('needClear') !== false) {
2247
+ var property = _this4.get(propertyName);
2248
+ if (property instanceof BaseModel$1 && property._get_data('needClear') !== false) {
3284
2249
  var _property$clear;
3285
2250
  (_property$clear = property.clear) === null || _property$clear === void 0 || _property$clear.call(property, useDefault);
3286
2251
  }
@@ -3314,7 +2279,7 @@
3314
2279
  var propertyNames = this._get_data('propertyNames');
3315
2280
  for (var i = 0, len = propertyNames.length; i < len; i++) {
3316
2281
  gridModel = this.get(propertyNames[i]);
3317
- var isGridModel = gridModel instanceof GridModel || gridModel.modelType == 'GridModel';
2282
+ var isGridModel = gridModel instanceof GridModel$1 || gridModel.modelType == 'GridModel';
3318
2283
  if (isGridModel) {
3319
2284
  this._set_data('gridModel', gridModel);
3320
2285
  return gridModel;
@@ -3328,81 +2293,157 @@
3328
2293
  var gridModels = [];
3329
2294
  for (var i = 0, len = propertyNames.length; i < len; i++) {
3330
2295
  var gridModel = this.get(propertyNames[i]);
3331
- var isGridModel = gridModel instanceof GridModel || gridModel.modelType == 'GridModel';
2296
+ var isGridModel = gridModel instanceof GridModel$1 || gridModel.modelType == 'GridModel';
3332
2297
  if (isGridModel) {
3333
2298
  gridModels.push(gridModel);
3334
2299
  }
3335
2300
  }
3336
2301
  return gridModels;
3337
2302
  }
2303
+ }, {
2304
+ key: "getGridFilterModel",
2305
+ value: function getGridFilterModel(propertyName) {
2306
+ var gridModel = this.getGridModel(propertyName);
2307
+ return gridModel.getCache('FilterViewModel');
2308
+ }
3338
2309
  }]);
3339
- }(BaseModel);
3340
-
3341
- function createModelFactory(props) {
3342
- var cControlType = props.cControlType.toLowerCase();
3343
- var model;
3344
- switch (cControlType) {
3345
- case 'input':
3346
- model = new SimpleModel(props);
3347
- break;
2310
+ }(BaseModel$1);
2311
+
2312
+ function loadScripts(_require, _path, _files, _callback, _params) {
2313
+ var _params2;
2314
+ var path = _path;
2315
+ var files = _files;
2316
+ var callback = _callback;
2317
+ var params = _params;
2318
+ if (Array.isArray(_path) && typeof _files === 'function') {
2319
+ path = undefined;
2320
+ files = _path;
2321
+ callback = _files;
2322
+ params = _callback;
3348
2323
  }
3349
- return model;
2324
+ var self = ((_params2 = params) === null || _params2 === void 0 ? void 0 : _params2.vm) || this;
2325
+ var result = {
2326
+ code: 0,
2327
+ message: ''
2328
+ };
2329
+ files = Array.isArray(files) ? files : [];
2330
+ var filesStr = files.join(',');
2331
+ if (typeof _require !== 'function') {
2332
+ var _callback2;
2333
+ result.code = -1;
2334
+ result.message = "requirejs.js \u672A\u52A0\u8F7D\uFF0C\u8DF3\u8FC7\u6269\u5C55\u811A\u672C\uFF1A".concat(filesStr);
2335
+ (_callback2 = callback) === null || _callback2 === void 0 || _callback2(result);
2336
+ return;
2337
+ }
2338
+ if (!files.length) {
2339
+ var _callback3;
2340
+ result.code = 404;
2341
+ result.message = '扩展脚本为空';
2342
+ (_callback3 = callback) === null || _callback3 === void 0 || _callback3(result);
2343
+ return;
2344
+ }
2345
+ _require(path, files, function () {
2346
+ var _callback4;
2347
+ for (var i = 0, len = arguments.length; i < len; i++) {
2348
+ var extend = i < 0 || arguments.length <= i ? undefined : arguments[i];
2349
+ if (extend && extend.doAction) {
2350
+ // 处理扩展脚本异常导致渲染失败
2351
+ try {
2352
+ extend.doAction('init', self);
2353
+ } catch (err) {
2354
+ result.code = -2;
2355
+ result.message = "".concat(filesStr, "\u62D3\u5C55\u811A\u672C\u5F02\u5E38");
2356
+ result.error = err;
2357
+ break;
2358
+ }
2359
+ } else {
2360
+ result.code = -3;
2361
+ result.message = "".concat(filesStr, "\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25 \u6216 \u672A\u6CE8\u518C\u62D3\u5C55\u811A\u672C");
2362
+ break;
2363
+ }
2364
+ }
2365
+ (_callback4 = callback) === null || _callback4 === void 0 || _callback4(result);
2366
+ }, function (err) {
2367
+ var _callback5;
2368
+ result.code = -4;
2369
+ result.message = "\u672A\u627E\u5230\u6269\u5C55\u811A\u672C\uFF1A".concat(filesStr);
2370
+ result.error = err;
2371
+ (_callback5 = callback) === null || _callback5 === void 0 || _callback5(result);
2372
+ });
3350
2373
  }
3351
- function _initExtendJs(params) {
2374
+
2375
+ // 初始化拓展脚本
2376
+ function initExtendScripts(params) {
3352
2377
  var self = this;
3353
- if (window && window.__debugger_initExtendJs) {
2378
+ if (window.devfab && window.devfab.__debugger_initExtendJs) {
3354
2379
  // eslint-disable-next-line no-debugger
3355
2380
  debugger;
3356
2381
  }
3357
2382
  var requirejs = params.requirejs,
3358
- extendFilePath = params.extendFilePath,
3359
- pageKey = params.pageKey,
3360
- _params$enableExtendJ = params.enableExtendJs,
3361
- enableExtendJs = _params$enableExtendJ === void 0 ? true : _params$enableExtendJ,
3362
- _params$extendJsPath = params.extendJsPath,
3363
- extendJsPath = _params$extendJsPath === void 0 ? '_VM.Extend.js' : _params$extendJsPath;
3364
- if (!enableExtendJs) {
2383
+ extendScriptParams = params.extendScriptParams;
2384
+ var _ref = extendScriptParams || {},
2385
+ _ref$enableJs = _ref.enableJs,
2386
+ enableJs = _ref$enableJs === void 0 ? true : _ref$enableJs,
2387
+ filepath = _ref.filepath,
2388
+ scriptUrl = _ref.scriptUrl;
2389
+ if (!enableJs) {
2390
+ window.devfab.debug && console.info("[devfab][extendjs] \u672A\u542F\u7528\u6269\u5C55\u811A\u672C");
3365
2391
  self.execute('extendReady', self);
3366
2392
  return;
3367
2393
  }
3368
- var extendFile = "".concat(pageKey).concat(extendJsPath);
3369
- var extendFiles = [extendFile];
3370
- // if (self.getEnv && self.getEnv('everyCommonExtend')) {
3371
- // extendFiles.push(self.getEnv('everyCommonExtend'))
3372
- // }
3373
- if (typeof requirejs.require !== 'function') {
3374
- console.warn("requirejs.js \u672A\u52A0\u8F7D\uFF0C\u8DF3\u8FC7\u6269\u5C55\u811A\u672C\uFF1A".concat(extendFile));
2394
+ if (!scriptUrl) {
2395
+ window.devfab.debug && console.info("[devfab][extendjs] \u6269\u5C55\u811A\u672C\u672A\u5B9A\u4E49");
3375
2396
  self.execute('extendReady', self);
3376
2397
  return;
3377
2398
  }
3378
- requirejs.require(extendFilePath, extendFiles, function (extend, everyCommonExtend) {
3379
- if (extend && extend.doAction) {
3380
- // 处理扩展脚本异常导致渲染失败
3381
- try {
3382
- extend.doAction('init', self);
3383
- if (everyCommonExtend) {
3384
- everyCommonExtend.doAction('init', self);
3385
- }
3386
- } catch (err) {
3387
- console.error('扩展脚本异常:', err);
2399
+ var extendFilePath = filepath;
2400
+ var extendFile = scriptUrl;
2401
+ var extendFiles = [extendFile];
2402
+ if (self.getEnv && self.getEnv('everyCommonExtend')) {
2403
+ extendFiles.push(self.getEnv('everyCommonExtend'));
2404
+ }
2405
+ loadScripts.call(self, requirejs.require, extendFilePath, extendFiles, function (result) {
2406
+ if ((result === null || result === void 0 ? void 0 : result.code) != 0 && window.devfab.debug) {
2407
+ if (!result.error) {
2408
+ console.warn("[devfab][extendjs] ".concat(result.message));
2409
+ } else {
2410
+ console.error("[devfab][extendjs] ".concat(result.message, " \u9519\u8BEF\u4FE1\u606F\uFF1A"), result.error);
3388
2411
  }
3389
- } else {
3390
- console.error("".concat(extendFile, "\u6269\u5C55\u6587\u4EF6extend.*.min.js\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25 \u6216 \u672A\u6CE8\u518C\u6269\u5C55\u811A\u672C"));
3391
2412
  }
3392
2413
  self.execute('extendReady', self);
3393
- }, function (err) {
3394
- console.warn("\u672A\u627E\u5230\u6269\u5C55\u811A\u672C\uFF1A".concat(extendFile, "\u9519\u8BEF\u4FE1\u606F\uFF1A"), err);
3395
- self.execute('extendReady', self);
3396
2414
  });
3397
2415
  }
3398
- var _extscripturls = /*#__PURE__*/function () {
3399
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(result, vm, params) {
2416
+
2417
+ // 初始化客开脚本
2418
+ var initExtScripts = /*#__PURE__*/function () {
2419
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(data, vm, params) {
3400
2420
  var _vm$getParams, _exturls;
3401
- var _result$extscripturls, exturls;
2421
+ var requirejs, extendScriptParams, _ref3, _ref3$enableExtJs, enableExtJs, _ref3$exturlsField, exturlsField, extscripturls, exturls;
3402
2422
  return _regenerator().w(function (_context2) {
3403
2423
  while (1) switch (_context2.n) {
3404
2424
  case 0:
3405
- _result$extscripturls = result.extscripturls, exturls = _result$extscripturls === void 0 ? [] : _result$extscripturls; // 支持注入单据级本地化扩展脚本
2425
+ if (window.devfab && window.devfab.__debugger_initExtJs) {
2426
+ // eslint-disable-next-line no-debugger
2427
+ debugger;
2428
+ }
2429
+ requirejs = params.requirejs, extendScriptParams = params.extendScriptParams;
2430
+ _ref3 = extendScriptParams || {}, _ref3$enableExtJs = _ref3.enableExtJs, enableExtJs = _ref3$enableExtJs === void 0 ? true : _ref3$enableExtJs, _ref3$exturlsField = _ref3.exturlsField, exturlsField = _ref3$exturlsField === void 0 ? 'extscripturls' : _ref3$exturlsField;
2431
+ if (enableExtJs) {
2432
+ _context2.n = 1;
2433
+ break;
2434
+ }
2435
+ window.devfab.debug && console.info("[devfab][exturls] \u672A\u542F\u7528\u5BA2\u5F00\u6269\u5C55\u811A\u672C");
2436
+ return _context2.a(2, Promise.resolve(true));
2437
+ case 1:
2438
+ if (data) {
2439
+ _context2.n = 2;
2440
+ break;
2441
+ }
2442
+ window.devfab.debug && console.info("[devfab][exturls] \u5143\u6570\u636E\u4E0D\u80FD\u4E3A\u7A7A");
2443
+ return _context2.a(2, Promise.resolve(true));
2444
+ case 2:
2445
+ extscripturls = data === null || data === void 0 ? void 0 : data[exturlsField];
2446
+ exturls = Array.isArray(extscripturls) ? extscripturls : []; // 支持注入单据级本地化扩展脚本
3406
2447
  exturls = (vm.getCache('localDynamicScripts') || []).concat(exturls);
3407
2448
 
3408
2449
  // 支持给全单据注入扩展脚本
@@ -3415,13 +2456,13 @@
3415
2456
 
3416
2457
  // 预处理扩展脚本
3417
2458
  if (!((_exturls = exturls) !== null && _exturls !== void 0 && _exturls.length)) {
3418
- _context2.n = 2;
2459
+ _context2.n = 4;
3419
2460
  break;
3420
2461
  }
3421
2462
  exturls = _toConsumableArray(new Set(exturls));
3422
- _context2.n = 1;
2463
+ _context2.n = 3;
3423
2464
  return Promise.all(exturls.map(/*#__PURE__*/function () {
3424
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
2465
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
3425
2466
  return _regenerator().w(function (_context) {
3426
2467
  while (1) switch (_context.n) {
3427
2468
  case 0:
@@ -3430,86 +2471,59 @@
3430
2471
  }, _callee);
3431
2472
  }));
3432
2473
  return function (_x4) {
3433
- return _ref2.apply(this, arguments);
2474
+ return _ref4.apply(this, arguments);
3434
2475
  };
3435
2476
  }()));
3436
- case 1:
2477
+ case 3:
3437
2478
  exturls = _context2.v;
3438
- case 2:
2479
+ case 4:
3439
2480
  // 加载扩展脚本
3440
- result.extscripturls = exturls;
2481
+ data[exturlsField] = exturls;
3441
2482
  return _context2.a(2, new Promise(function (resolve, reject) {
3442
- _requireExtscripturls(result, vm, params, function () {
2483
+ loadScripts.call(vm, requirejs.require, exturls, function (result) {
2484
+ if ((result === null || result === void 0 ? void 0 : result.code) != 0 && window.devfab.debug) {
2485
+ if (!result.error) {
2486
+ console.warn("[devfab][extjs] ".concat(result.message));
2487
+ } else {
2488
+ console.error("[devfab][extjs] ".concat(result.message, " \u9519\u8BEF\u4FE1\u606F\uFF1A"), result.error);
2489
+ }
2490
+ }
3443
2491
  resolve(true);
3444
2492
  });
3445
2493
  }));
3446
2494
  }
3447
2495
  }, _callee2);
3448
2496
  }));
3449
- return function _extscripturls(_x, _x2, _x3) {
3450
- return _ref.apply(this, arguments);
2497
+ return function initExtScripts(_x, _x2, _x3) {
2498
+ return _ref2.apply(this, arguments);
3451
2499
  };
3452
2500
  }();
3453
- function _requireExtscripturls(result, vm, params, callback) {
3454
- // 二开、客开的扩展脚本
3455
- var _result$extscripturls2 = result.extscripturls,
3456
- exturls = _result$extscripturls2 === void 0 ? [] : _result$extscripturls2;
3457
- if (exturls !== null && exturls !== void 0 && exturls.length) {
3458
- try {
3459
- var _params$requirejs;
3460
- var requireInner = params === null || params === void 0 || (_params$requirejs = params.requirejs) === null || _params$requirejs === void 0 ? void 0 : _params$requirejs.requireInner;
3461
- if (typeof requireInner !== 'function') {
3462
- console.warn("requirejs.js \u672A\u52A0\u8F7D\uFF0C\u8DF3\u8FC7\u5BA2\u5F00\u6269\u5C55\u811A\u672C");
3463
- callback === null || callback === void 0 || callback(result, vm);
3464
- return;
3465
- }
3466
- requireInner(exturls,
3467
- // eslint-disable-next-line prefer-arrow-callback
3468
- function () {
3469
- // cb.console.info('[exturls]: %c [extscript js] cb.requireInner success and doAction[init]', 'color:green')
3470
- var correct = true;
3471
- if (arguments.length) {
3472
- for (var i = 0, len = arguments.length; i < len; i++) {
3473
- var external = i < 0 || arguments.length <= i ? undefined : arguments[i];
3474
- if (external) {
3475
- external.doAction('init', vm);
3476
- } else {
3477
- correct = false;
3478
- }
3479
- }
3480
- if (correct) {
3481
- callback === null || callback === void 0 || callback(result, vm);
3482
- }
3483
- } else {
3484
- correct = false;
3485
- }
3486
- if (!correct) {
3487
- console.log('[error] [extendjs] 租户级扩展脚本有语法错误,请修改正确后刷新浏览器重试!');
3488
- }
3489
- },
3490
- // eslint-disable-next-line prefer-arrow-callback
3491
- function (_error) {
3492
- // cb.console.info('[exturls]: %c [extscript js] cb.requireInner, but notFound', 'font-size:12pt;color:#860786')
3493
- callback === null || callback === void 0 || callback(result, vm);
3494
- });
3495
- } catch (e) {
3496
- // cb.console.log('[exturls]: %c [extscript js] cb.requireInner exception', 'font-size:12pt;color:#860786', e)
3497
- callback === null || callback === void 0 || callback(result, vm);
3498
- }
3499
- } else {
3500
- callback === null || callback === void 0 || callback(result, vm);
2501
+
2502
+ var BaseModel = BaseModel$1;
2503
+ var SimpleModel = SimpleModel$1;
2504
+ var ViewModel = ViewModel$1;
2505
+ var GridModel = GridModel$1;
2506
+ function createModelFactory(props, params) {
2507
+ var SimpleModel = (params === null || params === void 0 ? void 0 : params.SimpleModel) || SimpleModel$1;
2508
+ var cControlType = props.cControlType || props.component || props.controlType || props.ctrlType;
2509
+ cControlType = cControlType.toLowerCase();
2510
+ var model;
2511
+ switch (cControlType) {
2512
+ case 'input':
2513
+ model = new SimpleModel(props);
2514
+ break;
2515
+ default:
2516
+ model = new SimpleModel(props);
2517
+ break;
3501
2518
  }
2519
+ return model;
3502
2520
  }
3503
2521
  function _createViewModel(meta) {
2522
+ var _params$models;
3504
2523
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3505
- var _params$extendFilePat = params.extendFilePathField,
3506
- extendFilePathField = _params$extendFilePat === void 0 ? 'domainKey' : _params$extendFilePat,
3507
- _params$pageKeyField = params.pageKeyField,
3508
- pageKeyField = _params$pageKeyField === void 0 ? 'billNo' : _params$pageKeyField,
3509
- _params$modelNameFiel = params.modelNameField,
2524
+ var _params$modelNameFiel = params.modelNameField,
3510
2525
  modelNameField = _params$modelNameFiel === void 0 ? 'cName' : _params$modelNameFiel;
3511
- var extendFilePath = meta[extendFilePathField] || '';
3512
- var pageKey = meta[pageKeyField] || '';
2526
+ var ViewModel = (params === null || params === void 0 || (_params$models = params.models) === null || _params$models === void 0 ? void 0 : _params$models.ViewModel) || ViewModel$1;
3513
2527
  var VM = /*#__PURE__*/function (_ViewModel) {
3514
2528
  function VM() {
3515
2529
  _classCallCheck(this, VM);
@@ -3528,29 +2542,26 @@
3528
2542
  value: function createModels(_models, meta) {
3529
2543
  var fields = {};
3530
2544
  var models = Array.isArray(_models) ? _models : [];
3531
- models.forEach(function (m) {
3532
- var _params$createModelFa, _params$onBeforeCreat;
3533
- var model = params === null || params === void 0 || (_params$createModelFa = params.createModelFactory) === null || _params$createModelFa === void 0 ? void 0 : _params$createModelFa.call(params, m);
3534
- if (!model) {
3535
- model = createModelFactory(m);
3536
- }
2545
+ models.forEach(function (field) {
2546
+ var _params$onBeforeInitM, _params$onAfterInitMo;
2547
+ var model = createModelFactory(field, params);
2548
+ var modelName = field[modelNameField];
3537
2549
  var param = {
3538
2550
  model: model,
3539
- field: m,
3540
- meta: meta
2551
+ meta: field,
2552
+ childModel: true,
2553
+ modelName: modelName
3541
2554
  };
3542
- params === null || params === void 0 || (_params$onBeforeCreat = params.onBeforeCreateModel) === null || _params$onBeforeCreat === void 0 || _params$onBeforeCreat.call(params, param);
3543
- fields[m[modelNameField]] = param.model;
2555
+ params === null || params === void 0 || (_params$onBeforeInitM = params.onBeforeInitModel) === null || _params$onBeforeInitM === void 0 || _params$onBeforeInitM.call(params, param);
2556
+ fields[param.modelName] = param.model;
2557
+ params === null || params === void 0 || (_params$onAfterInitMo = params.onAfterInitModel) === null || _params$onAfterInitMo === void 0 || _params$onAfterInitMo.call(params, param);
3544
2558
  });
3545
2559
  return fields;
3546
2560
  }
3547
2561
  }, {
3548
2562
  key: "initData",
3549
2563
  value: function initData() {
3550
- _initExtendJs.call(this, _objectSpread2(_objectSpread2({}, params), {}, {
3551
- extendFilePath: extendFilePath,
3552
- pageKey: pageKey
3553
- }));
2564
+ initExtendScripts.call(this, params);
3554
2565
  }
3555
2566
  }]);
3556
2567
  }(ViewModel);
@@ -3558,9 +2569,17 @@
3558
2569
  return VM;
3559
2570
  }
3560
2571
  function _initViewModel(meta, params) {
2572
+ var _params$onBeforeInitM2, _vm$init, _params$onAfterInitMo2;
3561
2573
  var VM = _createViewModel(meta, params);
3562
2574
  var vm = new VM();
3563
- vm.init(meta.models, meta);
2575
+ var param = {
2576
+ model: vm,
2577
+ meta: meta
2578
+ };
2579
+ params === null || params === void 0 || (_params$onBeforeInitM2 = params.onBeforeInitModel) === null || _params$onBeforeInitM2 === void 0 || _params$onBeforeInitM2.call(params, param);
2580
+ param.model = vm;
2581
+ vm === null || vm === void 0 || (_vm$init = vm.init) === null || _vm$init === void 0 || _vm$init.call(vm, meta.models, meta);
2582
+ params === null || params === void 0 || (_params$onAfterInitMo2 = params.onAfterInitModel) === null || _params$onAfterInitMo2 === void 0 || _params$onAfterInitMo2.call(params, param);
3564
2583
  return vm;
3565
2584
  }
3566
2585
  function initViewModel(meta) {
@@ -3574,30 +2593,30 @@
3574
2593
  var _vm, _vm$destroyVM;
3575
2594
  (_vm = vm) === null || _vm === void 0 || (_vm$destroyVM = _vm.destroyVM) === null || _vm$destroyVM === void 0 || _vm$destroyVM.call(_vm);
3576
2595
  vm = null;
2596
+ window.devfab.debug && console.info("[devfab][initVM]: destory vm ".concat(new Date().toString()));
3577
2597
  });
3578
- vm.on('extendReady', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
2598
+ vm.on('extendReady', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
3579
2599
  var promises;
3580
- return _regenerator().w(function (_context3) {
3581
- while (1) switch (_context3.n) {
2600
+ return _regenerator().w(function (_context) {
2601
+ while (1) switch (_context.n) {
3582
2602
  case 0:
3583
- promises = []; // 加载二开脚本
3584
- promises.push(_extscripturls(meta, vm, params));
3585
- _context3.n = 1;
2603
+ promises = []; // 加载客开脚本
2604
+ promises.push(initExtScripts(meta, vm, params));
2605
+ _context.n = 1;
3586
2606
  return Promise.all(promises);
3587
2607
  case 1:
3588
- // console.info(`[initVM]: after vm init ${ moment().format('YYYY-MM-DD HH:mm:ss.SSS')}`)
2608
+ window.devfab.debug && console.info("[devfab][initVM]: after vm init ".concat(new Date().toString()));
3589
2609
  callback === null || callback === void 0 || callback(vm, meta);
3590
2610
  case 2:
3591
- return _context3.a(2);
2611
+ return _context.a(2);
3592
2612
  }
3593
- }, _callee3);
2613
+ }, _callee);
3594
2614
  })));
3595
2615
  vm.initData();
3596
2616
  return vm;
3597
2617
  }
3598
2618
  var models = {
3599
2619
  BaseModel: BaseModel,
3600
- FilterModel: FilterModel,
3601
2620
  SimpleModel: SimpleModel,
3602
2621
  GridModel: GridModel,
3603
2622
  ViewModel: ViewModel,
@@ -3612,6 +2631,7 @@
3612
2631
  };
3613
2632
 
3614
2633
  var devfab = {
2634
+ debug: false,
3615
2635
  utils: {
3616
2636
  builder: new utils.Builder(),
3617
2637
  cache: new utils.CacheUtil(),
@@ -3623,6 +2643,7 @@
3623
2643
  utils: utils
3624
2644
  }
3625
2645
  };
2646
+ window.devfab = devfab;
3626
2647
 
3627
2648
  exports["default"] = devfab;
3628
2649