devfab 1.1.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
@@ -19,6 +19,31 @@
19
19
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
20
20
  return e;
21
21
  }
22
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
23
+ try {
24
+ var i = n[a](c),
25
+ u = i.value;
26
+ } catch (n) {
27
+ return void e(n);
28
+ }
29
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
30
+ }
31
+ function _asyncToGenerator(n) {
32
+ return function () {
33
+ var t = this,
34
+ e = arguments;
35
+ return new Promise(function (r, o) {
36
+ var a = n.apply(t, e);
37
+ function _next(n) {
38
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
39
+ }
40
+ function _throw(n) {
41
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
42
+ }
43
+ _next(void 0);
44
+ });
45
+ };
46
+ }
22
47
  function _callSuper(t, o, e) {
23
48
  return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
24
49
  }
@@ -151,6 +176,114 @@
151
176
  if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
152
177
  return _assertThisInitialized(t);
153
178
  }
179
+ function _regenerator() {
180
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
181
+ var e,
182
+ t,
183
+ r = "function" == typeof Symbol ? Symbol : {},
184
+ n = r.iterator || "@@iterator",
185
+ o = r.toStringTag || "@@toStringTag";
186
+ function i(r, n, o, i) {
187
+ var c = n && n.prototype instanceof Generator ? n : Generator,
188
+ u = Object.create(c.prototype);
189
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
190
+ var i,
191
+ c,
192
+ u,
193
+ f = 0,
194
+ p = o || [],
195
+ y = !1,
196
+ G = {
197
+ p: 0,
198
+ n: 0,
199
+ v: e,
200
+ a: d,
201
+ f: d.bind(e, 4),
202
+ d: function (t, r) {
203
+ return i = t, c = 0, u = e, G.n = r, a;
204
+ }
205
+ };
206
+ function d(r, n) {
207
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
208
+ var o,
209
+ i = p[t],
210
+ d = G.p,
211
+ l = i[2];
212
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
213
+ }
214
+ if (o || r > 1) return a;
215
+ throw y = !0, n;
216
+ }
217
+ return function (o, p, l) {
218
+ if (f > 1) throw TypeError("Generator is already running");
219
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
220
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
221
+ try {
222
+ if (f = 2, i) {
223
+ if (c || (o = "next"), t = i[o]) {
224
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
225
+ if (!t.done) return t;
226
+ u = t.value, c < 2 && (c = 0);
227
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
228
+ i = e;
229
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
230
+ } catch (t) {
231
+ i = e, c = 1, u = t;
232
+ } finally {
233
+ f = 1;
234
+ }
235
+ }
236
+ return {
237
+ value: t,
238
+ done: y
239
+ };
240
+ };
241
+ }(r, o, i), !0), u;
242
+ }
243
+ var a = {};
244
+ function Generator() {}
245
+ function GeneratorFunction() {}
246
+ function GeneratorFunctionPrototype() {}
247
+ t = Object.getPrototypeOf;
248
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
249
+ return this;
250
+ }), t),
251
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
252
+ function f(e) {
253
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
254
+ }
255
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
256
+ return this;
257
+ }), _regeneratorDefine(u, "toString", function () {
258
+ return "[object Generator]";
259
+ }), (_regenerator = function () {
260
+ return {
261
+ w: i,
262
+ m: f
263
+ };
264
+ })();
265
+ }
266
+ function _regeneratorDefine(e, r, n, t) {
267
+ var i = Object.defineProperty;
268
+ try {
269
+ i({}, "", {});
270
+ } catch (e) {
271
+ i = 0;
272
+ }
273
+ _regeneratorDefine = function (e, r, n, t) {
274
+ function o(r, n) {
275
+ _regeneratorDefine(e, r, function (e) {
276
+ return this._invoke(r, n, e);
277
+ });
278
+ }
279
+ r ? i ? i(e, r, {
280
+ value: n,
281
+ enumerable: !t,
282
+ configurable: !t,
283
+ writable: !t
284
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
285
+ }, _regeneratorDefine(e, r, n, t);
286
+ }
154
287
  function _setPrototypeOf(t, e) {
155
288
  return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
156
289
  return t.__proto__ = e, t;
@@ -193,130 +326,276 @@
193
326
  }
194
327
  }
195
328
 
196
- var _excluded$1 = ["component", "children", "render"];
197
- var isInit = false;
198
- var components = {}; // 组件
199
- var renderFactory = null;
200
- function _initComponent(name, comp) {
201
- if (!name) {
202
- 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;
203
397
  }
204
- if (typeof name === 'string') {
205
- if (components[name]) {
206
- console.log("[warning] Component ".concat(name, " is exist!"));
207
- 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;
208
409
  }
209
- components[name] = comp;
210
- return;
410
+ queryStr.push("".concat(attr, "=").concat(params[attr]));
211
411
  }
212
- Object.assign(components, name);
213
- }
214
- function _getComponent(name) {
215
- return components[name];
216
- }
217
- function clearComponents() {
218
- components = {};
219
- }
220
- function _initRenderFactory(fn) {
221
- 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);
222
417
  }
223
- function renderComponent(config, extraConfig) {
224
- if (!Array.isArray(config)) {
225
- 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;
226
434
  }
227
- var _component = [];
228
- config.forEach(function (item, i) {
229
- var _com = item.component,
230
- _children = item.children,
231
- _render = item.render,
232
- _props = _objectWithoutProperties(item, _excluded$1);
233
- var component = _getComponent(_com);
234
- if (!component && typeof _render !== 'function') {
235
- console.log("[warning] Component ".concat(_com, " is not registered!"));
236
- }
237
- var children = renderComponent(_children, extraConfig);
238
- var node = {
239
- component: component,
240
- children: children
241
- };
242
- _props.index = i;
243
- var props = Object.assign({}, extraConfig === null || extraConfig === void 0 ? void 0 : extraConfig.props, _props);
244
- if (typeof _render === 'function') {
245
- _component.push(_render({
246
- node: node,
247
- props: props
248
- }));
249
- } else if (typeof renderFactory === 'function') {
250
- _component.push(renderFactory({
251
- node: node,
252
- props: props
253
- }));
254
- } else {
255
- Object.assign(node, props);
256
- _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;
257
447
  }
258
- });
259
- return _component;
260
- }
261
- var Builder = /*#__PURE__*/function () {
262
- function Builder() {
263
- _classCallCheck(this, Builder);
264
448
  }
265
- 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, [{
266
463
  key: "init",
267
- value: function init(fn) {
268
- 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) {
269
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);
270
489
  }
271
- if (typeof fn === 'function') {
272
- 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;
273
512
  }
274
- 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;
275
549
  }
276
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, [{
277
565
  key: "initComponent",
278
566
  value: function initComponent(name, comp) {
279
- _initComponent(name, comp);
567
+ this._initComponent(name, comp);
280
568
  }
281
569
  }, {
282
570
  key: "getComponents",
283
571
  value: function getComponents() {
284
- return _objectSpread2({}, components);
572
+ return _objectSpread2({}, this._components);
285
573
  }
286
574
  }, {
287
575
  key: "getComponent",
288
576
  value: function getComponent(name) {
289
- return _getComponent(name);
577
+ return this._getComponent(name);
290
578
  }
291
579
  }, {
292
580
  key: "hasComponent",
293
581
  value: function hasComponent(name) {
294
- return !!_getComponent(name);
582
+ return !!this._getComponent(name);
295
583
  }
296
584
  }, {
297
585
  key: "initRenderFactory",
298
586
  value: function initRenderFactory(fn) {
299
- _initRenderFactory(fn);
300
- }
301
- }, {
302
- key: "initRequest",
303
- value: function initRequest() {
304
- //
587
+ this._initRenderFactory(fn);
305
588
  }
306
589
  }, {
307
590
  key: "render",
308
591
  value: function render(config, extraConfig) {
309
- return renderComponent(config, extraConfig);
310
- }
311
- }, {
312
- key: "clear",
313
- value: function clear() {
314
- clearComponents();
315
- renderFactory = null;
316
- isInit = false;
592
+ return this._renderComponent(config, extraConfig);
317
593
  }
318
594
  }]);
319
- }();
595
+ }(BaseBuilder);
596
+ Builder.create = function (args) {
597
+ return new Builder(args);
598
+ };
320
599
 
321
600
  var CacheUtil = /*#__PURE__*/function () {
322
601
  function CacheUtil(args) {
@@ -326,23 +605,23 @@
326
605
  return _createClass(CacheUtil, [{
327
606
  key: "_init",
328
607
  value: function _init(args) {
329
- this.cache = Object.assign({}, args);
608
+ this._data = Object.assign({}, args);
330
609
  }
331
610
  }, {
332
611
  key: "set",
333
612
  value: function set(key, value) {
334
- this.cache[key] = value;
613
+ this._data[key] = value;
335
614
  }
336
615
  }, {
337
616
  key: "get",
338
617
  value: function get(key) {
339
- var _this$cache;
340
- 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];
341
620
  }
342
621
  }, {
343
622
  key: "clear",
344
623
  value: function clear(key) {
345
- delete this.cache[key];
624
+ delete this._data[key];
346
625
  }
347
626
  }]);
348
627
  }();
@@ -357,13 +636,13 @@
357
636
  value: function _init(args) {
358
637
  var _args$__ASYNC_EXECUTE;
359
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;
360
- this.events = new Map();
361
- this.firstevents = new Map();
639
+ this._events = new Map();
640
+ this._firstevents = new Map();
362
641
  }
363
642
  }, {
364
643
  key: "on",
365
644
  value: function on(name, callback, context) {
366
- var fnList = this.events.get(name);
645
+ var fnList = this._events.get(name);
367
646
  if (!Array.isArray(fnList)) {
368
647
  fnList = [];
369
648
  }
@@ -371,12 +650,12 @@
371
650
  callback: callback,
372
651
  context: context
373
652
  });
374
- this.events.set(name, fnList);
653
+ this._events.set(name, fnList);
375
654
  }
376
655
  }, {
377
656
  key: "onFirst",
378
657
  value: function onFirst(name, callback, context) {
379
- var fnList = this.firstevents.get(name);
658
+ var fnList = this._firstevents.get(name);
380
659
  if (!Array.isArray(fnList)) {
381
660
  fnList = [];
382
661
  }
@@ -384,7 +663,7 @@
384
663
  callback: callback,
385
664
  context: context
386
665
  });
387
- this.firstevents.set(name, fnList);
666
+ this._firstevents.set(name, fnList);
388
667
  }
389
668
  }, {
390
669
  key: "execute",
@@ -392,8 +671,8 @@
392
671
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
393
672
  args[_key - 1] = arguments[_key];
394
673
  }
395
- var events = this.events.get(name);
396
- var firstevents = this.firstevents.get(name);
674
+ var events = this._events.get(name);
675
+ var firstevents = this._firstevents.get(name);
397
676
  if (!events && !firstevents) {
398
677
  return true;
399
678
  }
@@ -411,8 +690,8 @@
411
690
  }, {
412
691
  key: "un",
413
692
  value: function un(name, callback) {
414
- this._unEvents(name, callback, this.events);
415
- this._unEvents(name, callback, this.firstevents);
693
+ this._unEvents(name, callback, this._events);
694
+ this._unEvents(name, callback, this._firstevents);
416
695
  }
417
696
  }, {
418
697
  key: "_unEvents",
@@ -435,12 +714,12 @@
435
714
  }, {
436
715
  key: "hasEvent",
437
716
  value: function hasEvent(name) {
438
- var _this$events$get, _this$firstevents$get;
717
+ var _this$_events$get, _this$_firstevents$ge;
439
718
  if (!name) {
440
719
  return 0;
441
720
  }
442
- var eventsLen = ((_this$events$get = this.events.get(name)) === null || _this$events$get === void 0 ? void 0 : _this$events$get.length) || 0;
443
- 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;
444
723
  return eventsLen + firsteventsLen;
445
724
  }
446
725
  }, {
@@ -533,8 +812,8 @@
533
812
  }, {
534
813
  key: "_asyncPromiseExecute",
535
814
  value: function _asyncPromiseExecute(name, resolve, reject, args) {
536
- var events = this.events.get(name);
537
- var firstevents = this.firstevents.get(name);
815
+ var events = this._events.get(name);
816
+ var firstevents = this._firstevents.get(name);
538
817
  if ((Array.isArray(events) ? !events.length : !events) && (Array.isArray(firstevents) ? !firstevents.length : !firstevents)) {
539
818
  return resolve === null || resolve === void 0 ? void 0 : resolve();
540
819
  }
@@ -593,9 +872,9 @@
593
872
  var returnData = this.execute.apply(this, args);
594
873
  if (returnData instanceof Promise) {
595
874
  var self = this;
596
- /**
597
- * 背景参考下面的else注释,当第二次命中这里的时候,会在promise执行的时候直接then了,因为没有重新走一遍判定,这里直接执行了callback
598
- * 解决方案:想着是想办法把then里的代码作为callback传进去最后在执行,但是没想到方案
875
+ /**
876
+ * 背景参考下面的else注释,当第二次命中这里的时候,会在promise执行的时候直接then了,因为没有重新走一遍判定,这里直接执行了callback
877
+ * 解决方案:想着是想办法把then里的代码作为callback传进去最后在执行,但是没想到方案
599
878
  */
600
879
  returnData.then(function () {
601
880
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
@@ -608,9 +887,9 @@
608
887
  }
609
888
  });
610
889
  } else {
611
- /*
612
- 这里是因为历史代码没有考虑promise得情况 导致直接使用!returnData做结果判定,但是undefined也会命中false 导致后续执行阻断,不做callback了,所以会有问题,加了下面代码还是有问题,因为如果命中了promise得话没有返回值
613
- 导致命中不了returnData === false 导致阻断,所以上面execute里promise的时候将整个results返回,但是加了还有另外的问题,就是如果有两个分开的promise 会导致第一次好使,第二次命中了上面的if
890
+ /*
891
+ 这里是因为历史代码没有考虑promise得情况 导致直接使用!returnData做结果判定,但是undefined也会命中false 导致后续执行阻断,不做callback了,所以会有问题,加了下面代码还是有问题,因为如果命中了promise得话没有返回值
892
+ 导致命中不了returnData === false 导致阻断,所以上面execute里promise的时候将整个results返回,但是加了还有另外的问题,就是如果有两个分开的promise 会导致第一次好使,第二次命中了上面的if
614
893
  */
615
894
  // if (window.__ASYNC_EXECUTE__ ? returnData === false : !returnData) {
616
895
  if (!returnData) {
@@ -675,152 +954,62 @@
675
954
  }, {
676
955
  key: "clearEvents",
677
956
  value: function clearEvents() {
678
- this.events.clear();
679
- this.firstevents.clear();
957
+ this._events.clear();
958
+ this._firstevents.clear();
680
959
  }
681
960
  }]);
682
961
  }();
683
962
 
684
- function QueryString(_url) {
685
- this.pathname = '';
686
- this.query = {};
963
+ var _excluded = ["onBeforeRequest", "_onAfterRequest"],
964
+ _excluded2 = ["_onBeforeRequest", "onAfterRequest"];
965
+ function _getUrl(_url, params) {
687
966
  var url = _url;
688
- this.init = function () {
689
- if (!url) {
690
- url = location.search;
967
+ return url;
968
+ }
969
+ function getAllResponseHeaders(payload) {
970
+ var xhr = payload.xhr;
971
+ var headerString = xhr.getAllResponseHeaders();
972
+ var headers = {};
973
+ headerString.split('\r\n').map(function (header) {
974
+ var _header$split = header.split(': '),
975
+ _header$split2 = _slicedToArray(_header$split, 2),
976
+ key = _header$split2[0],
977
+ value = _header$split2[1];
978
+ headers[key] = value;
979
+ });
980
+ return headers;
981
+ }
982
+ var AjaxRequestManager = {
983
+ _xhrs: [],
984
+ _jsonps: {
985
+ index: 0
986
+ },
987
+ // eslint-disable-next-line object-shorthand
988
+ doRequest: function doRequest(_options) {
989
+ var _ref = _options || {},
990
+ onBeforeRequest = _ref.onBeforeRequest;
991
+ _ref._onAfterRequest;
992
+ var options = _objectWithoutProperties(_ref, _excluded);
993
+ var method = options.method || 'GET';
994
+ var url = _getUrl(options.url);
995
+ var headers;
996
+ try {
997
+ if (options !== null && options !== void 0 && options.requestHeaders) {
998
+ headers = options.requestHeaders;
999
+ options.requestHeaders = undefined;
1000
+ delete options.requestHeaders;
1001
+ }
1002
+ } catch (e) {
1003
+ console.log('[ajax]: [doRequest]: options["requestHeaders"] ERR : ', e);
691
1004
  }
692
- var index1 = url.indexOf('?');
693
- var index2 = url.indexOf('#');
694
- if (index1 >= 0) {
695
- this.pathname = url.substr(0, index1);
696
- url = index2 < 0 ? url.substr(index1 + 1) : url.substring(index1 + 1, index2);
697
- if (url.length > 0) {
698
- url = url.replace(/\+/g, ' ');
699
- var params = url.split('&');
700
- for (var i = 0, len = params.length; i < len; i++) {
701
- var param = params[i] || '';
702
- if (param) {
703
- var index = param.indexOf('=');
704
- var key = '';
705
- var value = '';
706
- if (index < 0) {
707
- key = window.decode(param);
708
- value = key;
709
- } else {
710
- key = window.decode(param.substr(0, index));
711
- value = window.decode(param.substr(index + 1));
712
- }
713
- this.query[key] = value;
714
- }
715
- }
1005
+ try {
1006
+ if (options.params && options.params.requestHeaders) {
1007
+ headers = options.params.requestHeaders;
1008
+ options.params.requestHeaders = undefined;
1009
+ delete options.params.requestHeaders;
716
1010
  }
717
- } else {
718
- this.pathname = url;
719
- }
720
- };
721
- this.set = function (key, value) {
722
- this.query[key] = value;
723
- };
724
- this.get = function (key) {
725
- return this.query[key];
726
- };
727
- this.del = function (key) {
728
- delete this.query[key];
729
- };
730
- this.has = function (key) {
731
- return this.query[key] != null;
732
- };
733
- this.toStr = function () {
734
- var items = ['?'];
735
- for (var key in this.query) {
736
- items.push(encodeURIComponent(key));
737
- items.push('=');
738
- items.push(encodeURIComponent(this.query[key]));
739
- items.push('&');
740
- }
741
- if (items.length === 1) {
742
- return '';
743
- }
744
- items.splice(items.length - 1, 1);
745
- return items.join('');
746
- };
747
- this.init();
748
- }
749
- String.prototype['equalsIgnoreCase'] = function (str) {
750
- if (str == null) {
751
- return false;
752
- }
753
- return this.toLowerCase() === str.toLowerCase();
754
- };
755
- function _appendUrl(restUrl, params) {
756
- if (!params) {
757
- return restUrl;
758
- }
759
- var queryStr = [];
760
- var queryUrl = new QueryString(restUrl);
761
- for (var attr in params) {
762
- if (queryUrl.get(attr)) {
763
- continue;
764
- }
765
- queryStr.push("".concat(attr, "=").concat(params[attr]));
766
- }
767
- if (!queryStr.length) {
768
- return restUrl;
769
- }
770
- var queryString = queryStr.join('&');
771
- return restUrl.indexOf('?') >= 0 ? "".concat(restUrl, "&").concat(queryString) : "".concat(restUrl, "?").concat(queryString);
772
- }
773
-
774
- var _excluded = ["onBeforeRequest", "_onAfterRequest"],
775
- _excluded2 = ["_onBeforeRequest", "onAfterRequest"];
776
- function _getUrl(_url, params) {
777
- var url = _url;
778
- return url;
779
- }
780
- function getAllResponseHeaders(payload) {
781
- var xhr = payload.xhr;
782
- var headerString = xhr.getAllResponseHeaders();
783
- var headers = {};
784
- headerString.split('\r\n').map(function (header) {
785
- var _header$split = header.split(': '),
786
- _header$split2 = _slicedToArray(_header$split, 2),
787
- key = _header$split2[0],
788
- value = _header$split2[1];
789
- headers[key] = value;
790
- });
791
- return headers;
792
- }
793
- var AjaxRequestManager = {
794
- _xhrs: [],
795
- _jsonps: {
796
- index: 0
797
- },
798
- // eslint-disable-next-line object-shorthand
799
- doRequest: function doRequest(_options) {
800
- var _ref = _options || {},
801
- onBeforeRequest = _ref.onBeforeRequest;
802
- _ref._onAfterRequest;
803
- var options = _objectWithoutProperties(_ref, _excluded);
804
- var method = options.method || 'GET';
805
- var url = _getUrl(options.url);
806
- var headers;
807
- try {
808
- if (options !== null && options !== void 0 && options.requestHeaders) {
809
- headers = options.requestHeaders;
810
- options.requestHeaders = undefined;
811
- delete options.requestHeaders;
812
- }
813
- } catch (e) {
814
- console.log('[ajax]: [doRequest]: options["requestHeaders"] ERR : ', e);
815
- }
816
- try {
817
- if (options.params && options.params.requestHeaders) {
818
- headers = options.params.requestHeaders;
819
- options.params.requestHeaders = undefined;
820
- delete options.params.requestHeaders;
821
- }
822
- } catch (e) {
823
- console.log('[ajax]: [doRequest]: options.params["requestHeaders"] ERR : ', e);
1011
+ } catch (e) {
1012
+ console.log('[ajax]: [doRequest]: options.params["requestHeaders"] ERR : ', e);
824
1013
  }
825
1014
  var queryJson = null;
826
1015
  if (method.equalsIgnoreCase('get') || method.equalsIgnoreCase('delete')) {
@@ -1115,7 +1304,7 @@
1115
1304
  return ajax(url, options);
1116
1305
  };
1117
1306
 
1118
- var BaseModel = /*#__PURE__*/function () {
1307
+ var BaseModel$1 = /*#__PURE__*/function () {
1119
1308
  function BaseModel(args) {
1120
1309
  _classCallCheck(this, BaseModel);
1121
1310
  this._init(args);
@@ -1291,11 +1480,11 @@
1291
1480
  components.splice(index, 1);
1292
1481
  }
1293
1482
 
1294
- /**
1295
- * 统一的「写属性 + 通知组件」逻辑。
1296
- * 组件实现了 setXxx(如 setValue)就直接调;没实现则退回 setState({ [name]: value })。
1297
- * 原实现里只有 setVisible / setDisabled 有这层兜底,setValue 漏了,
1298
- * 导致模型改值永远传不到受控组件上。
1483
+ /**
1484
+ * 统一的「写属性 + 通知组件」逻辑。
1485
+ * 组件实现了 setXxx(如 setValue)就直接调;没实现则退回 setState({ [name]: value })。
1486
+ * 原实现里只有 setVisible / setDisabled 有这层兜底,setValue 漏了,
1487
+ * 导致模型改值永远传不到受控组件上。
1299
1488
  */
1300
1489
  }, {
1301
1490
  key: "_applyState",
@@ -1534,56 +1723,16 @@
1534
1723
  }]);
1535
1724
  }();
1536
1725
 
1537
- var FilterModel = /*#__PURE__*/function (_BaseModel) {
1538
- function FilterModel() {
1539
- _classCallCheck(this, FilterModel);
1540
- return _callSuper(this, FilterModel, arguments);
1541
- }
1542
- _inherits(FilterModel, _BaseModel);
1543
- return _createClass(FilterModel, [{
1544
- key: "mounted",
1545
- value: function mounted() {
1546
- var _this = this;
1547
- var _conditions = this.get('conditions');
1548
- var params = {};
1549
- _conditions.forEach(function (r) {
1550
- _this.get(r.name);
1551
- params[r.name] = r.defaultValue;
1552
- });
1553
- this._set_data('params', params);
1554
- }
1555
- }, {
1556
- key: "unmounted",
1557
- value: function unmounted() {
1558
- this._set_data('params', {});
1559
- this._set_data('conditions', []);
1560
- }
1561
- }, {
1562
- key: "getParams",
1563
- value: function getParams() {
1564
- var _this2 = this;
1565
- var params = {};
1566
- var conditions = this.get('conditions');
1567
- conditions.forEach(function (r) {
1568
- var model = _this2.get(r.name);
1569
- params[r.name] = model === null || model === void 0 ? void 0 : model.getValue();
1570
- });
1571
- this._set_data('params', params);
1572
- return params;
1573
- }
1574
- }, {
1575
- key: "search",
1576
- value: function search() {
1577
- var params = this.getParams();
1578
- this.execute('search', params);
1579
- }
1580
- }]);
1581
- }(BaseModel);
1582
-
1583
- var SimpleModel = /*#__PURE__*/function (_BaseModel) {
1584
- function SimpleModel(args) {
1726
+ var SimpleModel$1 = /*#__PURE__*/function (_BaseModel) {
1727
+ function SimpleModel() {
1728
+ var _this;
1585
1729
  _classCallCheck(this, SimpleModel);
1586
- return _callSuper(this, SimpleModel, [args]);
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;
1587
1736
  }
1588
1737
  _inherits(SimpleModel, _BaseModel);
1589
1738
  return _createClass(SimpleModel, [{
@@ -1593,8 +1742,8 @@
1593
1742
  }
1594
1743
  }, {
1595
1744
  key: "setDisabled",
1596
- value: function setDisabled(v) {
1597
- return this.setState('disabled', !!v);
1745
+ value: function setDisabled(value, ctrlName) {
1746
+ this._applyState('disabled', value, ctrlName);
1598
1747
  }
1599
1748
  }, {
1600
1749
  key: "getReadonly",
@@ -1603,63 +1752,20 @@
1603
1752
  }
1604
1753
  }, {
1605
1754
  key: "setReadonly",
1606
- value: function setReadonly(v) {
1607
- this.setState('readonly', !!v);
1755
+ value: function setReadonly(value, ctrlName) {
1756
+ this._applyState('readonly', value, ctrlName);
1608
1757
  }
1609
1758
  }]);
1610
- }(BaseModel);
1759
+ }(BaseModel$1);
1611
1760
 
1612
- /**
1613
- * models - GridModel
1614
- *
1615
- * 参照中台 `mdf-cube/src/models/GridModel.js`(`cb.models.register('GridModel')`)重写,
1616
- * 把它的约定搬进我们这套 devfab 的 ui-model 体系:
1617
- *
1618
- * 1. 两层数据:`dataSource`(全量原始数据)+ `rows`(当前展示行,本地模式下是 dataSource 的分页切片);
1619
- * 2. 行状态与数据同序:`rowsDataState[i]` 对应 `dataSource[i]`,取值见 DataStates;
1620
- * 3. 内部字段由 `innerUsedAttrs` 统一定义:`_id` / `_selected` / `_status`;
1621
- * 4. 列是 **object map**(key = field),不是数组 —— 给 vxe-grid 渲染时用 `getColumnList()` 转数组;
1622
- * 5. 分页状态叫 `pageInfo`(pageIndex/pageSize/pageCount/recordCount),不叫 pager;
1623
- * 6. 行、单元格、列都可以挂状态:`rowState` / `cellState`;
1624
- * 7. 选中分「当前页 `_selected` 标记」与「跨页选中缓存(selectedKeysSet + selectedRowsMap)」两层。
1625
- *
1626
- * 与中台实现不同的地方(有意为之,都有注释说明):
1627
- * - 中台的取数配置走 `proxyConfig` + `setProxy`,我们直接保留 `proxyConfig.load`(函数或 url),
1628
- * 并兼容旧的 `dataSource: fn` / `cUrl` 写法;
1629
- * - 中台的 `setRows` 会把 `getShowRows()`(展示文案副本)推给组件,我们推**原始行对象**,
1630
- * 否则选中回灌、单元格编辑会落到副本上;
1631
- * - 中台的行模型(editRowModel / ReferModel / 特征 / 孙表)没有移植,这里只做行级与单元格级能力。
1632
- */
1633
- var DataStates = {
1634
- Unchanged: '',
1635
- Insert: 'Insert',
1636
- Update: 'Update',
1637
- Delete: 'Delete'
1638
- };
1639
1761
  var DEFAULT_PAGE_SIZE = 20;
1640
1762
  var isArray = Array.isArray;
1641
- var isEmpty = function isEmpty(value) {
1642
- return value === undefined || value === null || value === '';
1643
- };
1644
- var isEmptyObject = function isEmptyObject(value) {
1645
- return !value || Object.keys(value).length === 0;
1646
- };
1647
- function cloneDeep(value) {
1648
- if (isArray(value)) return value.map(cloneDeep);
1649
- if (value instanceof Date) return new Date(value.getTime());
1650
- if (value && _typeof(value) === 'object') {
1651
- var result = {};
1652
- for (var key in value) result[key] = cloneDeep(value[key]);
1653
- return result;
1654
- }
1655
- return value;
1656
- }
1657
1763
 
1658
1764
  // ---------------- 列:数组 ↔ object map 归一 ----------------
1659
1765
 
1660
- /**
1661
- * 列统一收敛成 object map(key = field),与中台一致。
1662
- * 入参既接受数组(我们自己写 meta 的习惯),也接受后端下发的 map。
1766
+ /**
1767
+ * 列统一收敛成 object map(key = field),与中台一致。
1768
+ * 入参既接受数组(我们自己写 meta 的习惯),也接受后端下发的 map。
1663
1769
  */
1664
1770
  function normalizeColumns(columns) {
1665
1771
  var map = {};
@@ -1671,41 +1777,42 @@
1671
1777
  });
1672
1778
  list.forEach(function (column, index) {
1673
1779
  if (!column) return;
1674
- var field = column.field || column.cCaption || column.cFieldName || "col_".concat(index);
1780
+ var field = column.field || column.cFieldName || column.cName || "col_".concat(index);
1675
1781
  map[field] = _objectSpread2(_objectSpread2({}, column), {}, {
1676
1782
  field: field,
1677
- // 中台里列有 fieldName / cCaption 两套命名,这里都兜住
1678
- fieldName: column.fieldName || field,
1679
- cCaption: column.cCaption || field,
1783
+ label: column.label || column.title || column.cCaption || field,
1680
1784
  index: column.index === undefined ? index : column.index
1681
1785
  });
1682
1786
  });
1683
1787
  return map;
1684
1788
  }
1685
1789
 
1686
- /** 给行补内部 id(没有主键时用 rowId_ 前缀,与中台一致) */
1687
- function setIds() {
1688
- var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1689
- var idFlag = this.getIdFlag();
1690
- var keyField = this.getRowKeyField();
1691
- var seq = this._get_data('rowIdSeq') || 0;
1692
- rows.forEach(function (row) {
1693
- if (!row || row[idFlag] !== undefined) return;
1694
- var key = row[keyField];
1695
- if (key !== undefined && key !== null && key !== '') {
1696
- row[idFlag] = String(key);
1697
- } else {
1698
- seq += 1;
1699
- row[idFlag] = "rowId_".concat(seq);
1700
- }
1701
- });
1702
- this._set_data('rowIdSeq', seq);
1703
- return rows;
1790
+ // ---------------- 响应体:从各种后端结构里取行与总数 ----------------
1791
+
1792
+ function resolveRowsData(res) {
1793
+ if (!res) return [];
1794
+ if (isArray(res)) return res;
1795
+ if (isArray(res.data)) return res.data;
1796
+ if (isArray(res.records)) return res.records;
1797
+ if (isArray(res.list)) return res.list;
1798
+ if (isArray(res.rows)) return res.rows;
1799
+ var nested = res.data && _typeof(res.data) === 'object' ? res.data : res.result;
1800
+ if (isArray(nested)) return nested;
1801
+ if (nested && _typeof(nested) === 'object') return nested.records || nested.list || nested.rows || nested.data || [];
1802
+ return [];
1704
1803
  }
1705
1804
 
1706
1805
  // ---------------- 初始状态 ----------------
1707
1806
 
1708
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
+ };
1709
1816
  return {
1710
1817
  columns: {},
1711
1818
  dataSource: [],
@@ -1714,23 +1821,16 @@
1714
1821
  dataSourceMode: 'local',
1715
1822
  columnMode: 'local',
1716
1823
  editMode: 'cell',
1824
+ rowKeyField: 'id',
1717
1825
  cellState: {},
1718
1826
  rowState: {},
1719
- showCheckBox: true,
1827
+ showCheckBox: false,
1720
1828
  multiple: true,
1721
1829
  showRowNo: true,
1722
1830
  // 默认显示序号
1723
1831
  pagination: true,
1724
- pageInfo: {
1725
- pageIndex: 1,
1726
- pageSize: DEFAULT_PAGE_SIZE,
1727
- pageCount: 0
1728
- },
1729
- innerUsedAttrs: {
1730
- id: '_id',
1731
- selected: '_selected',
1732
- status: '_status'
1733
- },
1832
+ pageInfo: _defineProperty(_defineProperty(_defineProperty({}, innerUsedAttrs.pageIndex, 1), innerUsedAttrs.pageSize, DEFAULT_PAGE_SIZE), innerUsedAttrs.pageCount, 0),
1833
+ innerUsedAttrs: innerUsedAttrs,
1734
1834
  multiRowModel: false,
1735
1835
  // 表格多行模型
1736
1836
  editRowModels: {},
@@ -1742,238 +1842,92 @@
1742
1842
  defaultRowDatas: new Map()
1743
1843
  };
1744
1844
  }
1745
-
1746
- /**
1747
- * 取数配置:中台叫 proxyConfig({ load: fn|url }),这里兼容三种写法
1748
- * - `proxyConfig: { load }`
1749
- * - `dataSource: fn`(旧写法)
1750
- * - `cUrl: '/xxx'`
1751
- */
1752
1845
  function resolveProxyConfig() {
1753
1846
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1754
1847
  var proxy = _objectSpread2({}, props.proxyConfig || {});
1755
- if (typeof props.dataSource === 'function') proxy.load = proxy.load || props.dataSource;
1756
- if (typeof props.cUrl === 'string') proxy.load = proxy.load || props.cUrl;
1757
- if (!proxy.load && typeof props.url === 'string') proxy.load = props.url;
1758
1848
  return proxy;
1759
1849
  }
1760
-
1761
- /* code-link-enable */
1762
- var showPageInner = function showPageInner(proxyConfig, queryParams, callback, refresh, needLoadPageination, backQueryPageCount, extraProps) {
1850
+ function _getData(proxyConfig, queryParams, callback) {
1763
1851
  var _this = this;
1764
- this.promiseExecute('beforeBatchModifyPull', function () {
1765
- // this.rebuildProxyConfig(proxyConfig);
1852
+ this.promiseExecute('beforeQuery', {
1853
+ proxyConfig: proxyConfig,
1854
+ queryParams: queryParams
1855
+ }, function () {
1856
+ var self = _this;
1766
1857
  var proxy = _this.setProxy({
1767
1858
  queryData: proxyConfig
1768
1859
  });
1769
- var defaultParams = {
1770
- page: {
1771
- pageSize: _this.getPageSize(),
1772
- pageIndex: _this.getPageIndex()
1773
- }
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())
1774
1864
  };
1775
- if (!defaultParams.page.pageSize) {
1776
- _this.setPageSize(10);
1777
- defaultParams.page.pageSize = 10;
1778
- }
1779
- var bLoadPagination = _this._get_data('bLoadPagination');
1780
- if (!bLoadPagination && !needLoadPageination) defaultParams.page.totalCount = 1;
1781
- var delayLoadPageInfo = _this._get_data('delayLoadPageInfo');
1782
- if (bLoadPagination && delayLoadPageInfo) {
1783
- if (refresh) {
1784
- _this.setState('showDelayPagination', true);
1785
- }
1786
- defaultParams.page.totalCount = 1;
1787
- }
1788
- var params = Object.assign(defaultParams, queryParams);
1865
+ var params = Object.assign(queryParams, currentPageInfo);
1789
1866
  _this.setCache('proxyCache', {
1790
1867
  proxyConfig: proxyConfig,
1791
- params: params
1868
+ params: params,
1869
+ callback: callback
1792
1870
  });
1793
- var queryCount = 0;
1794
- var responseData = {};
1795
- var viewModel = _this.getRootParent();
1796
- var self = _this;
1797
-
1798
- // 增加queryId解决 报表临时表锁问题
1799
- var queryId = new Date().valueOf();
1800
- params.queryId = queryId;
1871
+ _this.getRootParent();
1801
1872
  var queryDataCallback = function queryDataCallback(err, result, callBackMsg, errorDetail) {
1802
- var _this$getParent, _this$getParent$getPa;
1803
- setTimeout(function () {
1804
- self.clearCache('isGridInLoading');
1805
- }, 0);
1806
- viewModel === null || viewModel === void 0 || viewModel.clearCache('lazySearch');
1807
1873
  if (err) {
1808
- this.setState('showDelayPagination', false);
1809
- this.clearCache('setPageIndexFromBack');
1810
1874
  return;
1811
1875
  }
1812
- result = result || {}; // 容错处理null或者undefined情况
1813
1876
  this._set_data('dataSourceMode', 'remote'); // 处理请求过程中被修改
1814
- if (refresh && bLoadPagination && delayLoadPageInfo) {
1815
- queryCount++;
1816
- result = Object.assign(responseData, result);
1817
- }
1818
- var data = Array.isArray(result.recordList) ? result.recordList : [];
1819
- if ((!(bLoadPagination && delayLoadPageInfo) || queryCount === 2) && callback) {
1820
- callback.call(this, result, callBackMsg, errorDetail);
1821
- }
1822
- this.getCache('setPageIndexFromBack'); // 是否是从卡片页返回的
1823
- this.clearCache('setPageIndexFromBack');
1824
- if (!this.execute('beforeSetDataSource', data)) return;
1825
- var rowKeyField = this._get_data('rowKeyField');
1826
- var keyMap = {};
1827
- data.forEach(function (item) {
1828
- keyMap[item[rowKeyField]] = item;
1829
- });
1830
- this._set_data('keyMap', keyMap);
1831
- if (!refresh && this._get_data('override') === false) {
1832
- this._set_data('dataSource', this._get_data('dataSource').concat(data), true);
1833
- } else {
1834
- this._set_data('dataSource', data, true);
1835
- this.doPropertyChange('resetCellStatus');
1836
- this._set_data('cellState', {}, true);
1837
- this._set_data('rowState', {}, true);
1838
- }
1839
- // 存入当前model缓存便于client端搜索
1840
- this.setCache('currentGridData', data);
1841
- if (data.length) {
1842
- setIds.call(this, data);
1843
- }
1844
- this.initRowState();
1845
- // 修改缓存数据
1846
- setCachePaginationRowData.call(this, data);
1847
- this._get_data('sortParams');
1848
- var colFilterParams = this._get_data('colFilterParams');
1849
- this.showRows(null, !cb.utils.isEmptyObject(colFilterParams));
1850
- var pageInfo = this._get_data('pageInfo');
1851
- // bLoadPagination 优先级比 delayLoadPageInfo 高,bLoadPagination开启时值是false,所以第一项条件需要用 bLoadPagination = false 约束 delayLoadPageInfo = true 的情况
1852
- if (bLoadPagination && !delayLoadPageInfo && (this._get_data('bLoadPagination') || needLoadPageination)) {
1853
- pageInfo = {
1854
- pageSize: result.pageSize,
1855
- pageIndex: result.pageIndex,
1856
- pageCount: result.pageCount,
1857
- recordCount: result.recordCount
1858
- };
1859
- this.setPageInfo(pageInfo);
1860
- } else {
1861
- pageInfo.pageIndex = result.pageIndex;
1862
- pageInfo.from = 'showPageInner';
1863
- this.setPageInfo(pageInfo);
1864
- }
1865
- resetSelected.call(this);
1866
- if (!(((_this$getParent = this.getParent) === null || _this$getParent === void 0 || (_this$getParent = _this$getParent.call(this)) === null || _this$getParent === void 0 || (_this$getParent$getPa = _this$getParent.getParams) === null || _this$getParent$getPa === void 0 || (_this$getParent$getPa = _this$getParent$getPa.call(_this$getParent)) === null || _this$getParent$getPa === void 0 ? void 0 : _this$getParent$getPa.templateType) === 'splitview')) {
1867
- this._set_data('focusedRowIndex', -1); // 重置选中行
1868
- }
1869
- for (var _len = arguments.length, args = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++) {
1870
- args[_key - 4] = arguments[_key];
1871
- }
1872
- this.execute('afterSetDataSource', data, result.viewmodel, args === null || args === void 0 ? void 0 : args[1]); // 社保缴交节点翻页的时候需要改columns
1877
+ result = Object.assign({}, result);
1878
+ var data = resolveRowsData(result);
1879
+ this.execute('afterQueryData', result);
1880
+ callback === null || callback === void 0 || callback.call(this, data);
1873
1881
  };
1874
- {
1875
- if (viewModel.execute('beforeQueryData', params) === false) return;
1876
- self.setCache('lastGridFilterCondition', JSON.stringify(params === null || params === void 0 ? void 0 : params.condition));
1877
- var queryDataParams = _.cloneDeep(params);
1878
- proxy.queryData(queryDataParams, queryDataCallback, _this);
1879
- }
1880
- if (refresh && bLoadPagination && delayLoadPageInfo) {
1881
- var queryPageProxyConfig = JSON.parse(JSON.stringify(proxyConfig));
1882
- if (!queryPageProxyConfig.options) {
1883
- queryPageProxyConfig.options = {};
1884
- }
1885
- queryPageProxyConfig.options.mask = false;
1886
- var _callback = function _callback(pageInfo) {
1887
- queryCount++;
1888
- Object.assign(responseData, pageInfo);
1889
- if (queryCount === 2 && callback) {
1890
- callback.call(_this, responseData);
1891
- }
1892
- };
1893
- queryPageCount.call(_this, queryPageProxyConfig, params, function (pageInfo) {
1894
- _callback(pageInfo);
1895
- });
1896
- }
1882
+ if (_this.execute('beforeQueryData', params) === false) return;
1883
+ var queryDataParams = _.cloneDeep(params);
1884
+ proxy.queryData(queryDataParams, queryDataCallback, self);
1897
1885
  });
1898
- };
1899
-
1900
- /* 查询分页 */
1901
- function queryPageCount(proxyConfig, queryParams, callback) {
1902
- this.setCache('queryPageCountLoading', true);
1903
- // this.rebuildProxyConfig(proxyConfig);
1904
- var proxy = this.setProxy({
1905
- queryPageCount: _objectSpread2({}, proxyConfig)
1886
+ }
1887
+ function _setData(data) {
1888
+ if (!this.execute('beforeSetDataSource', data)) return;
1889
+ var rowKeyField = this.getRowKeyField();
1890
+ var keyMap = {};
1891
+ data.forEach(function (item) {
1892
+ keyMap[item[rowKeyField]] = item;
1906
1893
  });
1907
- var defaultParams = {
1908
- page: {
1909
- totalCount: -1
1910
- }
1911
- };
1912
- var params = Object.assign(true, queryParams, defaultParams);
1913
- if (!this.__queryPageCountRequestId) this.__queryPageCountRequestId = 0;
1914
- this.__queryPageCountRequestId++;
1915
- var queryPageCountCallback = function queryPageCountCallback(requestId, err, result) {
1916
- if (this.__queryPageCountRequestId !== requestId) return;
1917
- this.setCache('queryPageCountLoading', false);
1918
- this.setState('showDelayPagination', false);
1919
- if (err) {
1920
- var currentpageinfo = this._get_data('pageInfo');
1921
- if (currentpageinfo) {
1922
- // 接口报错时,分页组件信息保持原来的值
1923
- this.setPageInfo(currentpageinfo);
1924
- }
1925
- return;
1926
- }
1927
- result = result || {}; // 容错处理null或者undefined情况
1928
- var pageInfo = {
1929
- beginPageIndex: result.beginPageIndex,
1930
- endPageIndex: result.endPageIndex,
1931
- pageSize: result.pageSize,
1932
- pageIndex: result.pageIndex,
1933
- pageCount: result.pageCount,
1934
- recordCount: result.recordCount
1935
- };
1936
- if (callback) {
1937
- callback.call(this, pageInfo);
1938
- }
1939
- this.setPageInfo(pageInfo);
1940
- this.execute('afterQueryPageInfo', result);
1941
- };
1942
- proxy.queryPageCount(params, queryPageCountCallback.bind(this, this.__queryPageCountRequestId), this);
1894
+ this._set_data('keyMap', keyMap);
1895
+ this._set_data('dataSource', data, true);
1896
+ this.doPropertyChange('setDataSource');
1897
+ this.execute('afterSetDataSource', data);
1943
1898
  }
1944
1899
 
1945
1900
  // ============================================================
1946
1901
 
1947
- var GridModel = /*#__PURE__*/function (_BaseModel) {
1902
+ var GridModel$1 = /*#__PURE__*/function (_BaseModel) {
1948
1903
  function GridModel() {
1949
1904
  var _this2;
1950
1905
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1951
1906
  _classCallCheck(this, GridModel);
1952
1907
  var data = _objectSpread2(_objectSpread2({}, createDefaultProps()), props);
1953
1908
  // `dataSource: fn` 是旧写法,含义是「取数函数」而不是「数据」,这里统一收敛掉
1954
- if (!isArray(data.dataSource)) data.dataSource = [];
1955
- if (!isArray(data.rows)) data.rows = [];
1909
+ if (!isArray(data.dataSource)) {
1910
+ data.dataSource = [];
1911
+ }
1912
+ if (!isArray(data.rows)) {
1913
+ data.rows = [];
1914
+ }
1956
1915
  var proxyConfig = resolveProxyConfig(props);
1957
1916
  data.proxyConfig = proxyConfig;
1958
1917
  // 有取数配置就是服务端分页,否则按静态数据在前端分页
1959
- data.dataSourceMode = props.dataSourceMode || (proxyConfig.load ? 'remote' : 'local');
1960
- // 静态数据:cData / data 数组
1961
- var seed = props.cData || (isArray(props.data) ? props.data : null);
1918
+ data.dataSourceMode = props.dataSourceMode || data.dataSourceMode;
1962
1919
  _this2 = _callSuper(this, GridModel, [data]);
1963
- _this2.initPageInfo(props.cPage || props.page);
1920
+ _defineProperty(_this2, "modelType", 'GridModel');
1964
1921
  _this2.initColumns(data.columns);
1965
- _this2.initRowState();
1922
+ _this2.initPageInfo(props.cPage || props.page);
1966
1923
  _this2.afterInit();
1967
- if (seed) _this2.setDataSource(seed);
1968
1924
  return _this2;
1969
1925
  }
1970
-
1971
- // 中台在 afterInit 里做主子表/行模型初始化,我们这里只留一个扩展点给业务继承
1972
1926
  _inherits(GridModel, _BaseModel);
1973
1927
  return _createClass(GridModel, [{
1974
1928
  key: "afterInit",
1975
1929
  value: function afterInit() {
1976
- if (this._get_data('parentRelation') === 'single') this._set_data('defaultSelectedRowIndexes', true);
1930
+ this.execute('afterInit');
1977
1931
  }
1978
1932
  }, {
1979
1933
  key: "initColumns",
@@ -1987,65 +1941,25 @@
1987
1941
  value: function initPageInfo() {
1988
1942
  var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1989
1943
  var pageInfo = _objectSpread2({}, this.getPageInfo());
1990
- pageInfo.pageIndex = page.pageNo || page.pageIndex || pageInfo.pageIndex || 1;
1991
- pageInfo.pageSize = page.pageSize || pageInfo.pageSize || DEFAULT_PAGE_SIZE;
1992
- // 中台习惯:不分页时把 pageSize 记成 -1
1993
- if (this.get('pagination') === false) pageInfo.pageSize = -1;
1994
- this.applyPageInfo(pageInfo);
1995
- }
1996
-
1997
- // 与 dataSource 同序的行状态,先铺平
1998
- }, {
1999
- key: "initRowState",
2000
- value: function initRowState() {
2001
- var _this3 = this;
2002
- var source = this._get_data('dataSource');
2003
- this._set_data('rowsDataState', (isArray(source) ? source : []).map(function (row) {
2004
- return (row === null || row === void 0 ? void 0 : row[_this3.getStatusFlag()]) || DataStates.Unchanged;
2005
- }), 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);
2006
1950
  }
2007
1951
 
2008
1952
  /* ========================= 内部字段 / 开关 ========================= */
2009
- }, {
2010
- key: "getInnerUsedAttrs",
2011
- value: function getInnerUsedAttrs() {
2012
- return this._get_data('innerUsedAttrs');
2013
- }
2014
- }, {
2015
- key: "getIdFlag",
2016
- value: function getIdFlag() {
2017
- return this.getInnerUsedAttrs().id;
2018
- }
2019
- }, {
2020
- key: "getSelectedFlag",
2021
- value: function getSelectedFlag() {
2022
- return this.getInnerUsedAttrs().selected;
2023
- }
2024
- }, {
2025
- key: "getStatusFlag",
2026
- value: function getStatusFlag() {
2027
- return this.getInnerUsedAttrs().status;
2028
- }
2029
1953
  }, {
2030
1954
  key: "getRowKeyField",
2031
1955
  value: function getRowKeyField() {
2032
1956
  return this._get_data('rowKeyField') || 'id';
2033
1957
  }
2034
- }, {
2035
- key: "getProxyConfig",
2036
- value: function getProxyConfig() {
2037
- return this._get_data('proxyConfig') || {};
2038
- }
2039
1958
  }, {
2040
1959
  key: "isRemote",
2041
1960
  value: function isRemote() {
2042
1961
  return this._get_data('dataSourceMode') === 'remote';
2043
1962
  }
2044
- }, {
2045
- key: "isPagination",
2046
- value: function isPagination() {
2047
- return !!this.get('pagination') && this.getPageSize() !== -1;
2048
- }
2049
1963
  }, {
2050
1964
  key: "getReadOnly",
2051
1965
  value: function getReadOnly() {
@@ -2056,6 +1970,20 @@
2056
1970
  value: function setReadOnly(readOnly) {
2057
1971
  this._applyState('readOnly', !!readOnly);
2058
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
+ }
2059
1987
  }, {
2060
1988
  key: "getParams",
2061
1989
  value: function getParams() {
@@ -2067,1217 +1995,150 @@
2067
1995
  this._set_data('params', params || {});
2068
1996
  }
2069
1997
  }, {
2070
- key: "setMeta",
2071
- value: function setMeta(meta) {
2072
- this._set_data('meta', meta);
1998
+ key: "getInnerUsedAttrs",
1999
+ value: function getInnerUsedAttrs() {
2000
+ return this._get_data('innerUsedAttrs');
2001
+ }
2002
+ }, {
2003
+ key: "get",
2004
+ value: function get() {
2005
+ return this.getInnerUsedAttrs().id;
2073
2006
  }
2074
2007
 
2075
- /* ============================= 列 ============================= */
2076
-
2077
- /** 与中台一致:返回 object map(深拷贝),而不是数组 */
2078
- }, {
2079
- key: "getColumns",
2080
- value: function getColumns(fields) {
2081
- var columns = this._get_data('columns') || {};
2082
- var result = {};
2083
- var keys = fields ? isArray(fields) ? fields : [fields] : Object.getOwnPropertyNames(columns);
2084
- keys.forEach(function (key) {
2085
- if (!columns[key]) return;
2086
- result[key] = _objectSpread2(_objectSpread2({}, columns[key]), {}, {
2087
- fieldName: columns[key].fieldName || key
2008
+ /* ======================= 数据写入 ======================= */
2009
+ }, {
2010
+ key: "setDataSource",
2011
+ value: function setDataSource(proxyConfig) {
2012
+ var _this3 = this;
2013
+ var queryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2014
+ var callback = arguments.length > 2 ? arguments[2] : undefined;
2015
+ if (this._get_data('dataSourceMode') === 'local') {
2016
+ var data = cb.utils.isArray(proxyConfig) ? proxyConfig : [];
2017
+ _setData(data);
2018
+ } else {
2019
+ if (!this.execute('beforeProxyLoad', queryParams)) return;
2020
+ this.setPageIndex(1);
2021
+ _getData.call(this, proxyConfig, queryParams, function (data) {
2022
+ _setData.call(_this3, data);
2023
+ callback === null || callback === void 0 || callback.call(_this3);
2088
2024
  });
2089
- });
2090
- return result;
2025
+ }
2091
2026
  }
2092
2027
  }, {
2093
- key: "getColumn",
2094
- value: function getColumn(field) {
2095
- var _this$_get_data;
2096
- var column = (_this$_get_data = this._get_data('columns')) === null || _this$_get_data === void 0 ? void 0 : _this$_get_data[field];
2097
- return column ? _objectSpread2(_objectSpread2({}, column), {}, {
2098
- fieldName: column.fieldName || field
2099
- }) : undefined;
2028
+ key: "reload",
2029
+ value: function reload() {
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;
2039
+ _getData.call(this, proxyConfig, queryParams, function (data) {
2040
+ callback === null || callback === void 0 || callback.call(_this4, data);
2041
+ });
2100
2042
  }
2043
+
2044
+ /* ======================== 数据(两层) ======================== */
2101
2045
  }, {
2102
- key: "hasColumn",
2103
- value: function hasColumn(field) {
2104
- return !!(this._get_data('columns') || {})[field];
2046
+ key: "getDataSource",
2047
+ value: function getDataSource() {
2048
+ var source = this._get_data('dataSource') || [];
2049
+ return source;
2105
2050
  }
2051
+
2052
+ /**
2053
+ * 数据出口,签名与中台一致,但语义容易踩坑,这里写清楚:
2054
+ * - `getData()` → 全量 dataSource(提交/保存用,保留 _status,剔除 _selected)
2055
+ * - `getData(true)` → 当前页 rows(视图用,剔除 _status / _selected)
2056
+ * - `getAllData()` → 等于 getData(true),仅为对齐中台签名而保留
2057
+ * - `getPageData()` → 等于 getData(true),语义更直白的别名
2058
+ */
2106
2059
  }, {
2107
- key: "getColumnList",
2108
- value: function getColumnList(fields) {
2109
- var columns = this.getColumns(fields);
2110
- return Object.keys(columns).sort(function (a, b) {
2111
- return (columns[a].index || 0) - (columns[b].index || 0);
2112
- }).map(function (key) {
2113
- return columns[key];
2114
- });
2060
+ key: "getData",
2061
+ value: function getData(view, realRows) {
2062
+ var rows = view || realRows ? this._get_data('rows') : this._get_data('dataSource');
2063
+ return rows;
2115
2064
  }
2116
2065
  }, {
2117
- key: "getVisibleColumns",
2118
- value: function getVisibleColumns(fields) {
2119
- return this.getColumnList(fields).filter(function (column) {
2120
- return column.bHidden !== true && column.bShowIt !== false;
2121
- });
2066
+ key: "getAllData",
2067
+ value: function getAllData() {
2068
+ return this.getData(true);
2122
2069
  }
2123
2070
  }, {
2124
- key: "setColumns",
2125
- value: function setColumns(columns) {
2126
- if (!columns) return;
2127
- this._applyState('columns', normalizeColumns(columns));
2071
+ key: "clear",
2072
+ value: function clear() {
2073
+ this._set_data('dataSource', [], true);
2074
+ this._set_data('rows', [], true);
2128
2075
  }
2129
2076
  }, {
2130
- key: "setColumnMode",
2131
- value: function setColumnMode(mode) {
2132
- this._set_data('columnMode', mode === 'remote' ? 'remote' : 'local', true);
2077
+ key: "getPageInfo",
2078
+ value: function getPageInfo() {
2079
+ return this._get_data('pageInfo') || createDefaults().pageInfo;
2133
2080
  }
2134
2081
  }, {
2135
- key: "addColumns",
2136
- value: function addColumns(columns) {
2137
- var map = normalizeColumns(columns);
2138
- this._applyState('columns', _objectSpread2(_objectSpread2({}, this._get_data('columns') || {}), map));
2082
+ key: "getPageIndex",
2083
+ value: function getPageIndex() {
2084
+ var pageIndexField = this._get_data('innerUsedAttrs').pageIndex;
2085
+ return this.getPageInfo()[pageIndexField];
2139
2086
  }
2140
2087
  }, {
2141
- key: "resetColumns",
2142
- value: function resetColumns(columns) {
2143
- this.setColumns(columns || this.get('cColumns'));
2088
+ key: "getPageSize",
2089
+ value: function getPageSize() {
2090
+ var pageSizeField = this._get_data('innerUsedAttrs').pageSize;
2091
+ return this.getPageInfo()[pageSizeField];
2144
2092
  }
2145
2093
  }, {
2146
- key: "getColumnState",
2147
- value: function getColumnState(rowIndex, field, name) {
2148
- var _this$_get_data2;
2149
- var rowKey = this.getRowKey(rowIndex);
2150
- 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;
2094
+ key: "getTotalCount",
2095
+ value: function getTotalCount() {
2096
+ var totalField = this._get_data('innerUsedAttrs').pageCount;
2097
+ return this.getPageInfo()[totalField];
2151
2098
  }
2152
2099
  }, {
2153
- key: "setColumnState",
2154
- value: function setColumnState(rowIndex, field, name, value) {
2155
- this.setCellState(rowIndex, field, name, value);
2100
+ key: "setPageInfo",
2101
+ value: function setPageInfo(pageInfo) {
2102
+ var _pageInfo = this.getPageInfo();
2103
+ this._set_data('pageInfo', _objectSpread2(_objectSpread2({}, _pageInfo), pageInfo));
2104
+ this.reload();
2156
2105
  }
2157
2106
  }, {
2158
- key: "setColumnStates",
2159
- value: function setColumnStates() {
2160
- var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2161
- this.setCellStates(states.map(function (item) {
2162
- return _objectSpread2(_objectSpread2({}, item), {}, {
2163
- cellName: item.cellName || item.columnName
2164
- });
2165
- }));
2166
- }
2167
- }, {
2168
- key: "setColumnValue",
2169
- value: function setColumnValue(field, name, value) {
2170
- var columns = this._get_data('columns') || {};
2171
- if (!columns[field]) return;
2172
- this._applyState('columns', _objectSpread2(_objectSpread2({}, columns), {}, _defineProperty({}, field, _objectSpread2(_objectSpread2({}, columns[field]), {}, _defineProperty({}, name, value)))));
2173
- }
2174
-
2175
- /* ============================ 取数 ============================ */
2176
-
2177
- // 中台签名:load(proxyConfig, params, callback) = 设置取数配置并立刻取一次
2178
- }, {
2179
- key: "load",
2180
- value: function load(proxyConfig, params, callback) {
2181
- // if (proxyConfig) this.setProxy(proxyConfig)
2182
- // return this.fetch(params || {}).then((result) => {
2183
- // if (typeof callback === 'function') callback.call(this, null, result)
2184
- // return result
2185
- // })
2186
-
2187
- var proxy = this.setProxy({
2188
- load: proxyConfig
2189
- });
2190
- proxy.load(params, function (err, result) {
2191
- if (err) {
2192
- cb.utils.alert(err, 'error');
2193
- return;
2194
- }
2195
- if (result.schema) {
2196
- this._set_data('columnMode', 'remote');
2197
- this.setColumns(result.schema);
2198
- }
2199
- this.setDataSource(result.data);
2200
- if (callback) {
2201
- callback.call(this);
2202
- }
2203
- }, this);
2204
- }
2205
-
2206
- // 重新取数:优先驱动已挂载的表格(走表格自带的分页状态),没有视图时直接取数
2207
- }, {
2208
- key: "refresh",
2209
- value: function refresh() {
2210
- var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2211
- if (this.hasEvent('refresh')) return this.execute('refresh', params);
2212
- return this.fetch({
2213
- body: params
2214
- });
2215
- }
2216
- }, {
2217
- key: "loadData",
2218
- value: function loadData() {
2219
- var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2220
- return this.refresh(params);
2221
- }
2222
- }, {
2223
- key: "queryData",
2224
- value: function queryData() {
2225
- var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2226
- return this.refresh(params);
2227
- }
2228
-
2229
- /* ======================== 数据(两层) ======================== */
2230
-
2231
- /** 全量数据源(中台 getRealData 的语义:不拷贝,剔除已删除行) */
2232
- }, {
2233
- key: "getDataSource",
2234
- value: function getDataSource() {
2235
- var source = this._get_data('dataSource') || [];
2236
- if (!this.hasDeletedRow()) return source;
2237
- var rowsDataState = this._get_data('rowsDataState') || [];
2238
- return source.filter(function (row, index) {
2239
- return rowsDataState[index] !== DataStates.Delete;
2240
- });
2241
- }
2242
- }, {
2243
- key: "getRealData",
2244
- value: function getRealData() {
2245
- return this.getDataSource();
2246
- }
2247
- }, {
2248
- key: "getRealRows",
2249
- value: function getRealRows() {
2250
- return this._get_data('rows') || [];
2251
- }
2252
- }, {
2253
- key: "getRowsCount",
2254
- value: function getRowsCount() {
2255
- return (this._get_data('rows') || []).length;
2256
- }
2257
- }, {
2258
- key: "getDataSourceCount",
2259
- value: function getDataSourceCount() {
2260
- return (this._get_data('dataSource') || []).length;
2261
- }
2262
- }, {
2263
- key: "hasDeletedRow",
2264
- value: function hasDeletedRow() {
2265
- return (this._get_data('rowsDataState') || []).some(function (state) {
2266
- return state === DataStates.Delete;
2267
- });
2268
- }
2269
-
2270
- /**
2271
- * 数据出口,签名与中台一致,但语义容易踩坑,这里写清楚:
2272
- * - `getData()` → 全量 dataSource(提交/保存用,保留 _status,剔除 _selected)
2273
- * - `getData(true)` → 当前页 rows(视图用,剔除 _status / _selected)
2274
- * - `getAllData()` → 等于 getData(true),仅为对齐中台签名而保留
2275
- * - `getPageData()` → 等于 getData(true),语义更直白的别名
2276
- */
2277
- }, {
2278
- key: "getData",
2279
- value: function getData(view, realRows) {
2280
- var rows = view || realRows ? this._get_data('rows') : this._get_data('dataSource');
2281
- return this.collectRows(rows, view);
2282
- }
2283
- }, {
2284
- key: "getAllData",
2285
- value: function getAllData() {
2286
- return this.getData(true);
2287
- }
2288
- }, {
2289
- key: "getPageData",
2290
- value: function getPageData() {
2291
- return this.getData(true);
2292
- }
2293
-
2294
- /** 有效数据:全量里剔除 Delete 状态的行 */
2295
- }, {
2296
- key: "getEffeData",
2297
- value: function getEffeData() {
2298
- var source = this._get_data('dataSource') || [];
2299
- var rowsDataState = this._get_data('rowsDataState') || [];
2300
- return this.collectRows(source.filter(function (row, index) {
2301
- return rowsDataState[index] !== DataStates.Delete;
2302
- }), false);
2303
- }
2304
-
2305
- /** 当前页行(浅引用),isCopy=true 时返回深拷贝 */
2306
- }, {
2307
- key: "getRows",
2308
- value: function getRows(isCopy) {
2309
- var rows = this._get_data('rows') || [];
2310
- return isCopy === false ? rows : rows.map(function (row) {
2311
- return cloneDeep(row);
2312
- });
2313
- }
2314
- }, {
2315
- key: "collectRows",
2316
- value: function collectRows(rows, view) {
2317
- var columns = this._get_data('columns') || {};
2318
- var statusFlag = this.getStatusFlag();
2319
- var selectedFlag = this.getSelectedFlag();
2320
- return (rows || []).map(function (rowData) {
2321
- var row = {};
2322
- for (var attr in rowData) {
2323
- var _columns$attr;
2324
- // 视图数据不带 _status;提交数据不带 _selected
2325
- if (view && attr === statusFlag) continue;
2326
- if (!view && attr === selectedFlag) continue;
2327
- if (((_columns$attr = columns[attr]) === null || _columns$attr === void 0 ? void 0 : _columns$attr.needCollect) === false) continue;
2328
- row[attr] = rowData[attr];
2329
- }
2330
- return row;
2331
- });
2332
- }
2333
-
2334
- /** 展示文案副本(中台会把它推给组件;我们只作为工具方法保留) */
2335
- }, {
2336
- key: "getShowRows",
2337
- value: function getShowRows(rows) {
2338
- return (rows || this._get_data('rows') || []).map(function (row) {
2339
- return _objectSpread2({}, row);
2340
- });
2341
- }
2342
- }, {
2343
- key: "getRow",
2344
- value: function getRow(rowIndex, needGrandSon) {
2345
- var _this$_get_data3;
2346
- var row = (_this$_get_data3 = this._get_data('rows')) === null || _this$_get_data3 === void 0 ? void 0 : _this$_get_data3[rowIndex];
2347
- if (!row) return undefined;
2348
- return needGrandSon === false ? row : cloneDeep(row);
2349
- }
2350
- }, {
2351
- key: "getRowIndex",
2352
- value: function getRowIndex(row) {
2353
- if (!row) return -1;
2354
- var rows = this._get_data('rows') || [];
2355
- var rowKeyField = this.getRowKeyField();
2356
- if (row[rowKeyField] !== undefined) {
2357
- return rows.findIndex(function (item) {
2358
- return item[rowKeyField] === row[rowKeyField];
2359
- });
2360
- }
2361
- return rows.indexOf(row);
2362
- }
2363
- }, {
2364
- key: "getRowIndexByRowId",
2365
- value: function getRowIndexByRowId(rowId) {
2366
- var _this4 = this;
2367
- var rows = this._get_data('rows') || [];
2368
- return rows.findIndex(function (row) {
2369
- return (row === null || row === void 0 ? void 0 : row[_this4.getIdFlag()]) === rowId;
2370
- });
2371
- }
2372
- }, {
2373
- key: "getDataSourceIndexByRowId",
2374
- value: function getDataSourceIndexByRowId(rowId) {
2375
- var _this5 = this;
2376
- return (this._get_data('dataSource') || []).findIndex(function (row) {
2377
- return (row === null || row === void 0 ? void 0 : row[_this5.getIdFlag()]) === rowId;
2378
- });
2379
- }
2380
- }, {
2381
- key: "getRowKey",
2382
- value: function getRowKey(rowIndex) {
2383
- var _this$_get_data$rowIn, _this$_get_data4;
2384
- 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;
2385
- }
2386
- }, {
2387
- key: "getRowKeys",
2388
- value: function getRowKeys(rowData) {
2389
- var list = rowData === undefined ? this.getRows() : isArray(rowData) ? rowData : [rowData];
2390
- var keyField = this.getRowKeyField();
2391
- return list.filter(function (row) {
2392
- return row && row[keyField] !== undefined;
2393
- }).map(function (row) {
2394
- return row[keyField];
2395
- });
2396
- }
2397
- }, {
2398
- key: "getRowsByIndexes",
2399
- value: function getRowsByIndexes(rowIndexes) {
2400
- var rows = this._get_data('rows') || [];
2401
- return (isArray(rowIndexes) ? rowIndexes : [rowIndexes]).map(function (index) {
2402
- return rows[index];
2403
- }).filter(Boolean);
2404
- }
2405
-
2406
- /* ==================== 单元格值 / 单元格状态 ==================== */
2407
- }, {
2408
- key: "getCellValue",
2409
- value: function getCellValue(rowIndex, cellName) {
2410
- var _this$_get_data5;
2411
- var row = rowIndex >= 0 ? (_this$_get_data5 = this._get_data('rows')) === null || _this$_get_data5 === void 0 ? void 0 : _this$_get_data5[rowIndex] : null;
2412
- if (!row || !cellName) return undefined;
2413
- return row[cellName];
2414
- }
2415
- }, {
2416
- key: "setCellValue",
2417
- value: function setCellValue(rowIndex, cellName, value) {
2418
- var rows = this._get_data('rows') || [];
2419
- var row = rows[rowIndex];
2420
- if (!row || !cellName) return;
2421
- var oldValue = row[cellName];
2422
- if (oldValue === value) return;
2423
- var data = {
2424
- rowIndex: rowIndex,
2425
- rowId: row[this.getIdFlag()],
2426
- cellName: cellName,
2427
- value: value,
2428
- oldValue: oldValue
2429
- };
2430
- if (!this.execute('beforeCellValueChange', data)) return;
2431
- row[cellName] = data.value;
2432
- this.markRowState(rowIndex, DataStates.Update);
2433
- this.execute('afterCellValueChange', data);
2434
- this.doPropertyChange('setCellValue', data);
2435
- }
2436
- }, {
2437
- key: "setCellValues",
2438
- value: function setCellValues() {
2439
- var _this6 = this;
2440
- var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2441
- if (!isArray(values)) return;
2442
- values.forEach(function (item) {
2443
- return _this6.setCellValue(item.rowIndex, item.cellName || item.field, item.value);
2444
- });
2445
- }
2446
- }, {
2447
- key: "getCellState",
2448
- value: function getCellState(rowIndex, cellName, name) {
2449
- var _this$_get_data6;
2450
- var rowKey = this.getRowKey(rowIndex);
2451
- 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;
2452
- if (!cell) return undefined;
2453
- return cell[name];
2454
- }
2455
- }, {
2456
- key: "setCellState",
2457
- value: function setCellState(rowIndex, cellName, name, value) {
2458
- var _this$_get_data7;
2459
- 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()];
2460
- var rowKey = rowId || rowIndex;
2461
- if (isEmpty(rowKey)) return;
2462
- var oldValue = this.getCellState(rowIndex, cellName, name);
2463
- if (oldValue === value) return;
2464
- var data = {
2465
- rowIndex: rowIndex,
2466
- rowId: rowId,
2467
- cellName: cellName,
2468
- propertyName: name,
2469
- value: value,
2470
- oldValue: oldValue
2471
- };
2472
- if (!this.execute('beforeCellStateChange', data)) return;
2473
- var cellState = _objectSpread2({}, this._get_data('cellState') || {});
2474
- cellState[rowKey] = _objectSpread2({}, cellState[rowKey] || {});
2475
- cellState[rowKey][cellName] = _objectSpread2(_objectSpread2({}, cellState[rowKey][cellName] || {}), {}, _defineProperty({}, name, value));
2476
- this._applyState('cellState', cellState);
2477
- this.execute('afterCellStateChange', data);
2478
- }
2479
- }, {
2480
- key: "setCellStates",
2481
- value: function setCellStates() {
2482
- var _this7 = this;
2483
- var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2484
- if (!isArray(states)) return;
2485
- states.forEach(function (item) {
2486
- return _this7.setCellState(item.rowIndex, item.cellName, item.propertyName || item.name, item.value);
2487
- });
2488
- }
2489
-
2490
- /* ==================== 行状态 / 脏数据 ==================== */
2491
-
2492
- /** 行数据状态(Insert / Update / Delete / 空),rowIndex 是 rows 的下标 */
2493
- }, {
2494
- key: "getRowDataState",
2495
- value: function getRowDataState(rowIndex) {
2496
- var _this$_get_data8;
2497
- var indexInDS = this.getDataSourceIndexByRow(rowIndex);
2498
- return (_this$_get_data8 = this._get_data('rowsDataState')) === null || _this$_get_data8 === void 0 ? void 0 : _this$_get_data8[indexInDS];
2499
- }
2500
- }, {
2501
- key: "getDataSourceIndexByRow",
2502
- value: function getDataSourceIndexByRow(rowIndex) {
2503
- var _this8 = this;
2504
- var rows = this._get_data('rows') || [];
2505
- var row = rows[rowIndex];
2506
- if (!row) return -1;
2507
- var source = this._get_data('dataSource') || [];
2508
- var index = source.indexOf(row);
2509
- if (index > -1) return index;
2510
- // 本地分页时 rows 是切片,引用一致;远程模式下 rows 与 dataSource 同源
2511
- return source.findIndex(function (item) {
2512
- return (item === null || item === void 0 ? void 0 : item[_this8.getIdFlag()]) === (row === null || row === void 0 ? void 0 : row[_this8.getIdFlag()]);
2513
- });
2514
- }
2515
- }, {
2516
- key: "setRowDataState",
2517
- value: function setRowDataState(rowIndex, dataState) {
2518
- var indexInDS = this.getDataSourceIndexByRow(rowIndex);
2519
- if (indexInDS < 0) return;
2520
- var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2521
- rowsDataState[indexInDS] = dataState;
2522
- this._set_data('rowsDataState', rowsDataState, true);
2523
- }
2524
-
2525
- // 只在「原状态是 Unchanged」时置为 Update,避免把 Insert 覆盖成 Update
2526
- }, {
2527
- key: "markRowState",
2528
- value: function markRowState(rowIndex, dataState) {
2529
- var current = this.getRowDataState(rowIndex);
2530
- if (current === DataStates.Insert || current === dataState) return;
2531
- this.setRowDataState(rowIndex, dataState);
2532
- }
2533
-
2534
- /** 单元格编辑由组件回灌时用:传行对象或行下标都可以 */
2535
- }, {
2536
- key: "markRowUpdate",
2537
- value: function markRowUpdate(rowOrIndex) {
2538
- var rowIndex = typeof rowOrIndex === 'number' ? rowOrIndex : this.getRowIndex(rowOrIndex);
2539
- if (rowIndex < 0) return;
2540
- this.markRowState(rowIndex, DataStates.Update);
2541
- }
2542
- }, {
2543
- key: "getRowState",
2544
- value: function getRowState(rowIndex, name) {
2545
- var _this$_get_data9;
2546
- var rowKey = this.getRowKey(rowIndex);
2547
- var row = rowKey ? (_this$_get_data9 = this._get_data('rowState')) === null || _this$_get_data9 === void 0 ? void 0 : _this$_get_data9[rowKey] : null;
2548
- if (!row || !name) return undefined;
2549
- return row[name];
2550
- }
2551
- }, {
2552
- key: "setRowState",
2553
- value: function setRowState(rowIndex, name, value) {
2554
- var _this$_get_data0;
2555
- var row = (_this$_get_data0 = this._get_data('rows')) === null || _this$_get_data0 === void 0 ? void 0 : _this$_get_data0[rowIndex];
2556
- if (!row || !name) return;
2557
- var rowKey = this.getRowKey(rowIndex);
2558
- var oldValue = this.getRowState(rowIndex, name);
2559
- if (oldValue === value) return;
2560
- var data = {
2561
- rowIndex: rowIndex,
2562
- rowId: row[this.getIdFlag()],
2563
- propertyName: name,
2564
- value: value,
2565
- oldValue: oldValue
2566
- };
2567
- if (!this.execute('beforeRowStateChange', data)) return;
2568
- var rowState = _objectSpread2({}, this._get_data('rowState') || {});
2569
- rowState[rowKey] = _objectSpread2(_objectSpread2({}, rowState[rowKey] || {}), {}, _defineProperty({}, name, value));
2570
- this._applyState('rowState', rowState);
2571
- this.execute('afterRowStateChange', data);
2572
- }
2573
- }, {
2574
- key: "setRowStates",
2575
- value: function setRowStates() {
2576
- var _this9 = this;
2577
- var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2578
- if (!isArray(states)) return;
2579
- states.forEach(function (item) {
2580
- return _this9.setRowState(item.rowIndex, item.propertyName || item.name, item.value);
2581
- });
2582
- }
2583
-
2584
- /** 收集增删改过的行,用于提交;没有脏数据时返回 undefined(中台同款) */
2585
- }, {
2586
- key: "getDirtyData",
2587
- value: function getDirtyData(necessary) {
2588
- var _this0 = this;
2589
- var source = this._get_data('dataSource') || [];
2590
- var rowsDataState = this._get_data('rowsDataState') || [];
2591
- var data = [];
2592
- source.forEach(function (row, index) {
2593
- var dataState = rowsDataState[index];
2594
- if (!dataState) return;
2595
- var item = cloneDeep(row);
2596
- item[_this0.getStatusFlag()] = dataState;
2597
- data.push(item);
2598
- });
2599
- return data.length ? data : undefined;
2600
- }
2601
- }, {
2602
- key: "getDirtyRowIndexes",
2603
- value: function getDirtyRowIndexes() {
2604
- var _this1 = this;
2605
- var rows = this._get_data('rows') || [];
2606
- return rows.map(function (row, index) {
2607
- return index;
2608
- }).filter(function (index) {
2609
- return !!_this1.getRowDataState(index);
2610
- });
2611
- }
2612
- }, {
2613
- key: "isDirty",
2614
- value: function isDirty() {
2615
- return !!this.getDirtyData();
2616
- }
2617
-
2618
- // 备份 / 还原未提交的数据(取消编辑时用)
2619
- }, {
2620
- key: "backupState",
2621
- value: function backupState() {
2622
- this._set_data('backupData', {
2623
- dataSource: cloneDeep(this._get_data('dataSource') || []),
2624
- rowsDataState: _toConsumableArray(this._get_data('rowsDataState') || [])
2625
- });
2626
- }
2627
- }, {
2628
- key: "restoreState",
2629
- value: function restoreState() {
2630
- var backup = this._get_data('backupData');
2631
- if (!backup) return;
2632
- this._set_data('dataSource', backup.dataSource, true);
2633
- this._set_data('rowsDataState', _toConsumableArray(backup.rowsDataState), true);
2634
- this.showPage();
2635
- }
2636
-
2637
- /* ======================= 增删改行 ======================= */
2638
-
2639
- /** 中台签名:insertRow(rowIndex, rowData, needCheckDefault, isCopy, extendParams) */
2640
- }, {
2641
- key: "insertRow",
2642
- value: function insertRow(rowIndex) {
2643
- var rowData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2644
- var isCopy = arguments.length > 3 ? arguments[3] : undefined;
2645
- var rows = this._get_data('rows') || [];
2646
- var index = Math.min(rows.length, Math.max(0, rowIndex === undefined ? rows.length : rowIndex));
2647
- var data = {
2648
- index: index,
2649
- row: _objectSpread2({}, rowData),
2650
- isCopy: isCopy
2651
- };
2652
- if (!this.execute('beforeInsertRow', data)) return;
2653
- var row = data.row;
2654
- delete row[this.getIdFlag()];
2655
- setIds.call(this, [row]);
2656
- var source = this._get_data('dataSource') || [];
2657
- var indexInDS = index < rows.length ? this.getDataSourceIndexByRow(index) : source.length;
2658
- source.splice(indexInDS < 0 ? source.length : indexInDS, 0, row);
2659
- var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2660
- rowsDataState.splice(indexInDS < 0 ? rowsDataState.length : indexInDS, 0, DataStates.Insert);
2661
- rows.splice(index, 0, row);
2662
- this._set_data('rowsDataState', rowsDataState, true);
2663
- this.setRows(rows);
2664
- this.execute('afterInsertRow', _objectSpread2(_objectSpread2({}, data), {}, {
2665
- rowIndex: index
2666
- }));
2667
- return row;
2668
- }
2669
- }, {
2670
- key: "insertRows",
2671
- value: function insertRows(rowIndex) {
2672
- var _this10 = this;
2673
- var rowsData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
2674
- var result = [];
2675
- (isArray(rowsData) ? rowsData : [rowsData]).forEach(function (rowData, offset) {
2676
- result.push(_this10.insertRow(rowIndex + offset, rowData));
2677
- });
2678
- return result;
2679
- }
2680
- }, {
2681
- key: "appendRow",
2682
- value: function appendRow() {
2683
- var rowData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2684
- return this.insertRow(this.getRowsCount(), rowData);
2685
- }
2686
- }, {
2687
- key: "updateRow",
2688
- value: function updateRow(rowIndex) {
2689
- var _this$_get_data1;
2690
- var rowData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2691
- var row = (_this$_get_data1 = this._get_data('rows')) === null || _this$_get_data1 === void 0 ? void 0 : _this$_get_data1[rowIndex];
2692
- if (!row) return;
2693
- if (!this.execute('beforeUpdateRow', {
2694
- index: rowIndex,
2695
- row: rowData
2696
- })) return;
2697
- Object.assign(row, rowData);
2698
- this.markRowState(rowIndex, DataStates.Update);
2699
- this.setRows(this._get_data('rows'));
2700
- this.execute('afterUpdateRow', {
2701
- index: rowIndex,
2702
- row: row
2703
- });
2704
- }
2705
- }, {
2706
- key: "updateRows",
2707
- value: function updateRows() {
2708
- var _this11 = this;
2709
- var rowsData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2710
- rowsData.forEach(function (item) {
2711
- var _item$rowIndex;
2712
- return _this11.updateRow((_item$rowIndex = item.rowIndex) !== null && _item$rowIndex !== void 0 ? _item$rowIndex : item.index, item.rowData || item.row);
2713
- });
2714
- }
2715
-
2716
- /** 删除行:有 id 的行标 Delete 保留占位,本地新增未保存的行直接丢弃(中台同款) */
2717
- }, {
2718
- key: "deleteRows",
2719
- value: function deleteRows(rowIndexes) {
2720
- var _this12 = this;
2721
- var indexes = (isArray(rowIndexes) ? rowIndexes : [rowIndexes]).filter(function (index) {
2722
- return index >= 0 && index < _this12.getRowsCount();
2723
- }).sort(function (a, b) {
2724
- return a - b;
2725
- });
2726
- if (!indexes.length) return;
2727
- var rowsToDelete = this.getRowsByIndexes(indexes);
2728
- if (!this.execute('beforeDeleteRows', rowsToDelete, indexes)) return;
2729
- var source = this._get_data('dataSource') || [];
2730
- var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2731
- var deletedIds = new Set();
2732
- // 本地新增的行不需要保留占位,直接从数据源里抹掉
2733
- var discardIds = new Set();
2734
- rowsToDelete.forEach(function (row) {
2735
- var index = source.indexOf(row);
2736
- if (index < 0) return;
2737
- var key = row[_this12.getIdFlag()];
2738
- deletedIds.add(key);
2739
- if (rowsDataState[index] === DataStates.Insert) discardIds.add(key);
2740
- });
2741
- var keptSource = [];
2742
- var keptState = [];
2743
- source.forEach(function (row, index) {
2744
- var key = row[_this12.getIdFlag()];
2745
- if (!deletedIds.has(key)) {
2746
- keptSource.push(row);
2747
- keptState.push(rowsDataState[index]);
2748
- return;
2749
- }
2750
- if (discardIds.has(key)) return;
2751
- keptSource.push(row);
2752
- keptState.push(DataStates.Delete);
2753
- });
2754
- this._set_data('dataSource', keptSource, true);
2755
- this._set_data('rowsDataState', keptState, true);
2756
- // 本地模式下重新切片即可,删除行会自然消失在当前页
2757
- this.showPage();
2758
- this.execute('afterDeleteRows', {
2759
- rowIndexes: indexes,
2760
- rows: rowsToDelete
2761
- });
2762
- }
2763
- }, {
2764
- key: "deleteAllRows",
2765
- value: function deleteAllRows() {
2766
- this.deleteRows(this.getRows().map(function (row, index) {
2767
- return index;
2768
- }));
2769
- }
2770
- }, {
2771
- key: "clear",
2772
- value: function clear() {
2773
- this._set_data('dataSource', [], true);
2774
- this._set_data('rows', [], true);
2775
- this._set_data('rowsDataState', [], true);
2776
- this.clearSelection();
2777
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
2778
- recordCount: 0,
2779
- pageIndex: 1
2780
- }));
2781
- this.setDataSourceView();
2782
- }
2783
-
2784
- /* ======================= 选中 ======================= */
2785
-
2786
- /**
2787
- * 选中行
2788
- * @param {Number|Array} rowIndexes rows 下标
2789
- * @param {Boolean} all true = 替换选择(先清掉其他选中),默认 false = 追加
2790
- */
2791
- }, {
2792
- key: "select",
2793
- value: function select(rowIndexes, all) {
2794
- var _this13 = this;
2795
- if (rowIndexes == null && all !== true) return;
2796
- if (all === true) this.unselectAll({
2797
- silent: true
2798
- });
2799
- var indexes = all === true ? this.getRows().map(function (row, index) {
2800
- return index;
2801
- }) : isArray(rowIndexes) ? rowIndexes : [rowIndexes];
2802
- indexes = indexes.filter(function (index) {
2803
- return index >= 0 && index < _this13.getRowsCount();
2804
- });
2805
- var rows = this._get_data('rows') || [];
2806
- var selectedFlag = this.getSelectedFlag();
2807
- var changed = indexes.filter(function (index) {
2808
- return !rows[index][selectedFlag];
2809
- });
2810
- if (!changed.length) {
2811
- if (all === true) this.flushSelection();
2812
- return;
2813
- }
2814
- var data = {
2815
- rowIndexes: changed,
2816
- rows: changed.map(function (index) {
2817
- return rows[index];
2818
- })
2819
- };
2820
- if (!this.execute('beforeSelect', data)) return;
2821
- changed.forEach(function (index) {
2822
- rows[index][selectedFlag] = true;
2823
- _this13.cacheSelectedRow(rows[index], true);
2824
- });
2825
- this.flushSelection();
2826
- }
2827
- }, {
2828
- key: "unselect",
2829
- value: function unselect(rowIndexes) {
2830
- var _this14 = this;
2831
- if (rowIndexes == null) return;
2832
- var indexes = isArray(rowIndexes) ? rowIndexes : [rowIndexes];
2833
- var rows = this._get_data('rows') || [];
2834
- var selectedFlag = this.getSelectedFlag();
2835
- var changed = indexes.filter(function (index) {
2836
- var _rows$index;
2837
- return (_rows$index = rows[index]) === null || _rows$index === void 0 ? void 0 : _rows$index[selectedFlag];
2838
- });
2839
- if (!changed.length) return;
2840
- if (!this.execute('beforeUnselect', changed)) return;
2841
- changed.forEach(function (index) {
2842
- rows[index][selectedFlag] = false;
2843
- _this14.cacheSelectedRow(rows[index], false);
2844
- });
2845
- this.flushSelection();
2846
- }
2847
- }, {
2848
- key: "selectAll",
2849
- value: function selectAll() {
2850
- var _this15 = this;
2851
- var rows = this._get_data('rows') || [];
2852
- var selectedFlag = this.getSelectedFlag();
2853
- rows.forEach(function (row) {
2854
- row[selectedFlag] = true;
2855
- _this15.cacheSelectedRow(row, true);
2856
- });
2857
- this.flushSelection();
2858
- }
2859
-
2860
- /**
2861
- * 清空选中
2862
- * @param {Object} options onlyPage=true 只清当前页(其他页的跨页缓存保留);silent=true 不下发视图
2863
- *
2864
- * 注意要清 **dataSource** 上的行:`_selected` 记在行对象上,
2865
- * 而本地分页时当前页的 rows 只是 dataSource 的切片,只清 rows 会让翻页回来的行「带着选中复活」。
2866
- */
2867
- }, {
2868
- key: "unselectAll",
2869
- value: function unselectAll() {
2870
- var _this16 = this;
2871
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2872
- var selectedFlag = this.getSelectedFlag();
2873
- var targets = options.onlyPage ? this._get_data('rows') : this._get_data('dataSource');
2874
- (targets || []).forEach(function (row) {
2875
- row[selectedFlag] = false;
2876
- });
2877
- if (options.onlyPage) {
2878
- (this._get_data('rows') || []).forEach(function (row) {
2879
- return _this16.cacheSelectedRow(row, false);
2880
- });
2881
- } else {
2882
- this._set_data('selectedKeys', [], true);
2883
- this._set_data('selectedRowsMap', {}, true);
2884
- this._set_data('selectedKeysSet', new Set(), true);
2885
- }
2886
- if (!options.silent) this.flushSelection();
2887
- }
2888
- }, {
2889
- key: "clearSelection",
2890
- value: function clearSelection() {
2891
- this.unselectAll();
2892
- }
2893
-
2894
- /**
2895
- * 以传入的行集合作为**当前页**的选中结果(表格选中变化回灌的入口)。
2896
- * 其他页的跨页选中缓存不受影响 —— 表格的勾选状态只覆盖当前页,
2897
- * 若在这里清空缓存,翻页就会把之前选的行丢掉。
2898
- */
2899
- }, {
2900
- key: "setSelectedRows",
2901
- value: function setSelectedRows() {
2902
- var _this17 = this;
2903
- var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2904
- var list = isArray(rows) ? rows : [];
2905
- var keyField = this.getRowKeyField();
2906
- var keys = new Set(list.map(function (row) {
2907
- var _row$keyField;
2908
- return String((_row$keyField = row === null || row === void 0 ? void 0 : row[keyField]) !== null && _row$keyField !== void 0 ? _row$keyField : row);
2909
- }));
2910
- var currentRows = this._get_data('rows') || [];
2911
- var selectedFlag = this.getSelectedFlag();
2912
- currentRows.forEach(function (row) {
2913
- var selected = keys.has(String(row[keyField]));
2914
- if (selected !== !!row[selectedFlag]) {
2915
- row[selectedFlag] = selected;
2916
- _this17.cacheSelectedRow(row, selected);
2917
- }
2918
- });
2919
- this.flushSelection();
2920
- }
2921
-
2922
- /** 全量替换选中(含清掉其他页的缓存) */
2923
- }, {
2924
- key: "setSelection",
2925
- value: function setSelection() {
2926
- var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2927
- this.unselectAll({
2928
- silent: true
2929
- });
2930
- this.setSelectedRows(rows);
2931
- }
2932
- }, {
2933
- key: "getSelectedRows",
2934
- value: function getSelectedRows(rowIndexes) {
2935
- var rows = this._get_data('rows') || [];
2936
- var selectedFlag = this.getSelectedFlag();
2937
- var keys = rowIndexes && new Set(isArray(rowIndexes) ? rowIndexes : [rowIndexes]);
2938
- return rows.filter(function (row, index) {
2939
- return row[selectedFlag] && (!keys || keys.has(index));
2940
- });
2941
- }
2942
- }, {
2943
- key: "getSelectedRowIndexes",
2944
- value: function getSelectedRowIndexes() {
2945
- var rows = this._get_data('rows') || [];
2946
- var selectedFlag = this.getSelectedFlag();
2947
- var indexes = [];
2948
- rows.forEach(function (row, index) {
2949
- if (row[selectedFlag]) indexes.push(index);
2950
- });
2951
- return indexes;
2952
- }
2953
- }, {
2954
- key: "getSelectedKeys",
2955
- value: function getSelectedKeys() {
2956
- return this._get_data('selectedKeys') || [];
2957
- }
2958
-
2959
- /** 跨页选中的全部行(按选中顺序) */
2960
- }, {
2961
- key: "getAllCacheSelectedRows",
2962
- value: function getAllCacheSelectedRows() {
2963
- var keys = this._get_data('selectedKeys') || [];
2964
- var rowsMap = this._get_data('selectedRowsMap') || {};
2965
- return keys.map(function (key) {
2966
- return rowsMap[key];
2967
- }).filter(Boolean);
2968
- }
2969
- }, {
2970
- key: "selectByKeys",
2971
- value: function selectByKeys(keys) {
2972
- var selected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2973
- var rowKeyField = this.getRowKeyField();
2974
- var list = isArray(keys) ? keys : [keys];
2975
- var rows = this._get_data('rows') || [];
2976
- var indexes = [];
2977
- list.forEach(function (key) {
2978
- var index = rows.findIndex(function (row) {
2979
- return String(row[rowKeyField]) === String(key);
2980
- });
2981
- if (index > -1) indexes.push(index);
2982
- });
2983
- if (!indexes.length) return;
2984
- selected ? this.select(indexes) : this.unselect(indexes);
2985
- }
2986
- }, {
2987
- key: "getSelectedNodes",
2988
- value: function getSelectedNodes() {
2989
- return this.getAllCacheSelectedRows();
2990
- }
2991
- }, {
2992
- key: "cacheSelectedRow",
2993
- value: function cacheSelectedRow(row, selected) {
2994
- var key = String(row === null || row === void 0 ? void 0 : row[this.getRowKeyField()]);
2995
- var keys = (this._get_data('selectedKeys') || []).filter(function (item) {
2996
- return item !== key;
2997
- });
2998
- var rowsMap = _objectSpread2({}, this._get_data('selectedRowsMap') || {});
2999
- if (selected) keys.push(key);
3000
- if (selected) rowsMap[key] = row;else delete rowsMap[key];
3001
- this._set_data('selectedKeys', keys, true);
3002
- this._set_data('selectedRowsMap', rowsMap, true);
3003
- this._set_data('selectedKeysSet', new Set(keys), true);
3004
- }
3005
-
3006
- // 选中变化统一在这里下发视图(组件侧用同步开关挡住回灌死循环)
3007
- }, {
3008
- key: "flushSelection",
3009
- value: function flushSelection() {
3010
- this._applyState('selectedRows', this.getSelectedRows());
3011
- this.execute('selectionChange', {
3012
- value: this.getSelectedRows(),
3013
- keys: this.getSelectedKeys(),
3014
- indexes: this.getSelectedRowIndexes()
3015
- });
3016
- }
3017
-
3018
- // 重新取数后把跨页选中的标记补回当前页的行上
3019
- }, {
3020
- key: "restoreSelectedFlags",
3021
- value: function restoreSelectedFlags() {
3022
- if (!this.get('cacheSelectedRows')) return;
3023
- var keysSet = this._get_data('selectedKeysSet') || new Set();
3024
- if (!keysSet.size) return;
3025
- var rowKeyField = this.getRowKeyField();
3026
- var selectedFlag = this.getSelectedFlag();
3027
- (this.getRows() || []).forEach(function (row) {
3028
- row[selectedFlag] = keysSet.has(String(row[rowKeyField]));
3029
- });
3030
- }
3031
-
3032
- /* ======================= 分页 ======================= */
3033
- }, {
3034
- key: "setPagination",
3035
- value: function setPagination(value) {
3036
- this._applyState('pagination', !!value);
3037
- this.showPage();
3038
- }
3039
- }, {
3040
- key: "getPageInfo",
3041
- value: function getPageInfo() {
3042
- return this._get_data('pageInfo') || createDefaults().pageInfo;
3043
- }
3044
- }, {
3045
- key: "getPageIndex",
3046
- value: function getPageIndex() {
3047
- return this.getPageInfo().pageIndex;
3048
- }
3049
- }, {
3050
- key: "getPageSize",
3051
- value: function getPageSize() {
3052
- return this.getPageInfo().pageSize;
3053
- }
3054
- }, {
3055
- key: "getTotalCount",
3056
- value: function getTotalCount() {
3057
- return this.getPageInfo().recordCount;
3058
- }
3059
- }, {
3060
- key: "setPageInfo",
3061
- value: function setPageInfo(pageInfo) {
3062
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), pageInfo), {
3063
- refresh: true
3064
- });
3065
- }
3066
- }, {
3067
- key: "setPageIndex",
3068
- value: function setPageIndex(pageIndex) {
3069
- var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3070
- if (typeof pageIndex !== 'number') return;
3071
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3072
- pageIndex: Math.max(1, pageIndex)
3073
- }), {
3074
- refresh: refresh
3075
- });
2107
+ key: "setPageIndex",
2108
+ value: function setPageIndex(pageIndex) {
2109
+ if (typeof pageIndex !== 'number') return;
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))));
3076
2113
  }
3077
2114
  }, {
3078
2115
  key: "setPageSize",
3079
2116
  value: function setPageSize(pageSize) {
3080
- var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3081
2117
  if (typeof pageSize !== 'number') return;
3082
- // 与中台一致:pageSize = -1 表示不分页
3083
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3084
- pageSize: Math.max(-1, pageSize),
3085
- pageIndex: 1
3086
- }), {
3087
- refresh: refresh
3088
- });
3089
- }
3090
- }, {
3091
- key: "setRecordCount",
3092
- value: function setRecordCount(recordCount) {
3093
- this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3094
- recordCount: recordCount || 0
3095
- }));
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)));
3096
2122
  }
3097
-
3098
- /**
3099
- * 统一的分页写入:算 pageCount / 记录 begin~end、切片、下发视图
3100
- * @param {Object} options silent=true 时不通知视图(组件自己的翻页动作走这里)
3101
- */
3102
2123
  }, {
3103
- key: "applyPageInfo",
3104
- value: function applyPageInfo(pageInfo) {
3105
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3106
- var next = _objectSpread2({}, pageInfo || {});
3107
- var pageSize = next.pageSize === -1 ? -1 : next.pageSize || DEFAULT_PAGE_SIZE;
3108
- var recordCount = next.recordCount || 0;
3109
- // recordCount 还没取到时不要按 pageCount 夹 pageIndex,否则「跳第 N 页」会被压回第 1 页
3110
- var known = recordCount > 0;
3111
- next.pageSize = pageSize;
3112
- next.recordCount = recordCount;
3113
- next.pageCount = pageSize > 0 ? Math.max(1, Math.ceil(recordCount / pageSize)) : 1;
3114
- next.pageIndex = pageSize > 0 ? Math.max(1, known ? Math.min(next.pageIndex || 1, next.pageCount) : next.pageIndex || 1) : 1;
3115
- next.beginPageIndex = pageSize > 0 ? (next.pageIndex - 1) * pageSize + 1 : 1;
3116
- next.endPageIndex = pageSize > 0 ? Math.min(next.pageIndex * pageSize, recordCount) : recordCount;
3117
- this._set_data('pageInfo', next, true);
3118
- if (options.silent) return next;
3119
- this._applyState('pageInfo', next);
3120
- if (!this.isRemote()) this.showPage();
3121
- if (options.refresh && this.isRemote()) this.refresh();
3122
- return next;
3123
- }
3124
-
3125
- /** 本地分页:按 pageInfo 从 dataSource 切出当前页 rows */
3126
- }, {
3127
- key: "showPage",
3128
- value: function showPage() {
3129
- var source = this._get_data('dataSource') || [];
3130
- if (this.isRemote() || !this.isPagination()) {
3131
- this.setRows(source);
3132
- return;
3133
- }
3134
- var _this$getPageInfo = this.getPageInfo(),
3135
- pageIndex = _this$getPageInfo.pageIndex,
3136
- pageSize = _this$getPageInfo.pageSize;
3137
- var start = (pageIndex - 1) * pageSize;
3138
- this.setRows(source.slice(start, start + pageSize));
3139
- }
3140
-
3141
- /* ======================= 数据写入 ======================= */
3142
-
3143
- /** 全量赋值(中台 setDataSource):本地模式重新切片,远程模式等于当前页 */
3144
- }, {
3145
- key: "setDataSource",
3146
- value: function setDataSource(proxyConfig) {
3147
- var queryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3148
- var callback = arguments.length > 2 ? arguments[2] : undefined;
3149
- if (this._get_data('dataSourceMode') === 'local') {
3150
- var data = cb.utils.isArray(proxyConfig) ? proxyConfig : [];
3151
- if (!this.execute('beforeSetDataSource', data)) return;
3152
- var rowKeyField = this._get_data('rowKeyField');
3153
- var keyMap = {};
3154
- data.forEach(function (item) {
3155
- keyMap[item[rowKeyField]] = item;
3156
- });
3157
- this._set_data('keyMap', keyMap);
3158
- this._set_data('dataSource', data, true);
3159
- this.getCache('grandson');
3160
- if (data.length) {
3161
- setIds.call(this, data);
3162
- }
3163
- this.initRowState();
3164
- // 修改缓存数据
3165
- setCachePaginationRowData.call(this, data);
3166
- // 修改行号
3167
- this.doPropertyChange('resetCellStatus');
3168
- this._set_data('rowState', {}, true);
3169
- // this.showRows(null, true)
3170
- this.doPropertyChange('setDataSource', this.getShowRows());
3171
- this._set_data('delayInsertRows', []); // setDataSource方法会同步模型和组件数据,把延迟存的数据清掉
3172
- if (this._get_data('isSorting')) {
3173
- this._set_data('isSorting', false);
3174
- }
3175
- this.execute('afterSetDataSource', data);
3176
- } else {
3177
- if (!this.execute('beforeProxyLoad', queryParams)) return;
3178
- var pageInfo = this._get_data('pageInfo');
3179
- pageInfo.pageIndex = 1;
3180
- var needLoadPageination = true;
3181
- // this.rebuildProxyConfig(proxyConfig)
3182
- this._set_data('proxyConfig', proxyConfig);
3183
- this._set_data('queryParams', queryParams);
3184
- this._set_data('callback', callback);
3185
- showPageInner.call(this, proxyConfig, queryParams, callback, true, needLoadPageination);
3186
- }
3187
- }
3188
-
3189
- /** 只换当前页 rows(中台 setRows) */
3190
- }, {
3191
- key: "setRows",
3192
- value: function setRows(rows) {
3193
- var list = isArray(rows) ? rows : [];
3194
- this._set_data('rows', list, true);
3195
- this.setRowsIdMap();
3196
- // 注意:这里推的是原始行对象,而不是中台的 getShowRows() 展示副本 —— 否则
3197
- // 选中回灌、单元格编辑会落到副本上,模型与视图的数据对不上
3198
- this._applyState('data', list);
3199
- }
3200
- }, {
3201
- key: "setDataSourceView",
3202
- value: function setDataSourceView() {
3203
- this._applyState('data', this._get_data('rows') || []);
3204
- }
3205
- }, {
3206
- key: "setRowsIdMap",
3207
- value: function setRowsIdMap() {
3208
- var _this18 = this;
3209
- var map = {};
3210
- (this._get_data('rows') || []).forEach(function (row) {
3211
- if ((row === null || row === void 0 ? void 0 : row[_this18.getIdFlag()]) !== undefined) map[row[_this18.getIdFlag()]] = row;
3212
- });
3213
- this._set_data('rowsIdMap', map);
3214
- }
3215
- }, {
3216
- key: "getRowIdMap",
3217
- value: function getRowIdMap() {
3218
- return this._get_data('rowsIdMap') || {};
3219
- }
3220
-
3221
- /* ======================= 校验 ======================= */
3222
-
3223
- /**
3224
- * 必输校验(中台会把校验委托给 editRowModel,我们这层没有行模型,只做列级必输)
3225
- * @returns {Boolean} 通过返回 true,不通过返回 false,并把消息推给视图(validate 事件)
3226
- */
3227
- }, {
3228
- key: "validate",
3229
- value: function validate(cancel, paramsRowsIndex) {
3230
- var _this19 = this;
3231
- if (cancel) {
3232
- this.doPropertyChange('validate', {
3233
- type: '',
3234
- message: '',
3235
- errors: []
3236
- });
3237
- this._set_data('validateErrors', []);
3238
- return false;
3239
- }
3240
- this.deleteNotModifiedRows();
3241
- var columns = this._get_data('columns') || {};
3242
- var rows = paramsRowsIndex ? this.getRowsByIndexes(paramsRowsIndex) : this.getRows();
3243
- var errors = [];
3244
- rows.forEach(function (row, index) {
3245
- for (var field in columns) {
3246
- var column = columns[field];
3247
- if (!_this19.isRequiredColumn(column)) continue;
3248
- var value = row[field];
3249
- var empty = isEmpty(value) || isArray(value) && !value.length || isEmptyObject(value);
3250
- if (!empty) continue;
3251
- var caption = column.cShowCaption || column.cCaption || column.cCaption || column.title || field;
3252
- errors.push({
3253
- rowIndex: index,
3254
- rowId: row[_this19.getIdFlag()],
3255
- cellName: field,
3256
- message: "".concat(caption, "\u4E0D\u80FD\u4E3A\u7A7A")
3257
- });
3258
- _this19.setCellState(index, field, 'msg', '不能为空');
3259
- }
3260
- });
3261
- this._set_data('validateErrors', errors);
3262
- var message = errors.length ? errors[0].message : '';
3263
- this.doPropertyChange('validate', {
3264
- type: errors.length ? 'error' : '',
3265
- message: message,
3266
- errors: errors
3267
- });
3268
- this.execute('afterValidate', {
3269
- valid: !errors.length,
3270
- errors: errors
3271
- });
3272
- return !errors.length;
2124
+ key: "setTotalCount",
2125
+ value: function setTotalCount(total) {
2126
+ var totalField = this._get_data('innerUsedAttrs').pageCount;
2127
+ this.getPageInfo()[totalField] = total;
3273
2128
  }
3274
2129
  }]);
3275
- }(BaseModel);
2130
+ }(BaseModel$1);
3276
2131
 
3277
- var ViewModel = /*#__PURE__*/function (_BaseModel) {
2132
+ var ViewModel$1 = /*#__PURE__*/function (_BaseModel) {
3278
2133
  function ViewModel() {
2134
+ var _this;
3279
2135
  _classCallCheck(this, ViewModel);
3280
- 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;
3281
2142
  }
3282
2143
  _inherits(ViewModel, _BaseModel);
3283
2144
  return _createClass(ViewModel, [{
@@ -3293,7 +2154,7 @@
3293
2154
  }, {
3294
2155
  key: "set",
3295
2156
  value: function set(propertyName, value) {
3296
- if (value instanceof BaseModel) {
2157
+ if (value instanceof BaseModel$1) {
3297
2158
  value.setParent(this);
3298
2159
  value.setName(propertyName);
3299
2160
  }
@@ -3319,12 +2180,12 @@
3319
2180
  }, {
3320
2181
  key: "getData",
3321
2182
  value: function getData() {
3322
- var _this = this;
2183
+ var _this2 = this;
3323
2184
  var propertyNames = this._get_data('propertyNames') || [];
3324
2185
  var data = {};
3325
2186
  propertyNames.forEach(function (propertyName) {
3326
- var property = _this.get(propertyName);
3327
- 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) {
3328
2189
  var _property$getData;
3329
2190
  data[propertyName] = (_property$getData = property.getData) === null || _property$getData === void 0 ? void 0 : _property$getData.call(property);
3330
2191
  }
@@ -3332,20 +2193,20 @@
3332
2193
  return data;
3333
2194
  }
3334
2195
 
3335
- /**
3336
- * 收集全部属性数据
3337
- * @param withOutGrid 为 true 时跳过标记了 isGrid 的子模型(子表格)
2196
+ /**
2197
+ * 收集全部属性数据
2198
+ * @param withOutGrid 为 true 时跳过标记了 isGrid 的子模型(子表格)
3338
2199
  */
3339
2200
  }, {
3340
2201
  key: "getAllData",
3341
2202
  value: function getAllData(withOutGrid) {
3342
- var _this2 = this;
2203
+ var _this3 = this;
3343
2204
  var propertyNames = this._get_data('propertyNames') || [];
3344
2205
  var rawData = {};
3345
2206
  propertyNames.forEach(function (propertyName) {
3346
2207
  var _property$getData2;
3347
- var property = _this2.get(propertyName);
3348
- 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) {
3349
2210
  return;
3350
2211
  }
3351
2212
  if (withOutGrid && property._get_data('isGrid')) {
@@ -3380,11 +2241,11 @@
3380
2241
  }, {
3381
2242
  key: "clear",
3382
2243
  value: function clear(useDefault) {
3383
- var _this3 = this;
2244
+ var _this4 = this;
3384
2245
  var propertyNames = this._get_data('propertyNames') || [];
3385
2246
  propertyNames.forEach(function (propertyName) {
3386
- var property = _this3.get(propertyName);
3387
- 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) {
3388
2249
  var _property$clear;
3389
2250
  (_property$clear = property.clear) === null || _property$clear === void 0 || _property$clear.call(property, useDefault);
3390
2251
  }
@@ -3418,7 +2279,7 @@
3418
2279
  var propertyNames = this._get_data('propertyNames');
3419
2280
  for (var i = 0, len = propertyNames.length; i < len; i++) {
3420
2281
  gridModel = this.get(propertyNames[i]);
3421
- var isGridModel = gridModel instanceof GridModel;
2282
+ var isGridModel = gridModel instanceof GridModel$1 || gridModel.modelType == 'GridModel';
3422
2283
  if (isGridModel) {
3423
2284
  this._set_data('gridModel', gridModel);
3424
2285
  return gridModel;
@@ -3432,42 +2293,237 @@
3432
2293
  var gridModels = [];
3433
2294
  for (var i = 0, len = propertyNames.length; i < len; i++) {
3434
2295
  var gridModel = this.get(propertyNames[i]);
3435
- if (gridModel instanceof GridModel) {
2296
+ var isGridModel = gridModel instanceof GridModel$1 || gridModel.modelType == 'GridModel';
2297
+ if (isGridModel) {
3436
2298
  gridModels.push(gridModel);
3437
2299
  }
3438
2300
  }
3439
2301
  return gridModels;
3440
2302
  }
2303
+ }, {
2304
+ key: "getGridFilterModel",
2305
+ value: function getGridFilterModel(propertyName) {
2306
+ var gridModel = this.getGridModel(propertyName);
2307
+ return gridModel.getCache('FilterViewModel');
2308
+ }
3441
2309
  }]);
3442
- }(BaseModel);
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;
2323
+ }
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
+ });
2373
+ }
3443
2374
 
3444
- function createModelFactory(props) {
3445
- var cControlType = props.cControlType.toLowerCase();
2375
+ // 初始化拓展脚本
2376
+ function initExtendScripts(params) {
2377
+ var self = this;
2378
+ if (window.devfab && window.devfab.__debugger_initExtendJs) {
2379
+ // eslint-disable-next-line no-debugger
2380
+ debugger;
2381
+ }
2382
+ var requirejs = params.requirejs,
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");
2391
+ self.execute('extendReady', self);
2392
+ return;
2393
+ }
2394
+ if (!scriptUrl) {
2395
+ window.devfab.debug && console.info("[devfab][extendjs] \u6269\u5C55\u811A\u672C\u672A\u5B9A\u4E49");
2396
+ self.execute('extendReady', self);
2397
+ return;
2398
+ }
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);
2411
+ }
2412
+ }
2413
+ self.execute('extendReady', self);
2414
+ });
2415
+ }
2416
+
2417
+ // 初始化客开脚本
2418
+ var initExtScripts = /*#__PURE__*/function () {
2419
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(data, vm, params) {
2420
+ var _vm$getParams, _exturls;
2421
+ var requirejs, extendScriptParams, _ref3, _ref3$enableExtJs, enableExtJs, _ref3$exturlsField, exturlsField, extscripturls, exturls;
2422
+ return _regenerator().w(function (_context2) {
2423
+ while (1) switch (_context2.n) {
2424
+ case 0:
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 : []; // 支持注入单据级本地化扩展脚本
2447
+ exturls = (vm.getCache('localDynamicScripts') || []).concat(exturls);
2448
+
2449
+ // 支持给全单据注入扩展脚本
2450
+ exturls = exturls.concat(window.__devfab__EXT_BILL_SCRIPTS__ || []);
2451
+
2452
+ // 支持参数注入扩展脚本
2453
+ if ((_vm$getParams = vm.getParams()) !== null && _vm$getParams !== void 0 && _vm$getParams.initVMExtUrls) {
2454
+ exturls = exturls.concat([vm.getParams().initVMExtUrls]);
2455
+ }
2456
+
2457
+ // 预处理扩展脚本
2458
+ if (!((_exturls = exturls) !== null && _exturls !== void 0 && _exturls.length)) {
2459
+ _context2.n = 4;
2460
+ break;
2461
+ }
2462
+ exturls = _toConsumableArray(new Set(exturls));
2463
+ _context2.n = 3;
2464
+ return Promise.all(exturls.map(/*#__PURE__*/function () {
2465
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
2466
+ return _regenerator().w(function (_context) {
2467
+ while (1) switch (_context.n) {
2468
+ case 0:
2469
+ return _context.a(2, url);
2470
+ }
2471
+ }, _callee);
2472
+ }));
2473
+ return function (_x4) {
2474
+ return _ref4.apply(this, arguments);
2475
+ };
2476
+ }()));
2477
+ case 3:
2478
+ exturls = _context2.v;
2479
+ case 4:
2480
+ // 加载扩展脚本
2481
+ data[exturlsField] = exturls;
2482
+ return _context2.a(2, new Promise(function (resolve, reject) {
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
+ }
2491
+ resolve(true);
2492
+ });
2493
+ }));
2494
+ }
2495
+ }, _callee2);
2496
+ }));
2497
+ return function initExtScripts(_x, _x2, _x3) {
2498
+ return _ref2.apply(this, arguments);
2499
+ };
2500
+ }();
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();
3446
2510
  var model;
3447
2511
  switch (cControlType) {
3448
2512
  case 'input':
3449
2513
  model = new SimpleModel(props);
3450
2514
  break;
2515
+ default:
2516
+ model = new SimpleModel(props);
2517
+ break;
3451
2518
  }
3452
2519
  return model;
3453
2520
  }
3454
- function createViewModel(meta, params) {
3455
- var _window$__devfab;
3456
- var _require = (_window$__devfab = window.__devfab) === null || _window$__devfab === void 0 ? void 0 : _window$__devfab.require;
3457
- var _ref = params || {},
3458
- _ref$domainKeyField = _ref.domainKeyField,
3459
- domainKeyField = _ref$domainKeyField === void 0 ? 'domainKey' : _ref$domainKeyField,
3460
- _ref$billNoField = _ref.billNoField,
3461
- billNoField = _ref$billNoField === void 0 ? 'billNo' : _ref$billNoField,
3462
- _ref$modelNameField = _ref.modelNameField,
3463
- modelNameField = _ref$modelNameField === void 0 ? 'modelName' : _ref$modelNameField,
3464
- _ref$enableExtendjs = _ref.enableExtendjs,
3465
- enableExtendjs = _ref$enableExtendjs === void 0 ? true : _ref$enableExtendjs;
3466
- if (params !== null && params !== void 0 && params.require) {
3467
- _require = params === null || params === void 0 ? void 0 : params.require;
3468
- }
3469
- var domainKey = meta[domainKeyField] || '';
3470
- var billno = meta[billNoField];
2521
+ function _createViewModel(meta) {
2522
+ var _params$models;
2523
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2524
+ var _params$modelNameFiel = params.modelNameField,
2525
+ modelNameField = _params$modelNameFiel === void 0 ? 'cName' : _params$modelNameFiel;
2526
+ var ViewModel = (params === null || params === void 0 || (_params$models = params.models) === null || _params$models === void 0 ? void 0 : _params$models.ViewModel) || ViewModel$1;
3471
2527
  var VM = /*#__PURE__*/function (_ViewModel) {
3472
2528
  function VM() {
3473
2529
  _classCallCheck(this, VM);
@@ -3486,87 +2542,84 @@
3486
2542
  value: function createModels(_models, meta) {
3487
2543
  var fields = {};
3488
2544
  var models = Array.isArray(_models) ? _models : [];
3489
- models.forEach(function (m) {
3490
- var _params$createModelFa, _params$onBeforeCreat;
3491
- var model = params === null || params === void 0 || (_params$createModelFa = params.createModelFactory) === null || _params$createModelFa === void 0 ? void 0 : _params$createModelFa.call(params, m);
3492
- if (!model) {
3493
- model = createModelFactory(m);
3494
- }
2545
+ models.forEach(function (field) {
2546
+ var _params$onBeforeInitM, _params$onAfterInitMo;
2547
+ var model = createModelFactory(field, params);
2548
+ var modelName = field[modelNameField];
3495
2549
  var param = {
3496
2550
  model: model,
3497
- field: m,
3498
- meta: meta
2551
+ meta: field,
2552
+ childModel: true,
2553
+ modelName: modelName
3499
2554
  };
3500
- params === null || params === void 0 || (_params$onBeforeCreat = params.onBeforeCreateModel) === null || _params$onBeforeCreat === void 0 || _params$onBeforeCreat.call(params, param);
3501
- 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);
3502
2558
  });
3503
2559
  return fields;
3504
2560
  }
3505
2561
  }, {
3506
2562
  key: "initData",
3507
2563
  value: function initData() {
3508
- this.initExtendJs();
3509
- }
3510
- }, {
3511
- key: "initExtendJs",
3512
- value: function initExtendJs() {
3513
- if (window && window.__debugger_initExtendJs) {
3514
- // eslint-disable-next-line no-debugger
3515
- debugger;
3516
- }
3517
- var self = this;
3518
- if (!enableExtendjs) {
3519
- self.execute('extendReady', self);
3520
- return;
3521
- }
3522
- var extendFile = "".concat(billno, "_VM.Extend.js");
3523
- var extendFiles = [extendFile];
3524
- // if (self.getEnv && self.getEnv('everyCommonExtend')) {
3525
- // extendFiles.push(self.getEnv('everyCommonExtend'))
3526
- // }
3527
- if (typeof _require !== 'function') {
3528
- console.warn("requirejs.js \u672A\u52A0\u8F7D\uFF0C\u8DF3\u8FC7\u6269\u5C55\u811A\u672C\uFF1A".concat(extendFile));
3529
- self.execute('extendReady', self);
3530
- return;
3531
- }
3532
- _require(domainKey, extendFiles, function (extend, everyCommonExtend) {
3533
- if (extend && extend.doAction) {
3534
- // 处理扩展脚本异常导致渲染失败
3535
- try {
3536
- extend.doAction('init', self);
3537
- if (everyCommonExtend) {
3538
- everyCommonExtend.doAction('init', self);
3539
- }
3540
- } catch (err) {
3541
- console.error('扩展脚本异常:', err);
3542
- }
3543
- } else {
3544
- console.error("".concat(extendFile, "\u6269\u5C55\u6587\u4EF6extend.*.min.js\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25 \u6216 \u672A\u6CE8\u518C\u6269\u5C55\u811A\u672C"));
3545
- }
3546
- self.execute('extendReady', self);
3547
- }, function (err) {
3548
- console.warn("\u672A\u627E\u5230\u6269\u5C55\u811A\u672C\uFF1A".concat(extendFile, "\u9519\u8BEF\u4FE1\u606F\uFF1A"), err);
3549
- self.execute('extendReady', self);
3550
- });
2564
+ initExtendScripts.call(this, params);
3551
2565
  }
3552
2566
  }]);
3553
2567
  }(ViewModel);
3554
2568
  VM.prototype.modelType = 'ViewModel';
3555
2569
  return VM;
3556
2570
  }
3557
- function initViewModel(meta, params) {
3558
- var ContainerModel = createViewModel(meta, params);
3559
- var vm = new ContainerModel();
3560
- vm.init(meta.models, meta);
2571
+ function _initViewModel(meta, params) {
2572
+ var _params$onBeforeInitM2, _vm$init, _params$onAfterInitMo2;
2573
+ var VM = _createViewModel(meta, params);
2574
+ var vm = new VM();
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);
2583
+ return vm;
2584
+ }
2585
+ function initViewModel(meta) {
2586
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2587
+ var callback = arguments.length > 2 ? arguments[2] : undefined;
2588
+ if (!(params !== null && params !== void 0 && params.requirejs)) {
2589
+ params.requirejs = window.__devfab;
2590
+ }
2591
+ var vm = _initViewModel(meta, params);
2592
+ vm.on('destroyVM', function () {
2593
+ var _vm, _vm$destroyVM;
2594
+ (_vm = vm) === null || _vm === void 0 || (_vm$destroyVM = _vm.destroyVM) === null || _vm$destroyVM === void 0 || _vm$destroyVM.call(_vm);
2595
+ vm = null;
2596
+ window.devfab.debug && console.info("[devfab][initVM]: destory vm ".concat(new Date().toString()));
2597
+ });
2598
+ vm.on('extendReady', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2599
+ var promises;
2600
+ return _regenerator().w(function (_context) {
2601
+ while (1) switch (_context.n) {
2602
+ case 0:
2603
+ promises = []; // 加载客开脚本
2604
+ promises.push(initExtScripts(meta, vm, params));
2605
+ _context.n = 1;
2606
+ return Promise.all(promises);
2607
+ case 1:
2608
+ window.devfab.debug && console.info("[devfab][initVM]: after vm init ".concat(new Date().toString()));
2609
+ callback === null || callback === void 0 || callback(vm, meta);
2610
+ case 2:
2611
+ return _context.a(2);
2612
+ }
2613
+ }, _callee);
2614
+ })));
2615
+ vm.initData();
3561
2616
  return vm;
3562
2617
  }
3563
2618
  var models = {
3564
2619
  BaseModel: BaseModel,
3565
- FilterModel: FilterModel,
3566
2620
  SimpleModel: SimpleModel,
3567
2621
  GridModel: GridModel,
3568
2622
  ViewModel: ViewModel,
3569
- createViewModel: createViewModel,
3570
2623
  initViewModel: initViewModel
3571
2624
  };
3572
2625
 
@@ -3578,6 +2631,7 @@
3578
2631
  };
3579
2632
 
3580
2633
  var devfab = {
2634
+ debug: false,
3581
2635
  utils: {
3582
2636
  builder: new utils.Builder(),
3583
2637
  cache: new utils.CacheUtil(),
@@ -3589,6 +2643,7 @@
3589
2643
  utils: utils
3590
2644
  }
3591
2645
  };
2646
+ window.devfab = devfab;
3592
2647
 
3593
2648
  exports["default"] = devfab;
3594
2649