devfab 1.0.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 ADDED
@@ -0,0 +1,3585 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.devfab = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ function _arrayLikeToArray(r, a) {
8
+ (null == a || a > r.length) && (a = r.length);
9
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
+ return n;
11
+ }
12
+ function _arrayWithHoles(r) {
13
+ if (Array.isArray(r)) return r;
14
+ }
15
+ function _arrayWithoutHoles(r) {
16
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
17
+ }
18
+ function _assertThisInitialized(e) {
19
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
20
+ return e;
21
+ }
22
+ function _callSuper(t, o, e) {
23
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
24
+ }
25
+ function _classCallCheck(a, n) {
26
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
27
+ }
28
+ function _defineProperties(e, r) {
29
+ for (var t = 0; t < r.length; t++) {
30
+ var o = r[t];
31
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
32
+ }
33
+ }
34
+ function _createClass(e, r, t) {
35
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
36
+ writable: !1
37
+ }), e;
38
+ }
39
+ function _defineProperty(e, r, t) {
40
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
41
+ value: t,
42
+ enumerable: !0,
43
+ configurable: !0,
44
+ writable: !0
45
+ }) : e[r] = t, e;
46
+ }
47
+ function _getPrototypeOf(t) {
48
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
49
+ return t.__proto__ || Object.getPrototypeOf(t);
50
+ }, _getPrototypeOf(t);
51
+ }
52
+ function _inherits(t, e) {
53
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
54
+ t.prototype = Object.create(e && e.prototype, {
55
+ constructor: {
56
+ value: t,
57
+ writable: !0,
58
+ configurable: !0
59
+ }
60
+ }), Object.defineProperty(t, "prototype", {
61
+ writable: !1
62
+ }), e && _setPrototypeOf(t, e);
63
+ }
64
+ function _isNativeReflectConstruct() {
65
+ try {
66
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
67
+ } catch (t) {}
68
+ return (_isNativeReflectConstruct = function () {
69
+ return !!t;
70
+ })();
71
+ }
72
+ function _iterableToArray(r) {
73
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
74
+ }
75
+ function _iterableToArrayLimit(r, l) {
76
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
77
+ if (null != t) {
78
+ var e,
79
+ n,
80
+ i,
81
+ u,
82
+ a = [],
83
+ f = !0,
84
+ o = !1;
85
+ try {
86
+ if (i = (t = t.call(r)).next, 0 === l) {
87
+ if (Object(t) !== t) return;
88
+ f = !1;
89
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
90
+ } catch (r) {
91
+ o = !0, n = r;
92
+ } finally {
93
+ try {
94
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
95
+ } finally {
96
+ if (o) throw n;
97
+ }
98
+ }
99
+ return a;
100
+ }
101
+ }
102
+ function _nonIterableRest() {
103
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
104
+ }
105
+ function _nonIterableSpread() {
106
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
107
+ }
108
+ function ownKeys(e, r) {
109
+ var t = Object.keys(e);
110
+ if (Object.getOwnPropertySymbols) {
111
+ var o = Object.getOwnPropertySymbols(e);
112
+ r && (o = o.filter(function (r) {
113
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
114
+ })), t.push.apply(t, o);
115
+ }
116
+ return t;
117
+ }
118
+ function _objectSpread2(e) {
119
+ for (var r = 1; r < arguments.length; r++) {
120
+ var t = null != arguments[r] ? arguments[r] : {};
121
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
122
+ _defineProperty(e, r, t[r]);
123
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
124
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
125
+ });
126
+ }
127
+ return e;
128
+ }
129
+ function _objectWithoutProperties(e, t) {
130
+ if (null == e) return {};
131
+ var o,
132
+ r,
133
+ i = _objectWithoutPropertiesLoose(e, t);
134
+ if (Object.getOwnPropertySymbols) {
135
+ var n = Object.getOwnPropertySymbols(e);
136
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
137
+ }
138
+ return i;
139
+ }
140
+ function _objectWithoutPropertiesLoose(r, e) {
141
+ if (null == r) return {};
142
+ var t = {};
143
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
144
+ if (-1 !== e.indexOf(n)) continue;
145
+ t[n] = r[n];
146
+ }
147
+ return t;
148
+ }
149
+ function _possibleConstructorReturn(t, e) {
150
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
151
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
152
+ return _assertThisInitialized(t);
153
+ }
154
+ function _setPrototypeOf(t, e) {
155
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
156
+ return t.__proto__ = e, t;
157
+ }, _setPrototypeOf(t, e);
158
+ }
159
+ function _slicedToArray(r, e) {
160
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
161
+ }
162
+ function _toConsumableArray(r) {
163
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
164
+ }
165
+ function _toPrimitive(t, r) {
166
+ if ("object" != typeof t || !t) return t;
167
+ var e = t[Symbol.toPrimitive];
168
+ if (void 0 !== e) {
169
+ var i = e.call(t, r || "default");
170
+ if ("object" != typeof i) return i;
171
+ throw new TypeError("@@toPrimitive must return a primitive value.");
172
+ }
173
+ return ("string" === r ? String : Number)(t);
174
+ }
175
+ function _toPropertyKey(t) {
176
+ var i = _toPrimitive(t, "string");
177
+ return "symbol" == typeof i ? i : i + "";
178
+ }
179
+ function _typeof(o) {
180
+ "@babel/helpers - typeof";
181
+
182
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
183
+ return typeof o;
184
+ } : function (o) {
185
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
186
+ }, _typeof(o);
187
+ }
188
+ function _unsupportedIterableToArray(r, a) {
189
+ if (r) {
190
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
191
+ var t = {}.toString.call(r).slice(8, -1);
192
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
193
+ }
194
+ }
195
+
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;
203
+ }
204
+ if (typeof name === 'string') {
205
+ if (components[name]) {
206
+ console.log("[warning] Component ".concat(name, " is exist!"));
207
+ return;
208
+ }
209
+ components[name] = comp;
210
+ return;
211
+ }
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;
222
+ }
223
+ function renderComponent(config, extraConfig) {
224
+ if (!Array.isArray(config)) {
225
+ return;
226
+ }
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);
257
+ }
258
+ });
259
+ return _component;
260
+ }
261
+ var Builder = /*#__PURE__*/function () {
262
+ function Builder() {
263
+ _classCallCheck(this, Builder);
264
+ }
265
+ return _createClass(Builder, [{
266
+ key: "init",
267
+ value: function init(fn) {
268
+ if (isInit) {
269
+ return;
270
+ }
271
+ if (typeof fn === 'function') {
272
+ fn();
273
+ }
274
+ isInit = true;
275
+ }
276
+ }, {
277
+ key: "initComponent",
278
+ value: function initComponent(name, comp) {
279
+ _initComponent(name, comp);
280
+ }
281
+ }, {
282
+ key: "getComponents",
283
+ value: function getComponents() {
284
+ return _objectSpread2({}, components);
285
+ }
286
+ }, {
287
+ key: "getComponent",
288
+ value: function getComponent(name) {
289
+ return _getComponent(name);
290
+ }
291
+ }, {
292
+ key: "hasComponent",
293
+ value: function hasComponent(name) {
294
+ return !!_getComponent(name);
295
+ }
296
+ }, {
297
+ key: "initRenderFactory",
298
+ value: function initRenderFactory(fn) {
299
+ _initRenderFactory(fn);
300
+ }
301
+ }, {
302
+ key: "initRequest",
303
+ value: function initRequest() {
304
+ //
305
+ }
306
+ }, {
307
+ key: "render",
308
+ 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;
317
+ }
318
+ }]);
319
+ }();
320
+
321
+ var CacheUtil = /*#__PURE__*/function () {
322
+ function CacheUtil(args) {
323
+ _classCallCheck(this, CacheUtil);
324
+ this._init(args);
325
+ }
326
+ return _createClass(CacheUtil, [{
327
+ key: "_init",
328
+ value: function _init(args) {
329
+ this.cache = Object.assign({}, args);
330
+ }
331
+ }, {
332
+ key: "set",
333
+ value: function set(key, value) {
334
+ this.cache[key] = value;
335
+ }
336
+ }, {
337
+ key: "get",
338
+ value: function get(key) {
339
+ var _this$cache;
340
+ return (_this$cache = this.cache) === null || _this$cache === void 0 ? void 0 : _this$cache[key];
341
+ }
342
+ }, {
343
+ key: "clear",
344
+ value: function clear(key) {
345
+ delete this.cache[key];
346
+ }
347
+ }]);
348
+ }();
349
+
350
+ var EventUtil = /*#__PURE__*/function () {
351
+ function EventUtil() {
352
+ _classCallCheck(this, EventUtil);
353
+ this._init();
354
+ }
355
+ return _createClass(EventUtil, [{
356
+ key: "_init",
357
+ value: function _init() {
358
+ this.events = new Map();
359
+ this.firstevents = new Map();
360
+ }
361
+ }, {
362
+ key: "on",
363
+ value: function on(name, callback, context) {
364
+ var fnList = this.events.get(name);
365
+ if (!Array.isArray(fnList)) {
366
+ fnList = [];
367
+ }
368
+ fnList.push({
369
+ callback: callback,
370
+ context: context
371
+ });
372
+ this.events.set(name, fnList);
373
+ }
374
+ }, {
375
+ key: "onFirst",
376
+ value: function onFirst(name, callback, context) {
377
+ var fnList = this.firstevents.get(name);
378
+ if (!Array.isArray(fnList)) {
379
+ fnList = [];
380
+ }
381
+ fnList.splice(0, 0, {
382
+ callback: callback,
383
+ context: context
384
+ });
385
+ this.firstevents.set(name, fnList);
386
+ }
387
+ }, {
388
+ key: "execute",
389
+ value: function execute(name) {
390
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
391
+ args[_key - 1] = arguments[_key];
392
+ }
393
+ var events = this.events.get(name);
394
+ var firstevents = this.firstevents.get(name);
395
+ if (!events && !firstevents) {
396
+ return true;
397
+ }
398
+ var result = true;
399
+ var allEvents = [].concat(_toConsumableArray(firstevents || []), _toConsumableArray(events || []));
400
+ allEvents.forEach(function (item) {
401
+ if (result === false) {
402
+ return;
403
+ }
404
+ var returnData = item.callback.apply(item.context || undefined, args);
405
+ result = returnData === false ? false : result;
406
+ });
407
+ return result;
408
+ }
409
+ }, {
410
+ key: "un",
411
+ value: function un(name, callback) {
412
+ this._unEvents(name, callback, this.events);
413
+ this._unEvents(name, callback, this.firstevents);
414
+ }
415
+ }, {
416
+ key: "_unEvents",
417
+ value: function _unEvents(name, callback, events) {
418
+ if (!name || !events.has(name)) {
419
+ return;
420
+ }
421
+ if (!callback) {
422
+ events["delete"](name);
423
+ } else {
424
+ var fnList = events.get(name);
425
+ var index = fnList === null || fnList === void 0 ? void 0 : fnList.findIndex(function (item) {
426
+ return item.callback === callback;
427
+ });
428
+ if (index !== -1) {
429
+ fnList === null || fnList === void 0 || fnList.splice(index, 1);
430
+ }
431
+ }
432
+ }
433
+ }, {
434
+ key: "hasEvent",
435
+ value: function hasEvent(name) {
436
+ var _this$events$get, _this$firstevents$get;
437
+ if (!name) {
438
+ return 0;
439
+ }
440
+ var eventsLen = ((_this$events$get = this.events.get(name)) === null || _this$events$get === void 0 ? void 0 : _this$events$get.length) || 0;
441
+ var firsteventsLen = ((_this$firstevents$get = this.firstevents.get(name)) === null || _this$firstevents$get === void 0 ? void 0 : _this$firstevents$get.length) || 0;
442
+ return eventsLen + firsteventsLen;
443
+ }
444
+ }, {
445
+ key: "fireEvent",
446
+ value: function fireEvent(eventName, args) {
447
+ if (!this.execute("before".concat(eventName), args)) {
448
+ return;
449
+ }
450
+ this.execute(eventName, args);
451
+ this.execute("after".concat(eventName), args);
452
+ }
453
+ }, {
454
+ key: "_asyncExecute",
455
+ value: function _asyncExecute(name, events, params) {
456
+ var _this = this;
457
+ var _resolve = params.resolve,
458
+ _reject = params.reject,
459
+ args = params.args;
460
+ var result = true;
461
+ var allEvents = events || [];
462
+ var promiseResult = false;
463
+ var _loop = function _loop(i) {
464
+ // if (i == allEvents.length - 1) {
465
+ // console.warn('最后一次啦', name)
466
+ // }
467
+ var event = allEvents[i];
468
+ if (result === false) {
469
+ return 0; // break
470
+ }
471
+ if (promiseResult) {
472
+ return {
473
+ v: void 0
474
+ };
475
+ }
476
+ var returnData;
477
+ if (process.env.nodeEnv === 'development') {
478
+ returnData = event.callback.apply(event.context || _this, args);
479
+ } else {
480
+ try {
481
+ returnData = event.callback.apply(event.context || _this, args);
482
+ } catch (e) {
483
+ if (!e.isAddedMsg) {
484
+ e.message = "(\u9886\u57DF\u6269\u5C55\u4E8B\u4EF6\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u6253\u5F00\u63A7\u5236\u53F0\u67E5\u770B\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F\u5E76\u4FEE\u590D):".concat(e.message); // @notranslate
485
+ }
486
+ e.isAddedMsg = true;
487
+ throw e;
488
+ }
489
+ }
490
+ if (returnData instanceof Promise) {
491
+ promiseResult = true;
492
+ result = returnData;
493
+ result.callbacks && result.callbacks.push({
494
+ reject: function reject() {
495
+ result.reject();
496
+ if (i === allEvents.length - 1) {
497
+ _reject === null || _reject === void 0 || _reject();
498
+ }
499
+ },
500
+ resolve: function resolve(res) {
501
+ if (i === allEvents.length - 1) {
502
+ args.length > 1 && (args[0] = res);
503
+ _resolve === null || _resolve === void 0 || _resolve(args);
504
+ } else {
505
+ _this._asyncExecute(name, allEvents.slice(i + 1), {
506
+ resolve: _resolve,
507
+ reject: _reject,
508
+ args: args
509
+ });
510
+ }
511
+ }
512
+ });
513
+ // 这里是因为下面promiseExecute里历史代码判定如果是undefined也会认为是false,但是此时是阻断机制所以不能不返回内容
514
+ // 但是这里有个额外的问题,就是如何让事件队列全结束才执行promiseExecutue的callback也就是then?
515
+ // return result;
516
+ } else {
517
+ result = returnData === false ? false : result;
518
+ if (i === allEvents.length - 1) {
519
+ result ? _resolve === null || _resolve === void 0 ? void 0 : _resolve(args) : _reject === null || _reject === void 0 ? void 0 : _reject();
520
+ }
521
+ }
522
+ },
523
+ _ret;
524
+ for (var i = 0; i < allEvents.length; i++) {
525
+ _ret = _loop(i);
526
+ if (_ret === 0) break;
527
+ if (_ret) return _ret.v;
528
+ }
529
+ return result;
530
+ }
531
+ }, {
532
+ key: "_asyncPromiseExecute",
533
+ value: function _asyncPromiseExecute(name, resolve, reject, args) {
534
+ var events = this.events.get(name);
535
+ var firstevents = this.firstevents.get(name);
536
+ if ((Array.isArray(events) ? !events.length : !events) && (Array.isArray(firstevents) ? !firstevents.length : !firstevents)) {
537
+ return resolve === null || resolve === void 0 ? void 0 : resolve();
538
+ }
539
+ var allEvents = [].concat(_toConsumableArray(firstevents || []), _toConsumableArray(events || []));
540
+ return this._asyncExecute(name, allEvents, {
541
+ resolve: resolve,
542
+ reject: reject,
543
+ args: args
544
+ });
545
+ }
546
+ }, {
547
+ key: "promiseExecute",
548
+ value: function promiseExecute(check, eventName) {
549
+ var _this2 = this;
550
+ var name = check;
551
+ var sliceStart = 1;
552
+ if (typeof check === 'boolean') {
553
+ name = eventName;
554
+ sliceStart = 2;
555
+ }
556
+ if (!name) {
557
+ return;
558
+ }
559
+ // 使用 rest 参数替代 arguments,根据 sliceStart 构造参数数组,行为与原 slice.call(arguments, sliceStart) 一致
560
+ for (var _len2 = arguments.length, rest = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
561
+ rest[_key2 - 2] = arguments[_key2];
562
+ }
563
+ var args = sliceStart === 2 ? rest : [eventName].concat(rest);
564
+ if (!args.length) {
565
+ return;
566
+ }
567
+ var callbackIndex = args.length - 1;
568
+ var callback = args[callbackIndex];
569
+ var errCallBack;
570
+ if (typeof callback !== 'function') {
571
+ if (_typeof(callback) === 'object' && callback[0] && typeof callback[0] === 'function' && callback[1] && typeof callback[1] === 'function') {
572
+ errCallBack = callback[1];
573
+ callback = callback[0];
574
+ } else {
575
+ return;
576
+ }
577
+ }
578
+ if (window.__ASYNC_EXECUTE__) {
579
+ return this._asyncPromiseExecute(name, function (args) {
580
+ callback.apply(_this2, args);
581
+ }, function () {
582
+ if (errCallBack && typeof errCallBack === 'function') {
583
+ errCallBack();
584
+ }
585
+ }, args);
586
+ }
587
+ // 非__ASYNC_EXECUTE__的时候参数处理放下面
588
+ args.splice(callbackIndex, 1);
589
+ args.unshift(name);
590
+ var returnData = this.execute.apply(this, args);
591
+ if (returnData instanceof Promise) {
592
+ var self = this;
593
+ /**
594
+ * 背景参考下面的else注释,当第二次命中这里的时候,会在promise执行的时候直接then了,因为没有重新走一遍判定,这里直接执行了callback
595
+ * 解决方案:想着是想办法把then里的代码作为callback传进去最后在执行,但是没想到方案
596
+ */
597
+ returnData.then(function () {
598
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
599
+ args[_key3] = arguments[_key3];
600
+ }
601
+ callback.apply(self, args);
602
+ }, function () {
603
+ if (errCallBack && typeof errCallBack === 'function') {
604
+ errCallBack();
605
+ }
606
+ });
607
+ } else {
608
+ /*
609
+ 这里是因为历史代码没有考虑promise得情况 导致直接使用!returnData做结果判定,但是undefined也会命中false 导致后续执行阻断,不做callback了,所以会有问题,加了下面代码还是有问题,因为如果命中了promise得话没有返回值
610
+ 导致命中不了returnData === false 导致阻断,所以上面execute里promise的时候将整个results返回,但是加了还有另外的问题,就是如果有两个分开的promise 会导致第一次好使,第二次命中了上面的if
611
+ */
612
+ // if (window.__ASYNC_EXECUTE__ ? returnData === false : !returnData) {
613
+ if (!returnData) {
614
+ if (errCallBack && typeof errCallBack === 'function') {
615
+ errCallBack();
616
+ }
617
+ return;
618
+ }
619
+ }
620
+ // let name
621
+ // let args
622
+ // if (typeof check === 'boolean') {
623
+ // name = eventName
624
+ // args = restArgs
625
+ // } else {
626
+ // name = check
627
+ // args = restArgs
628
+ // }
629
+ // if (!name) {
630
+ // return
631
+ // }
632
+ // if (!args.length) {
633
+ // return
634
+ // }
635
+
636
+ // const callbackIndex = args.length - 1
637
+ // let callback = args[callbackIndex]
638
+ // let errCallBack
639
+
640
+ // if (typeof callback !== 'function') {
641
+ // if (Array.isArray(callback) && callback[0] && typeof callback[0] === 'function' && callback[1] && typeof callback[1] === 'function') {
642
+ // errCallBack = callback[1]
643
+ // callback = callback[0]
644
+ // } else {
645
+ // return
646
+ // }
647
+ // }
648
+ // args.splice(callbackIndex, 1)
649
+
650
+ // const returnData = this.execute.apply(this, [name, ...args])
651
+ // if (returnData instanceof Promise) {
652
+ // returnData.then(
653
+ // (...resultArgs) => {
654
+ // callback.apply(this, resultArgs)
655
+ // },
656
+ // () => {
657
+ // if (errCallBack && typeof errCallBack === 'function') {
658
+ // errCallBack()
659
+ // }
660
+ // }
661
+ // )
662
+ // } else {
663
+ // if (!returnData) {
664
+ // if (errCallBack && typeof errCallBack === 'function') {
665
+ // errCallBack()
666
+ // }
667
+ // return
668
+ // }
669
+ // callback.call(this)
670
+ // }
671
+ }
672
+ }, {
673
+ key: "clearEvents",
674
+ value: function clearEvents() {
675
+ this.events.clear();
676
+ this.firstevents.clear();
677
+ }
678
+ }]);
679
+ }();
680
+
681
+ function QueryString(_url) {
682
+ this.pathname = '';
683
+ this.query = {};
684
+ var url = _url;
685
+ this.init = function () {
686
+ if (!url) {
687
+ url = location.search;
688
+ }
689
+ var index1 = url.indexOf('?');
690
+ var index2 = url.indexOf('#');
691
+ if (index1 >= 0) {
692
+ this.pathname = url.substr(0, index1);
693
+ url = index2 < 0 ? url.substr(index1 + 1) : url.substring(index1 + 1, index2);
694
+ if (url.length > 0) {
695
+ url = url.replace(/\+/g, ' ');
696
+ var params = url.split('&');
697
+ for (var i = 0, len = params.length; i < len; i++) {
698
+ var param = params[i] || '';
699
+ if (param) {
700
+ var index = param.indexOf('=');
701
+ var key = '';
702
+ var value = '';
703
+ if (index < 0) {
704
+ key = window.decode(param);
705
+ value = key;
706
+ } else {
707
+ key = window.decode(param.substr(0, index));
708
+ value = window.decode(param.substr(index + 1));
709
+ }
710
+ this.query[key] = value;
711
+ }
712
+ }
713
+ }
714
+ } else {
715
+ this.pathname = url;
716
+ }
717
+ };
718
+ this.set = function (key, value) {
719
+ this.query[key] = value;
720
+ };
721
+ this.get = function (key) {
722
+ return this.query[key];
723
+ };
724
+ this.del = function (key) {
725
+ delete this.query[key];
726
+ };
727
+ this.has = function (key) {
728
+ return this.query[key] != null;
729
+ };
730
+ this.toStr = function () {
731
+ var items = ['?'];
732
+ for (var key in this.query) {
733
+ items.push(encodeURIComponent(key));
734
+ items.push('=');
735
+ items.push(encodeURIComponent(this.query[key]));
736
+ items.push('&');
737
+ }
738
+ if (items.length === 1) {
739
+ return '';
740
+ }
741
+ items.splice(items.length - 1, 1);
742
+ return items.join('');
743
+ };
744
+ this.init();
745
+ }
746
+ String.prototype['equalsIgnoreCase'] = function (str) {
747
+ // eslint-disable-line
748
+ if (str == null) {
749
+ return false;
750
+ }
751
+ return this.toLowerCase() === str.toLowerCase();
752
+ };
753
+ function _appendUrl(restUrl, params) {
754
+ if (!params) {
755
+ return restUrl;
756
+ }
757
+ var queryStr = [];
758
+ var queryUrl = new QueryString(restUrl);
759
+ for (var attr in params) {
760
+ if (queryUrl.get(attr)) {
761
+ continue;
762
+ }
763
+ queryStr.push("".concat(attr, "=").concat(params[attr]));
764
+ }
765
+ if (!queryStr.length) {
766
+ return restUrl;
767
+ }
768
+ var queryString = queryStr.join('&');
769
+ return restUrl.indexOf('?') >= 0 ? "".concat(restUrl, "&").concat(queryString) : "".concat(restUrl, "?").concat(queryString);
770
+ }
771
+
772
+ var _excluded = ["onBeforeRequest", "_onAfterRequest"],
773
+ _excluded2 = ["_onBeforeRequest", "onAfterRequest"];
774
+ function _getUrl(_url, params) {
775
+ var url = _url;
776
+ return url;
777
+ }
778
+ function getAllResponseHeaders(payload) {
779
+ var xhr = payload.xhr;
780
+ var headerString = xhr.getAllResponseHeaders();
781
+ var headers = {};
782
+ headerString.split('\r\n').map(function (header) {
783
+ var _header$split = header.split(': '),
784
+ _header$split2 = _slicedToArray(_header$split, 2),
785
+ key = _header$split2[0],
786
+ value = _header$split2[1];
787
+ headers[key] = value;
788
+ });
789
+ return headers;
790
+ }
791
+ var AjaxRequestManager = {
792
+ _xhrs: [],
793
+ _jsonps: {
794
+ index: 0
795
+ },
796
+ // eslint-disable-next-line object-shorthand
797
+ doRequest: function doRequest(_options) {
798
+ var _ref = _options || {},
799
+ onBeforeRequest = _ref.onBeforeRequest;
800
+ _ref._onAfterRequest;
801
+ var options = _objectWithoutProperties(_ref, _excluded);
802
+ var method = options.method || 'GET';
803
+ var url = _getUrl(options.url);
804
+ var headers;
805
+ try {
806
+ if (options !== null && options !== void 0 && options.requestHeaders) {
807
+ headers = options.requestHeaders;
808
+ options.requestHeaders = undefined;
809
+ delete options.requestHeaders;
810
+ }
811
+ } catch (e) {
812
+ console.log('[ajax]: [doRequest]: options["requestHeaders"] ERR : ', e);
813
+ }
814
+ try {
815
+ if (options.params && options.params.requestHeaders) {
816
+ headers = options.params.requestHeaders;
817
+ options.params.requestHeaders = undefined;
818
+ delete options.params.requestHeaders;
819
+ }
820
+ } catch (e) {
821
+ console.log('[ajax]: [doRequest]: options.params["requestHeaders"] ERR : ', e);
822
+ }
823
+ var queryJson = null;
824
+ if (method.equalsIgnoreCase('get') || method.equalsIgnoreCase('delete')) {
825
+ url = _appendUrl(url, options.params);
826
+ } else if (method.equalsIgnoreCase('post') || method.equalsIgnoreCase('put')) {
827
+ queryJson = JSON.stringify(options.params);
828
+ }
829
+ if (options.jsonp) {
830
+ return this.getJsonp(url, options.callback);
831
+ }
832
+ var xhr = this.getXMLHttpRequest();
833
+ if (!xhr) {
834
+ return;
835
+ }
836
+ xhr.open(method, url, options.async !== false);
837
+ // cb.rest.handlePendingRequestsState({ type: 'add', options }) // 处理请求是否完成状态管理
838
+ if (options.timeout) {
839
+ xhr.timeout = options.timeout;
840
+ xhr.setRequestHeader('timeout', options.timeout);
841
+ xhr.ontimeout = function () {
842
+ AjaxRequestManager.onerror(this, options, 'timeout');
843
+ };
844
+ }
845
+ if (options.contentType) {
846
+ // 支持x-www-form-urlencode的方式
847
+ xhr.setRequestHeader('Content-Type', options.contentType);
848
+ if (options.contentType.indexOf('x-www-form-urlencoded') >= 0) {
849
+ var _URLSearchParams;
850
+ queryJson = (_URLSearchParams = new URLSearchParams(options.params)) === null || _URLSearchParams === void 0 ? void 0 : _URLSearchParams.toString();
851
+ }
852
+ } else if (options.dateType) {
853
+ // 因上传文件参数为file格式,不需要JSON.stringify转化(转化后为空对象),也不需要设置请求头
854
+ queryJson = options.params;
855
+ } else {
856
+ xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
857
+ }
858
+ if (options.domainKey) {
859
+ xhr.setRequestHeader('Domain-Key', options.domainKey);
860
+ }
861
+ try {
862
+ if (headers && Object.prototype.toString.call(headers) === '[object Object]') {
863
+ for (var key in headers) {
864
+ xhr.setRequestHeader(key, headers[key]);
865
+ }
866
+ }
867
+ } catch (e) {
868
+ console.log('[ajax]: [doRequest]: options.params["requestHeaders"] ERR : ', e);
869
+ }
870
+ // eslint-disable-next-line no-prototype-builtins
871
+ xhr.withCredentials = options !== null && options !== void 0 && options.hasOwnProperty('withCredentials') ? options.withCredentials : true;
872
+ try {
873
+ xhr.send(queryJson);
874
+ } catch (e) {
875
+ // 增加断网情况下的容错处理,返回固定error和请求相关信息
876
+ return {
877
+ error: 'NetWorkError',
878
+ options: options
879
+ };
880
+ }
881
+ if (options.async === false) {
882
+ onBeforeRequest === null || onBeforeRequest === void 0 || onBeforeRequest(options);
883
+ return this.onreadystatechange(xhr, options);
884
+ // eslint-disable-next-line no-else-return
885
+ } else {
886
+ xhr.onreadystatechange = function () {
887
+ AjaxRequestManager.onreadystatechange(this, options);
888
+ };
889
+ }
890
+ onBeforeRequest === null || onBeforeRequest === void 0 || onBeforeRequest(options);
891
+ },
892
+ // eslint-disable-next-line object-shorthand
893
+ beforeReadystatechange: function beforeReadystatechange(xhr, options, callback) {
894
+ callback === null || callback === void 0 || callback();
895
+ },
896
+ // eslint-disable-next-line object-shorthand
897
+ onreadystatechange: function onreadystatechange(xhr, _options) {
898
+ var _ref2 = _options || {};
899
+ _ref2._onBeforeRequest;
900
+ var onAfterRequest = _ref2.onAfterRequest,
901
+ options = _objectWithoutProperties(_ref2, _excluded2);
902
+ if (xhr.readyState !== 4) {
903
+ return;
904
+ }
905
+ onAfterRequest === null || onAfterRequest === void 0 || onAfterRequest();
906
+ if (xhr.status === 200) {
907
+ // 兼容返回的数据不是json结构的错误处理
908
+ var ajaxResult;
909
+ try {
910
+ // 处理二进制文件返回值(暂时处理一种,后续需要其他类型再加)
911
+ if (options.responseType === 'blob') {
912
+ var headers = getAllResponseHeaders({
913
+ xhr: xhr
914
+ });
915
+ ajaxResult = {
916
+ code: xhr.status,
917
+ data: {
918
+ data: xhr.response,
919
+ headers: headers
920
+ }
921
+ };
922
+ } else {
923
+ ajaxResult = JSON.parse(xhr.responseText);
924
+ }
925
+ } catch (_unused) {
926
+ AjaxRequestManager.onerror(xhr, options, xhr.responseText);
927
+ }
928
+ if (options.async === false) {
929
+ xhr.isBusy = false;
930
+ if (options.precallback) {
931
+ options.precallback(ajaxResult);
932
+ }
933
+ // AjaxRequestManager.pushError(options, ajaxResult?.code, ajaxResult?.message, true)
934
+ return AjaxRequestManager.processAjaxResult(ajaxResult, false, null, null, options, xhr);
935
+ }
936
+ // AjaxRequestManager.pushError(options, ajaxResult?.code, ajaxResult?.message, true)
937
+ AjaxRequestManager.processAjaxResult(ajaxResult, options.async, options.callback, options.context, options, xhr);
938
+ if (options.precallback) {
939
+ options.precallback(ajaxResult);
940
+ }
941
+ } else if (xhr.status === 0) {
942
+ AjaxRequestManager.onerror(xhr, options, '网络连接已断开,请检查设备网络状态后重试');
943
+ } else if (xhr.status === 502 || xhr.status === 504) {
944
+ AjaxRequestManager.onerror(xhr, options, '服务出错了,请稍后再试');
945
+ } else if (xhr.status === 401) {
946
+ AjaxRequestManager.onerror(xhr, options, '登录信息失效,请重新登录或联系技术人员');
947
+ } else {
948
+ var messageObj = {};
949
+ try {
950
+ var message = JSON.parse(xhr.responseText);
951
+ messageObj = message;
952
+ } catch (_unused2) {
953
+ messageObj = {
954
+ code: xhr.status,
955
+ message: xhr.responseText
956
+ };
957
+ }
958
+ // AjaxRequestManager.pushError(options, messageObj.code, messageObj.message)
959
+ return AjaxRequestManager.onerror(xhr, options, messageObj);
960
+ }
961
+ xhr.isBusy = false;
962
+ },
963
+ // eslint-disable-next-line object-shorthand
964
+ onerror: function onerror(xhr, options, message) {
965
+ var errorType = 'Error.E01000';
966
+ var errorMessage = "[ajax]: [onerror]: \u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF \n [\u72B6\u6001\u7801]: ".concat(xhr.status, " \n [\u9519\u8BEF\u4FE1\u606F]: ").concat((_typeof(message) === 'object' ? JSON.stringify(message) : message) || '空', " \n [\u8BF7\u6C42\u5730\u5740]: ").concat(options.url, " \n [\u6D4F\u89C8\u5668Token]: ").concat(document.cookie);
967
+ console.log(errorType, errorMessage);
968
+ var ajaxResult = _typeof(message) === 'object' ? message : {
969
+ code: 500,
970
+ message: message
971
+ };
972
+ if (options.precallback) {
973
+ options.precallback(ajaxResult);
974
+ }
975
+ },
976
+ // eslint-disable-next-line object-shorthand
977
+ getXMLHttpRequest: function getXMLHttpRequest() {
978
+ return this.createXMLHttpRequest();
979
+ },
980
+ // eslint-disable-next-line object-shorthand
981
+ createXMLHttpRequest: function createXMLHttpRequest() {
982
+ var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : null;
983
+ return xhr;
984
+ },
985
+ // eslint-disable-next-line object-shorthand
986
+ getJsonp: function getJsonp(_url, callback) {
987
+ var url = _url;
988
+ // eslint-disable-next-line prefer-template
989
+ var responseCallback = 'callback' + this._jsonps.index++;
990
+ var scriptDom = document.createElement('script');
991
+ this._jsonps[responseCallback] = function (data) {
992
+ try {
993
+ callback(data);
994
+ } finally {
995
+ document.body.removeChild(scriptDom);
996
+ }
997
+ };
998
+ // eslint-disable-next-line prefer-template
999
+ url += url.indexOf('?') === -1 ? '?' : '&callback=cb.rest.AjaxRequestManager._jsonps.' + responseCallback;
1000
+ scriptDom.src = url;
1001
+ document.body.appendChild(scriptDom);
1002
+ },
1003
+ // eslint-disable-next-line object-shorthand
1004
+ processAjaxResult: function processAjaxResult(ajaxResult, async, callback, context, options, xhr) {
1005
+ if (!ajaxResult) {
1006
+ return;
1007
+ }
1008
+ if (!ajaxResult.code) {
1009
+ if (async === false) {
1010
+ return ajaxResult;
1011
+ }
1012
+ if (callback) {
1013
+ callback.call(context, null, ajaxResult);
1014
+ }
1015
+ return;
1016
+ }
1017
+ // eslint-disable-next-line eqeqeq
1018
+ if (ajaxResult.code == 200) {
1019
+ if (async === false) {
1020
+ return {
1021
+ result: ajaxResult.data
1022
+ };
1023
+ }
1024
+ if (callback) {
1025
+ callback.call(context, null, ajaxResult.data, ajaxResult.message, ajaxResult.errorDetail, ajaxResult.code, ajaxResult.displayCode && ajaxResult);
1026
+ }
1027
+ } else {
1028
+ if (async === false) {
1029
+ return {
1030
+ error: ajaxResult
1031
+ };
1032
+ }
1033
+ if (callback) {
1034
+ callback.call(context, ajaxResult);
1035
+ }
1036
+ }
1037
+ }
1038
+ };
1039
+ function ajax(url, options) {
1040
+ options.url = url;
1041
+ // if (cb.rest.ajaxPreprocess && cb.rest.ajaxPreprocess(options) === false) return
1042
+ return AjaxRequestManager.doRequest(options);
1043
+ }
1044
+
1045
+ function DynamicProxy(config, query) {
1046
+ if (this.init) {
1047
+ this.init(config);
1048
+ }
1049
+ this.queryParams = query;
1050
+ }
1051
+ DynamicProxy.create = function (config, query) {
1052
+ return new DynamicProxy(config, query);
1053
+ };
1054
+ DynamicProxy.prototype.init = function (config) {
1055
+ if (!config) {
1056
+ return;
1057
+ }
1058
+ this.config = config;
1059
+ for (var attr in this.config) {
1060
+ // eslint-disable-next-line wrap-iife
1061
+ this[attr] = function (attr) {
1062
+ return function (data, callback, context) {
1063
+ return this.Do(attr, data, callback, null, context);
1064
+ };
1065
+ }(attr);
1066
+ // eslint-disable-next-line wrap-iife
1067
+ this["".concat(attr, "Sync")] = function (attr) {
1068
+ return function (data) {
1069
+ return this.Do(attr, data, null, false);
1070
+ };
1071
+ }(attr);
1072
+ }
1073
+ };
1074
+ DynamicProxy.prototype.Do = function (op, data, callback, async, context) {
1075
+ var _config$options, _config$options2, _this$queryParams;
1076
+ if (!this.config || !this.config[op] || !this.config[op].url) {
1077
+ return;
1078
+ }
1079
+ var config = this.config[op];
1080
+ var url = config.url;
1081
+ if (!this.queryParams) {
1082
+ this.queryParams = {};
1083
+ }
1084
+ if ((_config$options = config.options) !== null && _config$options !== void 0 && _config$options.proxyServiceCode) {
1085
+ this.queryParams.serviceCode = config.options.proxyServiceCode;
1086
+ }
1087
+ if ((_config$options2 = config.options) !== null && _config$options2 !== void 0 && _config$options2.billnum) {
1088
+ this.queryParams.billnum = config.options.billnum;
1089
+ }
1090
+ if ((_this$queryParams = this.queryParams) !== null && _this$queryParams !== void 0 && _this$queryParams.serviceCode) {
1091
+ url = _appendUrl(url, this.queryParams);
1092
+ }
1093
+ var restUrl = url;
1094
+ var options = Object.assign({}, config.options);
1095
+ options.method = config.method || 'GET';
1096
+ if (typeof data === 'function') {
1097
+ options.callback = data;
1098
+ options.context = context || options.context || this;
1099
+ } else {
1100
+ options.params = data;
1101
+ }
1102
+ if (callback) {
1103
+ options.callback = callback;
1104
+ options.context = context || options.context || this;
1105
+ }
1106
+ if (async === false) {
1107
+ options.async = false;
1108
+ }
1109
+ return this.ajax(restUrl, options);
1110
+ };
1111
+ DynamicProxy.prototype.ajax = function (url, options) {
1112
+ // if (!cb.events?.execute('beforeProxyRequest', { url, options })) {return}
1113
+ return ajax(url, options);
1114
+ };
1115
+
1116
+ var BaseModel = /*#__PURE__*/function () {
1117
+ function BaseModel(args) {
1118
+ _classCallCheck(this, BaseModel);
1119
+ this._init(args);
1120
+ }
1121
+
1122
+ /* 数据容器 */
1123
+ return _createClass(BaseModel, [{
1124
+ key: "_init",
1125
+ value: function _init(args) {
1126
+ this._data = {};
1127
+ var propertyNames = [];
1128
+ if (args) {
1129
+ for (var propertyName in args) {
1130
+ propertyNames.push(propertyName);
1131
+ }
1132
+ }
1133
+ Object.assign(this._data, {
1134
+ components: [],
1135
+ propertyNames: propertyNames
1136
+ }, args);
1137
+ this._data.cache = new CacheUtil();
1138
+ this._data.events = new EventUtil();
1139
+ }
1140
+ }, {
1141
+ key: "_del_data",
1142
+ value: function _del_data(key) {
1143
+ if (!key) {
1144
+ return;
1145
+ }
1146
+ delete this._data[key];
1147
+ }
1148
+ }, {
1149
+ key: "_cls_data",
1150
+ value: function _cls_data() {
1151
+ this._data.cache.clear();
1152
+ this._data.events.clear();
1153
+ this._data = {
1154
+ components: [],
1155
+ propertyNames: [],
1156
+ cache: new CacheUtil(),
1157
+ events: new EventUtil()
1158
+ };
1159
+ }
1160
+ }, {
1161
+ key: "_set_data",
1162
+ value: function _set_data(name, val, update) {
1163
+ if (!name) {
1164
+ return;
1165
+ }
1166
+ if (update) {
1167
+ var propertyNames = this._data.propertyNames || [];
1168
+ if (propertyNames.indexOf(name) < 0) {
1169
+ propertyNames.push(name);
1170
+ }
1171
+ }
1172
+ this._data[name] = val;
1173
+ }
1174
+ }, {
1175
+ key: "_get_data",
1176
+ value: function _get_data(name) {
1177
+ if (!name) {
1178
+ return;
1179
+ }
1180
+ return this._data[name];
1181
+ }
1182
+ }, {
1183
+ key: "getData",
1184
+ value: function getData() {
1185
+ return this._get_data('value');
1186
+ }
1187
+
1188
+ /* 组件联动 */
1189
+ }, {
1190
+ key: "getState",
1191
+ value: function getState(name, ctrlName) {
1192
+ var _component$getState;
1193
+ if (!ctrlName) {
1194
+ return this._get_data(name);
1195
+ }
1196
+ var components = this._get_data('components') || [];
1197
+ var component = components.find(function (item) {
1198
+ return item.ctrlName === ctrlName;
1199
+ });
1200
+ if (!component) {
1201
+ return this._get_data(name);
1202
+ }
1203
+ return (_component$getState = component.getState) === null || _component$getState === void 0 ? void 0 : _component$getState.call(component, name);
1204
+ }
1205
+ }, {
1206
+ key: "setState",
1207
+ value: function setState(name, value, ctrlName) {
1208
+ if (!ctrlName) {
1209
+ this._set_data(name, value, true);
1210
+ }
1211
+ var state = {};
1212
+ state[name] = value;
1213
+ this.doPropertyChange('setState', state, ctrlName);
1214
+ }
1215
+ }, {
1216
+ key: "doPropertyChange",
1217
+ value: function doPropertyChange(name, value, ctrlName) {
1218
+ var _this = this;
1219
+ var components = this._get_data('components') || [];
1220
+ if (!components.length) {
1221
+ return components;
1222
+ }
1223
+ var notNotifiedComponents = [];
1224
+ if (!ctrlName) {
1225
+ components.forEach(function (item) {
1226
+ if (!_this.notifyComponent(item, name, value)) {
1227
+ notNotifiedComponents.push(item);
1228
+ }
1229
+ });
1230
+ } else {
1231
+ var component = components.find(function (item) {
1232
+ return item.ctrlName === ctrlName;
1233
+ });
1234
+ if (component && !this.notifyComponent(component, name, value)) {
1235
+ notNotifiedComponents.push(component);
1236
+ }
1237
+ }
1238
+ if (notNotifiedComponents.length) {
1239
+ return notNotifiedComponents;
1240
+ }
1241
+ }
1242
+ }, {
1243
+ key: "notifyComponent",
1244
+ value: function notifyComponent(component, name, value) {
1245
+ if (typeof component[name] !== 'function') {
1246
+ return false;
1247
+ }
1248
+ this.viewUpdater(component, name, value);
1249
+ return true;
1250
+ }
1251
+ }, {
1252
+ key: "viewUpdater",
1253
+ value: function viewUpdater(component, name, value) {
1254
+ if (name === 'setState') {
1255
+ component[name](value);
1256
+ } else {
1257
+ var propertyName = this.getCache('name');
1258
+ component[name](value, propertyName);
1259
+ }
1260
+ }
1261
+ }, {
1262
+ key: "get",
1263
+ value: function get(name) {
1264
+ return this._get_data(name);
1265
+ }
1266
+ }, {
1267
+ key: "addComponent",
1268
+ value: function addComponent(component, ctrlName) {
1269
+ if (!component) {
1270
+ return;
1271
+ }
1272
+ if (ctrlName && !component.ctrlName) {
1273
+ component.ctrlName = ctrlName;
1274
+ }
1275
+ var components = this._get_data('components') || [];
1276
+ if (components.indexOf(component) >= 0) {
1277
+ return;
1278
+ }
1279
+ components.push(component);
1280
+ }
1281
+ }, {
1282
+ key: "removeComponent",
1283
+ value: function removeComponent(component) {
1284
+ var components = this._get_data('components') || [];
1285
+ var index = components.indexOf(component);
1286
+ if (index < 0) {
1287
+ return;
1288
+ }
1289
+ components.splice(index, 1);
1290
+ }
1291
+
1292
+ /**
1293
+ * 统一的「写属性 + 通知组件」逻辑。
1294
+ * 组件实现了 setXxx(如 setValue)就直接调;没实现则退回 setState({ [name]: value })。
1295
+ * 原实现里只有 setVisible / setDisabled 有这层兜底,setValue 漏了,
1296
+ * 导致模型改值永远传不到受控组件上。
1297
+ */
1298
+ }, {
1299
+ key: "_applyState",
1300
+ value: function _applyState(name, value, ctrlName) {
1301
+ var _this2 = this;
1302
+ if (!ctrlName) {
1303
+ this._set_data(name, value, true);
1304
+ }
1305
+ var setterName = "set".concat(name.charAt(0).toUpperCase()).concat(name.slice(1));
1306
+ var notNotifiedComponents = this.doPropertyChange(setterName, value, ctrlName);
1307
+ if (!notNotifiedComponents) {
1308
+ return;
1309
+ }
1310
+ var state = {};
1311
+ state[name] = value;
1312
+ notNotifiedComponents.forEach(function (component) {
1313
+ _this2.notifyComponent(component, 'setState', state);
1314
+ });
1315
+ }
1316
+ }, {
1317
+ key: "getVisible",
1318
+ value: function getVisible(ctrlName) {
1319
+ return this.getState('visible', ctrlName);
1320
+ }
1321
+ }, {
1322
+ key: "setVisible",
1323
+ value: function setVisible(value, ctrlName) {
1324
+ this._applyState('visible', value, ctrlName);
1325
+ }
1326
+ }, {
1327
+ key: "getValue",
1328
+ value: function getValue() {
1329
+ return this.getData();
1330
+ }
1331
+ }, {
1332
+ key: "setValue",
1333
+ value: function setValue(value, fireEvent, ctrlName) {
1334
+ var self = this;
1335
+ var oldValue = this.getValue();
1336
+ if (value === oldValue) {
1337
+ return;
1338
+ }
1339
+ var data = {
1340
+ value: value,
1341
+ oldValue: oldValue
1342
+ };
1343
+ var forceFireEvent = this._get_data('forceFireEvent');
1344
+ if (fireEvent || forceFireEvent) {
1345
+ this.promiseExecute('beforeValueChange', data, [function () {
1346
+ self._set_data('value', value, true);
1347
+ self._applyState('value', value, ctrlName);
1348
+ self.execute('afterValueChange', data);
1349
+ }, function () {
1350
+ self._set_data('value', oldValue, true);
1351
+ self._applyState('value', oldValue, ctrlName);
1352
+ }]);
1353
+ return;
1354
+ }
1355
+ this._set_data('value', value, true);
1356
+ this._applyState('value', value, ctrlName);
1357
+ }
1358
+ }, {
1359
+ key: "getDisabled",
1360
+ value: function getDisabled(ctrlName) {
1361
+ return this.getState('disabled', ctrlName);
1362
+ }
1363
+ }, {
1364
+ key: "setDisabled",
1365
+ value: function setDisabled(value, ctrlName) {
1366
+ this._applyState('disabled', value, ctrlName);
1367
+ }
1368
+
1369
+ /* 父子关系 */
1370
+ }, {
1371
+ key: "setParent",
1372
+ value: function setParent(parent) {
1373
+ this.setCache('parent', parent);
1374
+ }
1375
+ }, {
1376
+ key: "getParent",
1377
+ value: function getParent() {
1378
+ return this.getCache('parent');
1379
+ }
1380
+ }, {
1381
+ key: "getRootParent",
1382
+ value: function getRootParent() {
1383
+ var viewModel = this.getParent();
1384
+ while ((_viewModel = viewModel) !== null && _viewModel !== void 0 && _viewModel.getParent()) {
1385
+ var _viewModel;
1386
+ viewModel = viewModel.getParent();
1387
+ }
1388
+ return viewModel;
1389
+ }
1390
+ }, {
1391
+ key: "setName",
1392
+ value: function setName(name) {
1393
+ this.setCache('name', name);
1394
+ }
1395
+ }, {
1396
+ key: "getName",
1397
+ value: function getName() {
1398
+ return this.getCache('name');
1399
+ }
1400
+
1401
+ /* 脏检查与清空 */
1402
+ }, {
1403
+ key: "setDirty",
1404
+ value: function setDirty(dirty) {
1405
+ if (dirty) {
1406
+ this._set_data('isDirty', true);
1407
+ return;
1408
+ }
1409
+ this._del_data('isDirty');
1410
+ this._set_data('originalData', this.getData());
1411
+ }
1412
+ }, {
1413
+ key: "getDirtyData",
1414
+ value: function getDirtyData(necessary) {
1415
+ var value = this.getData();
1416
+ if (necessary !== false && this._get_data('isDirty')) {
1417
+ return value;
1418
+ }
1419
+ if (value === this._get_data('originalData')) {
1420
+ return;
1421
+ }
1422
+ return value;
1423
+ }
1424
+ }, {
1425
+ key: "clear",
1426
+ value: function clear(useDefault) {
1427
+ if (useDefault === undefined) {
1428
+ this._set_data('value', this._get_data('cDefaultValue'));
1429
+ } else if (!useDefault) {
1430
+ this._set_data('value', undefined);
1431
+ }
1432
+ this._del_data('isDirty');
1433
+ this._del_data('checking');
1434
+ this._del_data('checkMsg');
1435
+ }
1436
+
1437
+ /* 事件门面 */
1438
+ }, {
1439
+ key: "on",
1440
+ value: function on(name, callback, context) {
1441
+ this._get_data('events').on(name, callback, context);
1442
+ }
1443
+ }, {
1444
+ key: "onFirst",
1445
+ value: function onFirst(name, callback, context) {
1446
+ this._get_data('events').onFirst(name, callback, context);
1447
+ }
1448
+ }, {
1449
+ key: "execute",
1450
+ value: function execute(name) {
1451
+ var _this$_get_data;
1452
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1453
+ args[_key - 1] = arguments[_key];
1454
+ }
1455
+ return (_this$_get_data = this._get_data('events')).execute.apply(_this$_get_data, [name].concat(args));
1456
+ }
1457
+ }, {
1458
+ key: "un",
1459
+ value: function un(name, callback) {
1460
+ this._get_data('events').un(name, callback);
1461
+ }
1462
+ }, {
1463
+ key: "hasEvent",
1464
+ value: function hasEvent(name) {
1465
+ return this._get_data('events').hasEvent(name);
1466
+ }
1467
+ }, {
1468
+ key: "fireEvent",
1469
+ value: function fireEvent(eventName, args) {
1470
+ this._get_data('events').fireEvent(eventName, args);
1471
+ }
1472
+ }, {
1473
+ key: "promiseExecute",
1474
+ value: function promiseExecute(check, eventName) {
1475
+ var _this$_get_data2;
1476
+ for (var _len2 = arguments.length, restArgs = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
1477
+ restArgs[_key2 - 2] = arguments[_key2];
1478
+ }
1479
+ (_this$_get_data2 = this._get_data('events')).promiseExecute.apply(_this$_get_data2, [check, eventName].concat(restArgs));
1480
+ }
1481
+
1482
+ /* 缓存门面 */
1483
+ }, {
1484
+ key: "setCache",
1485
+ value: function setCache(key, value) {
1486
+ this._get_data('cache').set(key, value);
1487
+ }
1488
+ }, {
1489
+ key: "getCache",
1490
+ value: function getCache(key) {
1491
+ return this._get_data('cache').get(key);
1492
+ }
1493
+ }, {
1494
+ key: "clearCache",
1495
+ value: function clearCache(key) {
1496
+ this._get_data('cache').clear(key);
1497
+ }
1498
+
1499
+ /* 请求 */
1500
+ }, {
1501
+ key: "setProxy",
1502
+ value: function setProxy(config) {
1503
+ if (config instanceof DynamicProxy) {
1504
+ this._set_data('proxy', config);
1505
+ } else {
1506
+ var _this$getProxy2;
1507
+ var requestHeaders = this._get_data('__requestHeaders__');
1508
+ for (var attr in config) {
1509
+ var _config$attr, _this$getProxy;
1510
+ if (requestHeaders && !((_config$attr = config[attr]) !== null && _config$attr !== void 0 && (_config$attr = _config$attr.options) !== null && _config$attr !== void 0 && _config$attr.requestHeaders)) {
1511
+ var _config$attr2;
1512
+ if (!((_config$attr2 = config[attr]) !== null && _config$attr2 !== void 0 && _config$attr2.options)) {
1513
+ config[attr].options = {};
1514
+ }
1515
+ config[attr].options.requestHeaders = requestHeaders;
1516
+ }
1517
+ // this.rebuildProxyConfig(config[attr]) // 处理参数
1518
+ if ((_this$getProxy = this.getProxy()) !== null && _this$getProxy !== void 0 && _this$getProxy[attr]) {
1519
+ console.warn("[baseModel.prototype.setProxy]: Proxy ".concat(attr, " already exists on the model. Please change the name of ").concat(attr, " and try again"));
1520
+ }
1521
+ }
1522
+ this._set_data('proxy', DynamicProxy.create(_objectSpread2(_objectSpread2({}, ((_this$getProxy2 = this.getProxy()) === null || _this$getProxy2 === void 0 ? void 0 : _this$getProxy2.config) || {}), config)));
1523
+ var proxyAll = this.getProxy();
1524
+ return proxyAll;
1525
+ }
1526
+ }
1527
+ }, {
1528
+ key: "getProxy",
1529
+ value: function getProxy() {
1530
+ return this._get_data('proxy');
1531
+ }
1532
+ }]);
1533
+ }();
1534
+
1535
+ var FilterModel = /*#__PURE__*/function (_BaseModel) {
1536
+ function FilterModel() {
1537
+ _classCallCheck(this, FilterModel);
1538
+ return _callSuper(this, FilterModel, arguments);
1539
+ }
1540
+ _inherits(FilterModel, _BaseModel);
1541
+ return _createClass(FilterModel, [{
1542
+ key: "mounted",
1543
+ value: function mounted() {
1544
+ var _this = this;
1545
+ var _conditions = this.get('conditions');
1546
+ var params = {};
1547
+ _conditions.forEach(function (r) {
1548
+ _this.get(r.name);
1549
+ params[r.name] = r.defaultValue;
1550
+ });
1551
+ this._set_data('params', params);
1552
+ }
1553
+ }, {
1554
+ key: "unmounted",
1555
+ value: function unmounted() {
1556
+ this._set_data('params', {});
1557
+ this._set_data('conditions', []);
1558
+ }
1559
+ }, {
1560
+ key: "getParams",
1561
+ value: function getParams() {
1562
+ var _this2 = this;
1563
+ var params = {};
1564
+ var conditions = this.get('conditions');
1565
+ conditions.forEach(function (r) {
1566
+ var model = _this2.get(r.name);
1567
+ params[r.name] = model === null || model === void 0 ? void 0 : model.getValue();
1568
+ });
1569
+ this._set_data('params', params);
1570
+ return params;
1571
+ }
1572
+ }, {
1573
+ key: "search",
1574
+ value: function search() {
1575
+ var params = this.getParams();
1576
+ this.execute('search', params);
1577
+ }
1578
+ }]);
1579
+ }(BaseModel);
1580
+
1581
+ var SimpleModel = /*#__PURE__*/function (_BaseModel) {
1582
+ function SimpleModel(args) {
1583
+ _classCallCheck(this, SimpleModel);
1584
+ return _callSuper(this, SimpleModel, [args]);
1585
+ }
1586
+ _inherits(SimpleModel, _BaseModel);
1587
+ return _createClass(SimpleModel, [{
1588
+ key: "getDisabled",
1589
+ value: function getDisabled() {
1590
+ return this.getState('disabled');
1591
+ }
1592
+ }, {
1593
+ key: "setDisabled",
1594
+ value: function setDisabled(v) {
1595
+ return this.setState('disabled', !!v);
1596
+ }
1597
+ }, {
1598
+ key: "getReadonly",
1599
+ value: function getReadonly() {
1600
+ return this.getState('readonly');
1601
+ }
1602
+ }, {
1603
+ key: "setReadonly",
1604
+ value: function setReadonly(v) {
1605
+ this.setState('readonly', !!v);
1606
+ }
1607
+ }]);
1608
+ }(BaseModel);
1609
+
1610
+ /**
1611
+ * models - GridModel
1612
+ *
1613
+ * 参照中台 `mdf-cube/src/models/GridModel.js`(`cb.models.register('GridModel')`)重写,
1614
+ * 把它的约定搬进我们这套 devfab 的 ui-model 体系:
1615
+ *
1616
+ * 1. 两层数据:`dataSource`(全量原始数据)+ `rows`(当前展示行,本地模式下是 dataSource 的分页切片);
1617
+ * 2. 行状态与数据同序:`rowsDataState[i]` 对应 `dataSource[i]`,取值见 DataStates;
1618
+ * 3. 内部字段由 `innerUsedAttrs` 统一定义:`_id` / `_selected` / `_status`;
1619
+ * 4. 列是 **object map**(key = field),不是数组 —— 给 vxe-grid 渲染时用 `getColumnList()` 转数组;
1620
+ * 5. 分页状态叫 `pageInfo`(pageIndex/pageSize/pageCount/recordCount),不叫 pager;
1621
+ * 6. 行、单元格、列都可以挂状态:`rowState` / `cellState`;
1622
+ * 7. 选中分「当前页 `_selected` 标记」与「跨页选中缓存(selectedKeysSet + selectedRowsMap)」两层。
1623
+ *
1624
+ * 与中台实现不同的地方(有意为之,都有注释说明):
1625
+ * - 中台的取数配置走 `proxyConfig` + `setProxy`,我们直接保留 `proxyConfig.load`(函数或 url),
1626
+ * 并兼容旧的 `dataSource: fn` / `cUrl` 写法;
1627
+ * - 中台的 `setRows` 会把 `getShowRows()`(展示文案副本)推给组件,我们推**原始行对象**,
1628
+ * 否则选中回灌、单元格编辑会落到副本上;
1629
+ * - 中台的行模型(editRowModel / ReferModel / 特征 / 孙表)没有移植,这里只做行级与单元格级能力。
1630
+ */
1631
+ var DataStates = {
1632
+ Unchanged: '',
1633
+ Insert: 'Insert',
1634
+ Update: 'Update',
1635
+ Delete: 'Delete'
1636
+ };
1637
+ var DEFAULT_PAGE_SIZE = 20;
1638
+ var isArray = Array.isArray;
1639
+ var isEmpty = function isEmpty(value) {
1640
+ return value === undefined || value === null || value === '';
1641
+ };
1642
+ var isEmptyObject = function isEmptyObject(value) {
1643
+ return !value || Object.keys(value).length === 0;
1644
+ };
1645
+ function cloneDeep(value) {
1646
+ if (isArray(value)) return value.map(cloneDeep);
1647
+ if (value instanceof Date) return new Date(value.getTime());
1648
+ if (value && _typeof(value) === 'object') {
1649
+ var result = {};
1650
+ for (var key in value) result[key] = cloneDeep(value[key]);
1651
+ return result;
1652
+ }
1653
+ return value;
1654
+ }
1655
+
1656
+ // ---------------- 列:数组 ↔ object map 归一 ----------------
1657
+
1658
+ /**
1659
+ * 列统一收敛成 object map(key = field),与中台一致。
1660
+ * 入参既接受数组(我们自己写 meta 的习惯),也接受后端下发的 map。
1661
+ */
1662
+ function normalizeColumns(columns) {
1663
+ var map = {};
1664
+ var list = isArray(columns) ? columns : Object.keys(columns || {}).map(function (key) {
1665
+ var _columns$key;
1666
+ return _objectSpread2(_objectSpread2({}, columns[key] || {}), {}, {
1667
+ field: ((_columns$key = columns[key]) === null || _columns$key === void 0 ? void 0 : _columns$key.field) || key
1668
+ });
1669
+ });
1670
+ list.forEach(function (column, index) {
1671
+ if (!column) return;
1672
+ var field = column.field || column.cCaption || column.cFieldName || "col_".concat(index);
1673
+ map[field] = _objectSpread2(_objectSpread2({}, column), {}, {
1674
+ field: field,
1675
+ // 中台里列有 fieldName / cCaption 两套命名,这里都兜住
1676
+ fieldName: column.fieldName || field,
1677
+ cCaption: column.cCaption || field,
1678
+ index: column.index === undefined ? index : column.index
1679
+ });
1680
+ });
1681
+ return map;
1682
+ }
1683
+
1684
+ /** 给行补内部 id(没有主键时用 rowId_ 前缀,与中台一致) */
1685
+ function setIds() {
1686
+ var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1687
+ var idFlag = this.getIdFlag();
1688
+ var keyField = this.getRowKeyField();
1689
+ var seq = this._get_data('rowIdSeq') || 0;
1690
+ rows.forEach(function (row) {
1691
+ if (!row || row[idFlag] !== undefined) return;
1692
+ var key = row[keyField];
1693
+ if (key !== undefined && key !== null && key !== '') {
1694
+ row[idFlag] = String(key);
1695
+ } else {
1696
+ seq += 1;
1697
+ row[idFlag] = "rowId_".concat(seq);
1698
+ }
1699
+ });
1700
+ this._set_data('rowIdSeq', seq);
1701
+ return rows;
1702
+ }
1703
+
1704
+ // ---------------- 初始状态 ----------------
1705
+
1706
+ function createDefaultProps() {
1707
+ return {
1708
+ columns: {},
1709
+ dataSource: [],
1710
+ rows: [],
1711
+ readOnly: true,
1712
+ dataSourceMode: 'local',
1713
+ columnMode: 'local',
1714
+ editMode: 'cell',
1715
+ cellState: {},
1716
+ rowState: {},
1717
+ showCheckBox: true,
1718
+ multiple: true,
1719
+ showRowNo: true,
1720
+ // 默认显示序号
1721
+ pagination: true,
1722
+ pageInfo: {
1723
+ pageIndex: 1,
1724
+ pageSize: DEFAULT_PAGE_SIZE,
1725
+ pageCount: 0
1726
+ },
1727
+ innerUsedAttrs: {
1728
+ id: '_id',
1729
+ selected: '_selected',
1730
+ status: '_status'
1731
+ },
1732
+ multiRowModel: false,
1733
+ // 表格多行模型
1734
+ editRowModels: {},
1735
+ // ---- 取数与加载态 ----
1736
+ loading: false,
1737
+ params: {},
1738
+ // ---- 脏数据 ----
1739
+ originalKeyMap: {},
1740
+ defaultRowDatas: new Map()
1741
+ };
1742
+ }
1743
+
1744
+ /**
1745
+ * 取数配置:中台叫 proxyConfig({ load: fn|url }),这里兼容三种写法
1746
+ * - `proxyConfig: { load }`
1747
+ * - `dataSource: fn`(旧写法)
1748
+ * - `cUrl: '/xxx'`
1749
+ */
1750
+ function resolveProxyConfig() {
1751
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1752
+ var proxy = _objectSpread2({}, props.proxyConfig || {});
1753
+ if (typeof props.dataSource === 'function') proxy.load = proxy.load || props.dataSource;
1754
+ if (typeof props.cUrl === 'string') proxy.load = proxy.load || props.cUrl;
1755
+ if (!proxy.load && typeof props.url === 'string') proxy.load = props.url;
1756
+ return proxy;
1757
+ }
1758
+
1759
+ /* code-link-enable */
1760
+ var showPageInner = function showPageInner(proxyConfig, queryParams, callback, refresh, needLoadPageination, backQueryPageCount, extraProps) {
1761
+ var _this = this;
1762
+ this.promiseExecute('beforeBatchModifyPull', function () {
1763
+ // this.rebuildProxyConfig(proxyConfig);
1764
+ var proxy = _this.setProxy({
1765
+ queryData: proxyConfig
1766
+ });
1767
+ var defaultParams = {
1768
+ page: {
1769
+ pageSize: _this.getPageSize(),
1770
+ pageIndex: _this.getPageIndex()
1771
+ }
1772
+ };
1773
+ if (!defaultParams.page.pageSize) {
1774
+ _this.setPageSize(10);
1775
+ defaultParams.page.pageSize = 10;
1776
+ }
1777
+ var bLoadPagination = _this._get_data('bLoadPagination');
1778
+ if (!bLoadPagination && !needLoadPageination) defaultParams.page.totalCount = 1;
1779
+ var delayLoadPageInfo = _this._get_data('delayLoadPageInfo');
1780
+ if (bLoadPagination && delayLoadPageInfo) {
1781
+ if (refresh) {
1782
+ _this.setState('showDelayPagination', true);
1783
+ }
1784
+ defaultParams.page.totalCount = 1;
1785
+ }
1786
+ var params = Object.assign(defaultParams, queryParams);
1787
+ _this.setCache('proxyCache', {
1788
+ proxyConfig: proxyConfig,
1789
+ params: params
1790
+ });
1791
+ var queryCount = 0;
1792
+ var responseData = {};
1793
+ var viewModel = _this.getRootParent();
1794
+ var self = _this;
1795
+
1796
+ // 增加queryId解决 报表临时表锁问题
1797
+ var queryId = new Date().valueOf();
1798
+ params.queryId = queryId;
1799
+ var queryDataCallback = function queryDataCallback(err, result, callBackMsg, errorDetail) {
1800
+ var _this$getParent, _this$getParent$getPa;
1801
+ setTimeout(function () {
1802
+ self.clearCache('isGridInLoading');
1803
+ }, 0);
1804
+ viewModel === null || viewModel === void 0 || viewModel.clearCache('lazySearch');
1805
+ if (err) {
1806
+ this.setState('showDelayPagination', false);
1807
+ this.clearCache('setPageIndexFromBack');
1808
+ return;
1809
+ }
1810
+ result = result || {}; // 容错处理null或者undefined情况
1811
+ this._set_data('dataSourceMode', 'remote'); // 处理请求过程中被修改
1812
+ if (refresh && bLoadPagination && delayLoadPageInfo) {
1813
+ queryCount++;
1814
+ result = Object.assign(responseData, result);
1815
+ }
1816
+ var data = Array.isArray(result.recordList) ? result.recordList : [];
1817
+ if ((!(bLoadPagination && delayLoadPageInfo) || queryCount === 2) && callback) {
1818
+ callback.call(this, result, callBackMsg, errorDetail);
1819
+ }
1820
+ this.getCache('setPageIndexFromBack'); // 是否是从卡片页返回的
1821
+ this.clearCache('setPageIndexFromBack');
1822
+ if (!this.execute('beforeSetDataSource', data)) return;
1823
+ var rowKeyField = this._get_data('rowKeyField');
1824
+ var keyMap = {};
1825
+ data.forEach(function (item) {
1826
+ keyMap[item[rowKeyField]] = item;
1827
+ });
1828
+ this._set_data('keyMap', keyMap);
1829
+ if (!refresh && this._get_data('override') === false) {
1830
+ this._set_data('dataSource', this._get_data('dataSource').concat(data), true);
1831
+ } else {
1832
+ this._set_data('dataSource', data, true);
1833
+ this.doPropertyChange('resetCellStatus');
1834
+ this._set_data('cellState', {}, true);
1835
+ this._set_data('rowState', {}, true);
1836
+ }
1837
+ // 存入当前model缓存便于client端搜索
1838
+ this.setCache('currentGridData', data);
1839
+ if (data.length) {
1840
+ setIds.call(this, data);
1841
+ }
1842
+ this.initRowState();
1843
+ // 修改缓存数据
1844
+ setCachePaginationRowData.call(this, data);
1845
+ this._get_data('sortParams');
1846
+ var colFilterParams = this._get_data('colFilterParams');
1847
+ this.showRows(null, !cb.utils.isEmptyObject(colFilterParams));
1848
+ var pageInfo = this._get_data('pageInfo');
1849
+ // bLoadPagination 优先级比 delayLoadPageInfo 高,bLoadPagination开启时值是false,所以第一项条件需要用 bLoadPagination = false 约束 delayLoadPageInfo = true 的情况
1850
+ if (bLoadPagination && !delayLoadPageInfo && (this._get_data('bLoadPagination') || needLoadPageination)) {
1851
+ pageInfo = {
1852
+ pageSize: result.pageSize,
1853
+ pageIndex: result.pageIndex,
1854
+ pageCount: result.pageCount,
1855
+ recordCount: result.recordCount
1856
+ };
1857
+ this.setPageInfo(pageInfo);
1858
+ } else {
1859
+ pageInfo.pageIndex = result.pageIndex;
1860
+ pageInfo.from = 'showPageInner';
1861
+ this.setPageInfo(pageInfo);
1862
+ }
1863
+ resetSelected.call(this);
1864
+ 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')) {
1865
+ this._set_data('focusedRowIndex', -1); // 重置选中行
1866
+ }
1867
+ for (var _len = arguments.length, args = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++) {
1868
+ args[_key - 4] = arguments[_key];
1869
+ }
1870
+ this.execute('afterSetDataSource', data, result.viewmodel, args === null || args === void 0 ? void 0 : args[1]); // 社保缴交节点翻页的时候需要改columns
1871
+ };
1872
+ {
1873
+ if (viewModel.execute('beforeQueryData', params) === false) return;
1874
+ self.setCache('lastGridFilterCondition', JSON.stringify(params === null || params === void 0 ? void 0 : params.condition));
1875
+ var queryDataParams = _.cloneDeep(params);
1876
+ proxy.queryData(queryDataParams, queryDataCallback, _this);
1877
+ }
1878
+ if (refresh && bLoadPagination && delayLoadPageInfo) {
1879
+ var queryPageProxyConfig = JSON.parse(JSON.stringify(proxyConfig));
1880
+ if (!queryPageProxyConfig.options) {
1881
+ queryPageProxyConfig.options = {};
1882
+ }
1883
+ queryPageProxyConfig.options.mask = false;
1884
+ var _callback = function _callback(pageInfo) {
1885
+ queryCount++;
1886
+ Object.assign(responseData, pageInfo);
1887
+ if (queryCount === 2 && callback) {
1888
+ callback.call(_this, responseData);
1889
+ }
1890
+ };
1891
+ queryPageCount.call(_this, queryPageProxyConfig, params, function (pageInfo) {
1892
+ _callback(pageInfo);
1893
+ });
1894
+ }
1895
+ });
1896
+ };
1897
+
1898
+ /* 查询分页 */
1899
+ function queryPageCount(proxyConfig, queryParams, callback) {
1900
+ this.setCache('queryPageCountLoading', true);
1901
+ // this.rebuildProxyConfig(proxyConfig);
1902
+ var proxy = this.setProxy({
1903
+ queryPageCount: _objectSpread2({}, proxyConfig)
1904
+ });
1905
+ var defaultParams = {
1906
+ page: {
1907
+ totalCount: -1
1908
+ }
1909
+ };
1910
+ var params = Object.assign(true, queryParams, defaultParams);
1911
+ if (!this.__queryPageCountRequestId) this.__queryPageCountRequestId = 0;
1912
+ this.__queryPageCountRequestId++;
1913
+ var queryPageCountCallback = function queryPageCountCallback(requestId, err, result) {
1914
+ if (this.__queryPageCountRequestId !== requestId) return;
1915
+ this.setCache('queryPageCountLoading', false);
1916
+ this.setState('showDelayPagination', false);
1917
+ if (err) {
1918
+ var currentpageinfo = this._get_data('pageInfo');
1919
+ if (currentpageinfo) {
1920
+ // 接口报错时,分页组件信息保持原来的值
1921
+ this.setPageInfo(currentpageinfo);
1922
+ }
1923
+ return;
1924
+ }
1925
+ result = result || {}; // 容错处理null或者undefined情况
1926
+ var pageInfo = {
1927
+ beginPageIndex: result.beginPageIndex,
1928
+ endPageIndex: result.endPageIndex,
1929
+ pageSize: result.pageSize,
1930
+ pageIndex: result.pageIndex,
1931
+ pageCount: result.pageCount,
1932
+ recordCount: result.recordCount
1933
+ };
1934
+ if (callback) {
1935
+ callback.call(this, pageInfo);
1936
+ }
1937
+ this.setPageInfo(pageInfo);
1938
+ this.execute('afterQueryPageInfo', result);
1939
+ };
1940
+ proxy.queryPageCount(params, queryPageCountCallback.bind(this, this.__queryPageCountRequestId), this);
1941
+ }
1942
+
1943
+ // ============================================================
1944
+
1945
+ var GridModel = /*#__PURE__*/function (_BaseModel) {
1946
+ function GridModel() {
1947
+ var _this2;
1948
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1949
+ _classCallCheck(this, GridModel);
1950
+ var data = _objectSpread2(_objectSpread2({}, createDefaultProps()), props);
1951
+ // `dataSource: fn` 是旧写法,含义是「取数函数」而不是「数据」,这里统一收敛掉
1952
+ if (!isArray(data.dataSource)) data.dataSource = [];
1953
+ if (!isArray(data.rows)) data.rows = [];
1954
+ var proxyConfig = resolveProxyConfig(props);
1955
+ data.proxyConfig = proxyConfig;
1956
+ // 有取数配置就是服务端分页,否则按静态数据在前端分页
1957
+ data.dataSourceMode = props.dataSourceMode || (proxyConfig.load ? 'remote' : 'local');
1958
+ // 静态数据:cData / data 数组
1959
+ var seed = props.cData || (isArray(props.data) ? props.data : null);
1960
+ _this2 = _callSuper(this, GridModel, [data]);
1961
+ _this2.initPageInfo(props.cPage || props.page);
1962
+ _this2.initColumns(data.columns);
1963
+ _this2.initRowState();
1964
+ _this2.afterInit();
1965
+ if (seed) _this2.setDataSource(seed);
1966
+ return _this2;
1967
+ }
1968
+
1969
+ // 中台在 afterInit 里做主子表/行模型初始化,我们这里只留一个扩展点给业务继承
1970
+ _inherits(GridModel, _BaseModel);
1971
+ return _createClass(GridModel, [{
1972
+ key: "afterInit",
1973
+ value: function afterInit() {
1974
+ if (this._get_data('parentRelation') === 'single') this._set_data('defaultSelectedRowIndexes', true);
1975
+ }
1976
+ }, {
1977
+ key: "initColumns",
1978
+ value: function initColumns(columns) {
1979
+ var map = normalizeColumns(columns);
1980
+ this._set_data('columns', map, true);
1981
+ return map;
1982
+ }
1983
+ }, {
1984
+ key: "initPageInfo",
1985
+ value: function initPageInfo() {
1986
+ var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1987
+ var pageInfo = _objectSpread2({}, this.getPageInfo());
1988
+ pageInfo.pageIndex = page.pageNo || page.pageIndex || pageInfo.pageIndex || 1;
1989
+ pageInfo.pageSize = page.pageSize || pageInfo.pageSize || DEFAULT_PAGE_SIZE;
1990
+ // 中台习惯:不分页时把 pageSize 记成 -1
1991
+ if (this.get('pagination') === false) pageInfo.pageSize = -1;
1992
+ this.applyPageInfo(pageInfo);
1993
+ }
1994
+
1995
+ // 与 dataSource 同序的行状态,先铺平
1996
+ }, {
1997
+ key: "initRowState",
1998
+ value: function initRowState() {
1999
+ var _this3 = this;
2000
+ var source = this._get_data('dataSource');
2001
+ this._set_data('rowsDataState', (isArray(source) ? source : []).map(function (row) {
2002
+ return (row === null || row === void 0 ? void 0 : row[_this3.getStatusFlag()]) || DataStates.Unchanged;
2003
+ }), true);
2004
+ }
2005
+
2006
+ /* ========================= 内部字段 / 开关 ========================= */
2007
+ }, {
2008
+ key: "getInnerUsedAttrs",
2009
+ value: function getInnerUsedAttrs() {
2010
+ return this._get_data('innerUsedAttrs');
2011
+ }
2012
+ }, {
2013
+ key: "getIdFlag",
2014
+ value: function getIdFlag() {
2015
+ return this.getInnerUsedAttrs().id;
2016
+ }
2017
+ }, {
2018
+ key: "getSelectedFlag",
2019
+ value: function getSelectedFlag() {
2020
+ return this.getInnerUsedAttrs().selected;
2021
+ }
2022
+ }, {
2023
+ key: "getStatusFlag",
2024
+ value: function getStatusFlag() {
2025
+ return this.getInnerUsedAttrs().status;
2026
+ }
2027
+ }, {
2028
+ key: "getRowKeyField",
2029
+ value: function getRowKeyField() {
2030
+ return this._get_data('rowKeyField') || 'id';
2031
+ }
2032
+ }, {
2033
+ key: "getProxyConfig",
2034
+ value: function getProxyConfig() {
2035
+ return this._get_data('proxyConfig') || {};
2036
+ }
2037
+ }, {
2038
+ key: "isRemote",
2039
+ value: function isRemote() {
2040
+ return this._get_data('dataSourceMode') === 'remote';
2041
+ }
2042
+ }, {
2043
+ key: "isPagination",
2044
+ value: function isPagination() {
2045
+ return !!this.get('pagination') && this.getPageSize() !== -1;
2046
+ }
2047
+ }, {
2048
+ key: "getReadOnly",
2049
+ value: function getReadOnly() {
2050
+ return !!this._get_data('readOnly');
2051
+ }
2052
+ }, {
2053
+ key: "setReadOnly",
2054
+ value: function setReadOnly(readOnly) {
2055
+ this._applyState('readOnly', !!readOnly);
2056
+ }
2057
+ }, {
2058
+ key: "getParams",
2059
+ value: function getParams() {
2060
+ return _objectSpread2(_objectSpread2({}, this.get('cParams') || {}), this._get_data('params') || {});
2061
+ }
2062
+ }, {
2063
+ key: "setParams",
2064
+ value: function setParams(params) {
2065
+ this._set_data('params', params || {});
2066
+ }
2067
+ }, {
2068
+ key: "setMeta",
2069
+ value: function setMeta(meta) {
2070
+ this._set_data('meta', meta);
2071
+ }
2072
+
2073
+ /* ============================= 列 ============================= */
2074
+
2075
+ /** 与中台一致:返回 object map(深拷贝),而不是数组 */
2076
+ }, {
2077
+ key: "getColumns",
2078
+ value: function getColumns(fields) {
2079
+ var columns = this._get_data('columns') || {};
2080
+ var result = {};
2081
+ var keys = fields ? isArray(fields) ? fields : [fields] : Object.getOwnPropertyNames(columns);
2082
+ keys.forEach(function (key) {
2083
+ if (!columns[key]) return;
2084
+ result[key] = _objectSpread2(_objectSpread2({}, columns[key]), {}, {
2085
+ fieldName: columns[key].fieldName || key
2086
+ });
2087
+ });
2088
+ return result;
2089
+ }
2090
+ }, {
2091
+ key: "getColumn",
2092
+ value: function getColumn(field) {
2093
+ var _this$_get_data;
2094
+ var column = (_this$_get_data = this._get_data('columns')) === null || _this$_get_data === void 0 ? void 0 : _this$_get_data[field];
2095
+ return column ? _objectSpread2(_objectSpread2({}, column), {}, {
2096
+ fieldName: column.fieldName || field
2097
+ }) : undefined;
2098
+ }
2099
+ }, {
2100
+ key: "hasColumn",
2101
+ value: function hasColumn(field) {
2102
+ return !!(this._get_data('columns') || {})[field];
2103
+ }
2104
+ }, {
2105
+ key: "getColumnList",
2106
+ value: function getColumnList(fields) {
2107
+ var columns = this.getColumns(fields);
2108
+ return Object.keys(columns).sort(function (a, b) {
2109
+ return (columns[a].index || 0) - (columns[b].index || 0);
2110
+ }).map(function (key) {
2111
+ return columns[key];
2112
+ });
2113
+ }
2114
+ }, {
2115
+ key: "getVisibleColumns",
2116
+ value: function getVisibleColumns(fields) {
2117
+ return this.getColumnList(fields).filter(function (column) {
2118
+ return column.bHidden !== true && column.bShowIt !== false;
2119
+ });
2120
+ }
2121
+ }, {
2122
+ key: "setColumns",
2123
+ value: function setColumns(columns) {
2124
+ if (!columns) return;
2125
+ this._applyState('columns', normalizeColumns(columns));
2126
+ }
2127
+ }, {
2128
+ key: "setColumnMode",
2129
+ value: function setColumnMode(mode) {
2130
+ this._set_data('columnMode', mode === 'remote' ? 'remote' : 'local', true);
2131
+ }
2132
+ }, {
2133
+ key: "addColumns",
2134
+ value: function addColumns(columns) {
2135
+ var map = normalizeColumns(columns);
2136
+ this._applyState('columns', _objectSpread2(_objectSpread2({}, this._get_data('columns') || {}), map));
2137
+ }
2138
+ }, {
2139
+ key: "resetColumns",
2140
+ value: function resetColumns(columns) {
2141
+ this.setColumns(columns || this.get('cColumns'));
2142
+ }
2143
+ }, {
2144
+ key: "getColumnState",
2145
+ value: function getColumnState(rowIndex, field, name) {
2146
+ var _this$_get_data2;
2147
+ var rowKey = this.getRowKey(rowIndex);
2148
+ 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;
2149
+ }
2150
+ }, {
2151
+ key: "setColumnState",
2152
+ value: function setColumnState(rowIndex, field, name, value) {
2153
+ this.setCellState(rowIndex, field, name, value);
2154
+ }
2155
+ }, {
2156
+ key: "setColumnStates",
2157
+ value: function setColumnStates() {
2158
+ var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2159
+ this.setCellStates(states.map(function (item) {
2160
+ return _objectSpread2(_objectSpread2({}, item), {}, {
2161
+ cellName: item.cellName || item.columnName
2162
+ });
2163
+ }));
2164
+ }
2165
+ }, {
2166
+ key: "setColumnValue",
2167
+ value: function setColumnValue(field, name, value) {
2168
+ var columns = this._get_data('columns') || {};
2169
+ if (!columns[field]) return;
2170
+ this._applyState('columns', _objectSpread2(_objectSpread2({}, columns), {}, _defineProperty({}, field, _objectSpread2(_objectSpread2({}, columns[field]), {}, _defineProperty({}, name, value)))));
2171
+ }
2172
+
2173
+ /* ============================ 取数 ============================ */
2174
+
2175
+ // 中台签名:load(proxyConfig, params, callback) = 设置取数配置并立刻取一次
2176
+ }, {
2177
+ key: "load",
2178
+ value: function load(proxyConfig, params, callback) {
2179
+ // if (proxyConfig) this.setProxy(proxyConfig)
2180
+ // return this.fetch(params || {}).then((result) => {
2181
+ // if (typeof callback === 'function') callback.call(this, null, result)
2182
+ // return result
2183
+ // })
2184
+
2185
+ var proxy = this.setProxy({
2186
+ load: proxyConfig
2187
+ });
2188
+ proxy.load(params, function (err, result) {
2189
+ if (err) {
2190
+ cb.utils.alert(err, 'error');
2191
+ return;
2192
+ }
2193
+ if (result.schema) {
2194
+ this._set_data('columnMode', 'remote');
2195
+ this.setColumns(result.schema);
2196
+ }
2197
+ this.setDataSource(result.data);
2198
+ if (callback) {
2199
+ callback.call(this);
2200
+ }
2201
+ }, this);
2202
+ }
2203
+
2204
+ // 重新取数:优先驱动已挂载的表格(走表格自带的分页状态),没有视图时直接取数
2205
+ }, {
2206
+ key: "refresh",
2207
+ value: function refresh() {
2208
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2209
+ if (this.hasEvent('refresh')) return this.execute('refresh', params);
2210
+ return this.fetch({
2211
+ body: params
2212
+ });
2213
+ }
2214
+ }, {
2215
+ key: "loadData",
2216
+ value: function loadData() {
2217
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2218
+ return this.refresh(params);
2219
+ }
2220
+ }, {
2221
+ key: "queryData",
2222
+ value: function queryData() {
2223
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2224
+ return this.refresh(params);
2225
+ }
2226
+
2227
+ /* ======================== 数据(两层) ======================== */
2228
+
2229
+ /** 全量数据源(中台 getRealData 的语义:不拷贝,剔除已删除行) */
2230
+ }, {
2231
+ key: "getDataSource",
2232
+ value: function getDataSource() {
2233
+ var source = this._get_data('dataSource') || [];
2234
+ if (!this.hasDeletedRow()) return source;
2235
+ var rowsDataState = this._get_data('rowsDataState') || [];
2236
+ return source.filter(function (row, index) {
2237
+ return rowsDataState[index] !== DataStates.Delete;
2238
+ });
2239
+ }
2240
+ }, {
2241
+ key: "getRealData",
2242
+ value: function getRealData() {
2243
+ return this.getDataSource();
2244
+ }
2245
+ }, {
2246
+ key: "getRealRows",
2247
+ value: function getRealRows() {
2248
+ return this._get_data('rows') || [];
2249
+ }
2250
+ }, {
2251
+ key: "getRowsCount",
2252
+ value: function getRowsCount() {
2253
+ return (this._get_data('rows') || []).length;
2254
+ }
2255
+ }, {
2256
+ key: "getDataSourceCount",
2257
+ value: function getDataSourceCount() {
2258
+ return (this._get_data('dataSource') || []).length;
2259
+ }
2260
+ }, {
2261
+ key: "hasDeletedRow",
2262
+ value: function hasDeletedRow() {
2263
+ return (this._get_data('rowsDataState') || []).some(function (state) {
2264
+ return state === DataStates.Delete;
2265
+ });
2266
+ }
2267
+
2268
+ /**
2269
+ * 数据出口,签名与中台一致,但语义容易踩坑,这里写清楚:
2270
+ * - `getData()` → 全量 dataSource(提交/保存用,保留 _status,剔除 _selected)
2271
+ * - `getData(true)` → 当前页 rows(视图用,剔除 _status / _selected)
2272
+ * - `getAllData()` → 等于 getData(true),仅为对齐中台签名而保留
2273
+ * - `getPageData()` → 等于 getData(true),语义更直白的别名
2274
+ */
2275
+ }, {
2276
+ key: "getData",
2277
+ value: function getData(view, realRows) {
2278
+ var rows = view || realRows ? this._get_data('rows') : this._get_data('dataSource');
2279
+ return this.collectRows(rows, view);
2280
+ }
2281
+ }, {
2282
+ key: "getAllData",
2283
+ value: function getAllData() {
2284
+ return this.getData(true);
2285
+ }
2286
+ }, {
2287
+ key: "getPageData",
2288
+ value: function getPageData() {
2289
+ return this.getData(true);
2290
+ }
2291
+
2292
+ /** 有效数据:全量里剔除 Delete 状态的行 */
2293
+ }, {
2294
+ key: "getEffeData",
2295
+ value: function getEffeData() {
2296
+ var source = this._get_data('dataSource') || [];
2297
+ var rowsDataState = this._get_data('rowsDataState') || [];
2298
+ return this.collectRows(source.filter(function (row, index) {
2299
+ return rowsDataState[index] !== DataStates.Delete;
2300
+ }), false);
2301
+ }
2302
+
2303
+ /** 当前页行(浅引用),isCopy=true 时返回深拷贝 */
2304
+ }, {
2305
+ key: "getRows",
2306
+ value: function getRows(isCopy) {
2307
+ var rows = this._get_data('rows') || [];
2308
+ return isCopy === false ? rows : rows.map(function (row) {
2309
+ return cloneDeep(row);
2310
+ });
2311
+ }
2312
+ }, {
2313
+ key: "collectRows",
2314
+ value: function collectRows(rows, view) {
2315
+ var columns = this._get_data('columns') || {};
2316
+ var statusFlag = this.getStatusFlag();
2317
+ var selectedFlag = this.getSelectedFlag();
2318
+ return (rows || []).map(function (rowData) {
2319
+ var row = {};
2320
+ for (var attr in rowData) {
2321
+ var _columns$attr;
2322
+ // 视图数据不带 _status;提交数据不带 _selected
2323
+ if (view && attr === statusFlag) continue;
2324
+ if (!view && attr === selectedFlag) continue;
2325
+ if (((_columns$attr = columns[attr]) === null || _columns$attr === void 0 ? void 0 : _columns$attr.needCollect) === false) continue;
2326
+ row[attr] = rowData[attr];
2327
+ }
2328
+ return row;
2329
+ });
2330
+ }
2331
+
2332
+ /** 展示文案副本(中台会把它推给组件;我们只作为工具方法保留) */
2333
+ }, {
2334
+ key: "getShowRows",
2335
+ value: function getShowRows(rows) {
2336
+ return (rows || this._get_data('rows') || []).map(function (row) {
2337
+ return _objectSpread2({}, row);
2338
+ });
2339
+ }
2340
+ }, {
2341
+ key: "getRow",
2342
+ value: function getRow(rowIndex, needGrandSon) {
2343
+ var _this$_get_data3;
2344
+ var row = (_this$_get_data3 = this._get_data('rows')) === null || _this$_get_data3 === void 0 ? void 0 : _this$_get_data3[rowIndex];
2345
+ if (!row) return undefined;
2346
+ return needGrandSon === false ? row : cloneDeep(row);
2347
+ }
2348
+ }, {
2349
+ key: "getRowIndex",
2350
+ value: function getRowIndex(row) {
2351
+ if (!row) return -1;
2352
+ var rows = this._get_data('rows') || [];
2353
+ var rowKeyField = this.getRowKeyField();
2354
+ if (row[rowKeyField] !== undefined) {
2355
+ return rows.findIndex(function (item) {
2356
+ return item[rowKeyField] === row[rowKeyField];
2357
+ });
2358
+ }
2359
+ return rows.indexOf(row);
2360
+ }
2361
+ }, {
2362
+ key: "getRowIndexByRowId",
2363
+ value: function getRowIndexByRowId(rowId) {
2364
+ var _this4 = this;
2365
+ var rows = this._get_data('rows') || [];
2366
+ return rows.findIndex(function (row) {
2367
+ return (row === null || row === void 0 ? void 0 : row[_this4.getIdFlag()]) === rowId;
2368
+ });
2369
+ }
2370
+ }, {
2371
+ key: "getDataSourceIndexByRowId",
2372
+ value: function getDataSourceIndexByRowId(rowId) {
2373
+ var _this5 = this;
2374
+ return (this._get_data('dataSource') || []).findIndex(function (row) {
2375
+ return (row === null || row === void 0 ? void 0 : row[_this5.getIdFlag()]) === rowId;
2376
+ });
2377
+ }
2378
+ }, {
2379
+ key: "getRowKey",
2380
+ value: function getRowKey(rowIndex) {
2381
+ var _this$_get_data$rowIn, _this$_get_data4;
2382
+ 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;
2383
+ }
2384
+ }, {
2385
+ key: "getRowKeys",
2386
+ value: function getRowKeys(rowData) {
2387
+ var list = rowData === undefined ? this.getRows() : isArray(rowData) ? rowData : [rowData];
2388
+ var keyField = this.getRowKeyField();
2389
+ return list.filter(function (row) {
2390
+ return row && row[keyField] !== undefined;
2391
+ }).map(function (row) {
2392
+ return row[keyField];
2393
+ });
2394
+ }
2395
+ }, {
2396
+ key: "getRowsByIndexes",
2397
+ value: function getRowsByIndexes(rowIndexes) {
2398
+ var rows = this._get_data('rows') || [];
2399
+ return (isArray(rowIndexes) ? rowIndexes : [rowIndexes]).map(function (index) {
2400
+ return rows[index];
2401
+ }).filter(Boolean);
2402
+ }
2403
+
2404
+ /* ==================== 单元格值 / 单元格状态 ==================== */
2405
+ }, {
2406
+ key: "getCellValue",
2407
+ value: function getCellValue(rowIndex, cellName) {
2408
+ var _this$_get_data5;
2409
+ var row = rowIndex >= 0 ? (_this$_get_data5 = this._get_data('rows')) === null || _this$_get_data5 === void 0 ? void 0 : _this$_get_data5[rowIndex] : null;
2410
+ if (!row || !cellName) return undefined;
2411
+ return row[cellName];
2412
+ }
2413
+ }, {
2414
+ key: "setCellValue",
2415
+ value: function setCellValue(rowIndex, cellName, value) {
2416
+ var rows = this._get_data('rows') || [];
2417
+ var row = rows[rowIndex];
2418
+ if (!row || !cellName) return;
2419
+ var oldValue = row[cellName];
2420
+ if (oldValue === value) return;
2421
+ var data = {
2422
+ rowIndex: rowIndex,
2423
+ rowId: row[this.getIdFlag()],
2424
+ cellName: cellName,
2425
+ value: value,
2426
+ oldValue: oldValue
2427
+ };
2428
+ if (!this.execute('beforeCellValueChange', data)) return;
2429
+ row[cellName] = data.value;
2430
+ this.markRowState(rowIndex, DataStates.Update);
2431
+ this.execute('afterCellValueChange', data);
2432
+ this.doPropertyChange('setCellValue', data);
2433
+ }
2434
+ }, {
2435
+ key: "setCellValues",
2436
+ value: function setCellValues() {
2437
+ var _this6 = this;
2438
+ var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2439
+ if (!isArray(values)) return;
2440
+ values.forEach(function (item) {
2441
+ return _this6.setCellValue(item.rowIndex, item.cellName || item.field, item.value);
2442
+ });
2443
+ }
2444
+ }, {
2445
+ key: "getCellState",
2446
+ value: function getCellState(rowIndex, cellName, name) {
2447
+ var _this$_get_data6;
2448
+ var rowKey = this.getRowKey(rowIndex);
2449
+ 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;
2450
+ if (!cell) return undefined;
2451
+ return cell[name];
2452
+ }
2453
+ }, {
2454
+ key: "setCellState",
2455
+ value: function setCellState(rowIndex, cellName, name, value) {
2456
+ var _this$_get_data7;
2457
+ 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()];
2458
+ var rowKey = rowId || rowIndex;
2459
+ if (isEmpty(rowKey)) return;
2460
+ var oldValue = this.getCellState(rowIndex, cellName, name);
2461
+ if (oldValue === value) return;
2462
+ var data = {
2463
+ rowIndex: rowIndex,
2464
+ rowId: rowId,
2465
+ cellName: cellName,
2466
+ propertyName: name,
2467
+ value: value,
2468
+ oldValue: oldValue
2469
+ };
2470
+ if (!this.execute('beforeCellStateChange', data)) return;
2471
+ var cellState = _objectSpread2({}, this._get_data('cellState') || {});
2472
+ cellState[rowKey] = _objectSpread2({}, cellState[rowKey] || {});
2473
+ cellState[rowKey][cellName] = _objectSpread2(_objectSpread2({}, cellState[rowKey][cellName] || {}), {}, _defineProperty({}, name, value));
2474
+ this._applyState('cellState', cellState);
2475
+ this.execute('afterCellStateChange', data);
2476
+ }
2477
+ }, {
2478
+ key: "setCellStates",
2479
+ value: function setCellStates() {
2480
+ var _this7 = this;
2481
+ var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2482
+ if (!isArray(states)) return;
2483
+ states.forEach(function (item) {
2484
+ return _this7.setCellState(item.rowIndex, item.cellName, item.propertyName || item.name, item.value);
2485
+ });
2486
+ }
2487
+
2488
+ /* ==================== 行状态 / 脏数据 ==================== */
2489
+
2490
+ /** 行数据状态(Insert / Update / Delete / 空),rowIndex 是 rows 的下标 */
2491
+ }, {
2492
+ key: "getRowDataState",
2493
+ value: function getRowDataState(rowIndex) {
2494
+ var _this$_get_data8;
2495
+ var indexInDS = this.getDataSourceIndexByRow(rowIndex);
2496
+ return (_this$_get_data8 = this._get_data('rowsDataState')) === null || _this$_get_data8 === void 0 ? void 0 : _this$_get_data8[indexInDS];
2497
+ }
2498
+ }, {
2499
+ key: "getDataSourceIndexByRow",
2500
+ value: function getDataSourceIndexByRow(rowIndex) {
2501
+ var _this8 = this;
2502
+ var rows = this._get_data('rows') || [];
2503
+ var row = rows[rowIndex];
2504
+ if (!row) return -1;
2505
+ var source = this._get_data('dataSource') || [];
2506
+ var index = source.indexOf(row);
2507
+ if (index > -1) return index;
2508
+ // 本地分页时 rows 是切片,引用一致;远程模式下 rows 与 dataSource 同源
2509
+ return source.findIndex(function (item) {
2510
+ return (item === null || item === void 0 ? void 0 : item[_this8.getIdFlag()]) === (row === null || row === void 0 ? void 0 : row[_this8.getIdFlag()]);
2511
+ });
2512
+ }
2513
+ }, {
2514
+ key: "setRowDataState",
2515
+ value: function setRowDataState(rowIndex, dataState) {
2516
+ var indexInDS = this.getDataSourceIndexByRow(rowIndex);
2517
+ if (indexInDS < 0) return;
2518
+ var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2519
+ rowsDataState[indexInDS] = dataState;
2520
+ this._set_data('rowsDataState', rowsDataState, true);
2521
+ }
2522
+
2523
+ // 只在「原状态是 Unchanged」时置为 Update,避免把 Insert 覆盖成 Update
2524
+ }, {
2525
+ key: "markRowState",
2526
+ value: function markRowState(rowIndex, dataState) {
2527
+ var current = this.getRowDataState(rowIndex);
2528
+ if (current === DataStates.Insert || current === dataState) return;
2529
+ this.setRowDataState(rowIndex, dataState);
2530
+ }
2531
+
2532
+ /** 单元格编辑由组件回灌时用:传行对象或行下标都可以 */
2533
+ }, {
2534
+ key: "markRowUpdate",
2535
+ value: function markRowUpdate(rowOrIndex) {
2536
+ var rowIndex = typeof rowOrIndex === 'number' ? rowOrIndex : this.getRowIndex(rowOrIndex);
2537
+ if (rowIndex < 0) return;
2538
+ this.markRowState(rowIndex, DataStates.Update);
2539
+ }
2540
+ }, {
2541
+ key: "getRowState",
2542
+ value: function getRowState(rowIndex, name) {
2543
+ var _this$_get_data9;
2544
+ var rowKey = this.getRowKey(rowIndex);
2545
+ var row = rowKey ? (_this$_get_data9 = this._get_data('rowState')) === null || _this$_get_data9 === void 0 ? void 0 : _this$_get_data9[rowKey] : null;
2546
+ if (!row || !name) return undefined;
2547
+ return row[name];
2548
+ }
2549
+ }, {
2550
+ key: "setRowState",
2551
+ value: function setRowState(rowIndex, name, value) {
2552
+ var _this$_get_data0;
2553
+ var row = (_this$_get_data0 = this._get_data('rows')) === null || _this$_get_data0 === void 0 ? void 0 : _this$_get_data0[rowIndex];
2554
+ if (!row || !name) return;
2555
+ var rowKey = this.getRowKey(rowIndex);
2556
+ var oldValue = this.getRowState(rowIndex, name);
2557
+ if (oldValue === value) return;
2558
+ var data = {
2559
+ rowIndex: rowIndex,
2560
+ rowId: row[this.getIdFlag()],
2561
+ propertyName: name,
2562
+ value: value,
2563
+ oldValue: oldValue
2564
+ };
2565
+ if (!this.execute('beforeRowStateChange', data)) return;
2566
+ var rowState = _objectSpread2({}, this._get_data('rowState') || {});
2567
+ rowState[rowKey] = _objectSpread2(_objectSpread2({}, rowState[rowKey] || {}), {}, _defineProperty({}, name, value));
2568
+ this._applyState('rowState', rowState);
2569
+ this.execute('afterRowStateChange', data);
2570
+ }
2571
+ }, {
2572
+ key: "setRowStates",
2573
+ value: function setRowStates() {
2574
+ var _this9 = this;
2575
+ var states = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2576
+ if (!isArray(states)) return;
2577
+ states.forEach(function (item) {
2578
+ return _this9.setRowState(item.rowIndex, item.propertyName || item.name, item.value);
2579
+ });
2580
+ }
2581
+
2582
+ /** 收集增删改过的行,用于提交;没有脏数据时返回 undefined(中台同款) */
2583
+ }, {
2584
+ key: "getDirtyData",
2585
+ value: function getDirtyData(necessary) {
2586
+ var _this0 = this;
2587
+ var source = this._get_data('dataSource') || [];
2588
+ var rowsDataState = this._get_data('rowsDataState') || [];
2589
+ var data = [];
2590
+ source.forEach(function (row, index) {
2591
+ var dataState = rowsDataState[index];
2592
+ if (!dataState) return;
2593
+ var item = cloneDeep(row);
2594
+ item[_this0.getStatusFlag()] = dataState;
2595
+ data.push(item);
2596
+ });
2597
+ return data.length ? data : undefined;
2598
+ }
2599
+ }, {
2600
+ key: "getDirtyRowIndexes",
2601
+ value: function getDirtyRowIndexes() {
2602
+ var _this1 = this;
2603
+ var rows = this._get_data('rows') || [];
2604
+ return rows.map(function (row, index) {
2605
+ return index;
2606
+ }).filter(function (index) {
2607
+ return !!_this1.getRowDataState(index);
2608
+ });
2609
+ }
2610
+ }, {
2611
+ key: "isDirty",
2612
+ value: function isDirty() {
2613
+ return !!this.getDirtyData();
2614
+ }
2615
+
2616
+ // 备份 / 还原未提交的数据(取消编辑时用)
2617
+ }, {
2618
+ key: "backupState",
2619
+ value: function backupState() {
2620
+ this._set_data('backupData', {
2621
+ dataSource: cloneDeep(this._get_data('dataSource') || []),
2622
+ rowsDataState: _toConsumableArray(this._get_data('rowsDataState') || [])
2623
+ });
2624
+ }
2625
+ }, {
2626
+ key: "restoreState",
2627
+ value: function restoreState() {
2628
+ var backup = this._get_data('backupData');
2629
+ if (!backup) return;
2630
+ this._set_data('dataSource', backup.dataSource, true);
2631
+ this._set_data('rowsDataState', _toConsumableArray(backup.rowsDataState), true);
2632
+ this.showPage();
2633
+ }
2634
+
2635
+ /* ======================= 增删改行 ======================= */
2636
+
2637
+ /** 中台签名:insertRow(rowIndex, rowData, needCheckDefault, isCopy, extendParams) */
2638
+ }, {
2639
+ key: "insertRow",
2640
+ value: function insertRow(rowIndex) {
2641
+ var rowData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2642
+ var isCopy = arguments.length > 3 ? arguments[3] : undefined;
2643
+ var rows = this._get_data('rows') || [];
2644
+ var index = Math.min(rows.length, Math.max(0, rowIndex === undefined ? rows.length : rowIndex));
2645
+ var data = {
2646
+ index: index,
2647
+ row: _objectSpread2({}, rowData),
2648
+ isCopy: isCopy
2649
+ };
2650
+ if (!this.execute('beforeInsertRow', data)) return;
2651
+ var row = data.row;
2652
+ delete row[this.getIdFlag()];
2653
+ setIds.call(this, [row]);
2654
+ var source = this._get_data('dataSource') || [];
2655
+ var indexInDS = index < rows.length ? this.getDataSourceIndexByRow(index) : source.length;
2656
+ source.splice(indexInDS < 0 ? source.length : indexInDS, 0, row);
2657
+ var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2658
+ rowsDataState.splice(indexInDS < 0 ? rowsDataState.length : indexInDS, 0, DataStates.Insert);
2659
+ rows.splice(index, 0, row);
2660
+ this._set_data('rowsDataState', rowsDataState, true);
2661
+ this.setRows(rows);
2662
+ this.execute('afterInsertRow', _objectSpread2(_objectSpread2({}, data), {}, {
2663
+ rowIndex: index
2664
+ }));
2665
+ return row;
2666
+ }
2667
+ }, {
2668
+ key: "insertRows",
2669
+ value: function insertRows(rowIndex) {
2670
+ var _this10 = this;
2671
+ var rowsData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
2672
+ var result = [];
2673
+ (isArray(rowsData) ? rowsData : [rowsData]).forEach(function (rowData, offset) {
2674
+ result.push(_this10.insertRow(rowIndex + offset, rowData));
2675
+ });
2676
+ return result;
2677
+ }
2678
+ }, {
2679
+ key: "appendRow",
2680
+ value: function appendRow() {
2681
+ var rowData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2682
+ return this.insertRow(this.getRowsCount(), rowData);
2683
+ }
2684
+ }, {
2685
+ key: "updateRow",
2686
+ value: function updateRow(rowIndex) {
2687
+ var _this$_get_data1;
2688
+ var rowData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2689
+ var row = (_this$_get_data1 = this._get_data('rows')) === null || _this$_get_data1 === void 0 ? void 0 : _this$_get_data1[rowIndex];
2690
+ if (!row) return;
2691
+ if (!this.execute('beforeUpdateRow', {
2692
+ index: rowIndex,
2693
+ row: rowData
2694
+ })) return;
2695
+ Object.assign(row, rowData);
2696
+ this.markRowState(rowIndex, DataStates.Update);
2697
+ this.setRows(this._get_data('rows'));
2698
+ this.execute('afterUpdateRow', {
2699
+ index: rowIndex,
2700
+ row: row
2701
+ });
2702
+ }
2703
+ }, {
2704
+ key: "updateRows",
2705
+ value: function updateRows() {
2706
+ var _this11 = this;
2707
+ var rowsData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2708
+ rowsData.forEach(function (item) {
2709
+ var _item$rowIndex;
2710
+ return _this11.updateRow((_item$rowIndex = item.rowIndex) !== null && _item$rowIndex !== void 0 ? _item$rowIndex : item.index, item.rowData || item.row);
2711
+ });
2712
+ }
2713
+
2714
+ /** 删除行:有 id 的行标 Delete 保留占位,本地新增未保存的行直接丢弃(中台同款) */
2715
+ }, {
2716
+ key: "deleteRows",
2717
+ value: function deleteRows(rowIndexes) {
2718
+ var _this12 = this;
2719
+ var indexes = (isArray(rowIndexes) ? rowIndexes : [rowIndexes]).filter(function (index) {
2720
+ return index >= 0 && index < _this12.getRowsCount();
2721
+ }).sort(function (a, b) {
2722
+ return a - b;
2723
+ });
2724
+ if (!indexes.length) return;
2725
+ var rowsToDelete = this.getRowsByIndexes(indexes);
2726
+ if (!this.execute('beforeDeleteRows', rowsToDelete, indexes)) return;
2727
+ var source = this._get_data('dataSource') || [];
2728
+ var rowsDataState = _toConsumableArray(this._get_data('rowsDataState') || []);
2729
+ var deletedIds = new Set();
2730
+ // 本地新增的行不需要保留占位,直接从数据源里抹掉
2731
+ var discardIds = new Set();
2732
+ rowsToDelete.forEach(function (row) {
2733
+ var index = source.indexOf(row);
2734
+ if (index < 0) return;
2735
+ var key = row[_this12.getIdFlag()];
2736
+ deletedIds.add(key);
2737
+ if (rowsDataState[index] === DataStates.Insert) discardIds.add(key);
2738
+ });
2739
+ var keptSource = [];
2740
+ var keptState = [];
2741
+ source.forEach(function (row, index) {
2742
+ var key = row[_this12.getIdFlag()];
2743
+ if (!deletedIds.has(key)) {
2744
+ keptSource.push(row);
2745
+ keptState.push(rowsDataState[index]);
2746
+ return;
2747
+ }
2748
+ if (discardIds.has(key)) return;
2749
+ keptSource.push(row);
2750
+ keptState.push(DataStates.Delete);
2751
+ });
2752
+ this._set_data('dataSource', keptSource, true);
2753
+ this._set_data('rowsDataState', keptState, true);
2754
+ // 本地模式下重新切片即可,删除行会自然消失在当前页
2755
+ this.showPage();
2756
+ this.execute('afterDeleteRows', {
2757
+ rowIndexes: indexes,
2758
+ rows: rowsToDelete
2759
+ });
2760
+ }
2761
+ }, {
2762
+ key: "deleteAllRows",
2763
+ value: function deleteAllRows() {
2764
+ this.deleteRows(this.getRows().map(function (row, index) {
2765
+ return index;
2766
+ }));
2767
+ }
2768
+ }, {
2769
+ key: "clear",
2770
+ value: function clear() {
2771
+ this._set_data('dataSource', [], true);
2772
+ this._set_data('rows', [], true);
2773
+ this._set_data('rowsDataState', [], true);
2774
+ this.clearSelection();
2775
+ this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
2776
+ recordCount: 0,
2777
+ pageIndex: 1
2778
+ }));
2779
+ this.setDataSourceView();
2780
+ }
2781
+
2782
+ /* ======================= 选中 ======================= */
2783
+
2784
+ /**
2785
+ * 选中行
2786
+ * @param {Number|Array} rowIndexes rows 下标
2787
+ * @param {Boolean} all true = 替换选择(先清掉其他选中),默认 false = 追加
2788
+ */
2789
+ }, {
2790
+ key: "select",
2791
+ value: function select(rowIndexes, all) {
2792
+ var _this13 = this;
2793
+ if (rowIndexes == null && all !== true) return;
2794
+ if (all === true) this.unselectAll({
2795
+ silent: true
2796
+ });
2797
+ var indexes = all === true ? this.getRows().map(function (row, index) {
2798
+ return index;
2799
+ }) : isArray(rowIndexes) ? rowIndexes : [rowIndexes];
2800
+ indexes = indexes.filter(function (index) {
2801
+ return index >= 0 && index < _this13.getRowsCount();
2802
+ });
2803
+ var rows = this._get_data('rows') || [];
2804
+ var selectedFlag = this.getSelectedFlag();
2805
+ var changed = indexes.filter(function (index) {
2806
+ return !rows[index][selectedFlag];
2807
+ });
2808
+ if (!changed.length) {
2809
+ if (all === true) this.flushSelection();
2810
+ return;
2811
+ }
2812
+ var data = {
2813
+ rowIndexes: changed,
2814
+ rows: changed.map(function (index) {
2815
+ return rows[index];
2816
+ })
2817
+ };
2818
+ if (!this.execute('beforeSelect', data)) return;
2819
+ changed.forEach(function (index) {
2820
+ rows[index][selectedFlag] = true;
2821
+ _this13.cacheSelectedRow(rows[index], true);
2822
+ });
2823
+ this.flushSelection();
2824
+ }
2825
+ }, {
2826
+ key: "unselect",
2827
+ value: function unselect(rowIndexes) {
2828
+ var _this14 = this;
2829
+ if (rowIndexes == null) return;
2830
+ var indexes = isArray(rowIndexes) ? rowIndexes : [rowIndexes];
2831
+ var rows = this._get_data('rows') || [];
2832
+ var selectedFlag = this.getSelectedFlag();
2833
+ var changed = indexes.filter(function (index) {
2834
+ var _rows$index;
2835
+ return (_rows$index = rows[index]) === null || _rows$index === void 0 ? void 0 : _rows$index[selectedFlag];
2836
+ });
2837
+ if (!changed.length) return;
2838
+ if (!this.execute('beforeUnselect', changed)) return;
2839
+ changed.forEach(function (index) {
2840
+ rows[index][selectedFlag] = false;
2841
+ _this14.cacheSelectedRow(rows[index], false);
2842
+ });
2843
+ this.flushSelection();
2844
+ }
2845
+ }, {
2846
+ key: "selectAll",
2847
+ value: function selectAll() {
2848
+ var _this15 = this;
2849
+ var rows = this._get_data('rows') || [];
2850
+ var selectedFlag = this.getSelectedFlag();
2851
+ rows.forEach(function (row) {
2852
+ row[selectedFlag] = true;
2853
+ _this15.cacheSelectedRow(row, true);
2854
+ });
2855
+ this.flushSelection();
2856
+ }
2857
+
2858
+ /**
2859
+ * 清空选中
2860
+ * @param {Object} options onlyPage=true 只清当前页(其他页的跨页缓存保留);silent=true 不下发视图
2861
+ *
2862
+ * 注意要清 **dataSource** 上的行:`_selected` 记在行对象上,
2863
+ * 而本地分页时当前页的 rows 只是 dataSource 的切片,只清 rows 会让翻页回来的行「带着选中复活」。
2864
+ */
2865
+ }, {
2866
+ key: "unselectAll",
2867
+ value: function unselectAll() {
2868
+ var _this16 = this;
2869
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2870
+ var selectedFlag = this.getSelectedFlag();
2871
+ var targets = options.onlyPage ? this._get_data('rows') : this._get_data('dataSource');
2872
+ (targets || []).forEach(function (row) {
2873
+ row[selectedFlag] = false;
2874
+ });
2875
+ if (options.onlyPage) {
2876
+ (this._get_data('rows') || []).forEach(function (row) {
2877
+ return _this16.cacheSelectedRow(row, false);
2878
+ });
2879
+ } else {
2880
+ this._set_data('selectedKeys', [], true);
2881
+ this._set_data('selectedRowsMap', {}, true);
2882
+ this._set_data('selectedKeysSet', new Set(), true);
2883
+ }
2884
+ if (!options.silent) this.flushSelection();
2885
+ }
2886
+ }, {
2887
+ key: "clearSelection",
2888
+ value: function clearSelection() {
2889
+ this.unselectAll();
2890
+ }
2891
+
2892
+ /**
2893
+ * 以传入的行集合作为**当前页**的选中结果(表格选中变化回灌的入口)。
2894
+ * 其他页的跨页选中缓存不受影响 —— 表格的勾选状态只覆盖当前页,
2895
+ * 若在这里清空缓存,翻页就会把之前选的行丢掉。
2896
+ */
2897
+ }, {
2898
+ key: "setSelectedRows",
2899
+ value: function setSelectedRows() {
2900
+ var _this17 = this;
2901
+ var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2902
+ var list = isArray(rows) ? rows : [];
2903
+ var keyField = this.getRowKeyField();
2904
+ var keys = new Set(list.map(function (row) {
2905
+ var _row$keyField;
2906
+ return String((_row$keyField = row === null || row === void 0 ? void 0 : row[keyField]) !== null && _row$keyField !== void 0 ? _row$keyField : row);
2907
+ }));
2908
+ var currentRows = this._get_data('rows') || [];
2909
+ var selectedFlag = this.getSelectedFlag();
2910
+ currentRows.forEach(function (row) {
2911
+ var selected = keys.has(String(row[keyField]));
2912
+ if (selected !== !!row[selectedFlag]) {
2913
+ row[selectedFlag] = selected;
2914
+ _this17.cacheSelectedRow(row, selected);
2915
+ }
2916
+ });
2917
+ this.flushSelection();
2918
+ }
2919
+
2920
+ /** 全量替换选中(含清掉其他页的缓存) */
2921
+ }, {
2922
+ key: "setSelection",
2923
+ value: function setSelection() {
2924
+ var rows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2925
+ this.unselectAll({
2926
+ silent: true
2927
+ });
2928
+ this.setSelectedRows(rows);
2929
+ }
2930
+ }, {
2931
+ key: "getSelectedRows",
2932
+ value: function getSelectedRows(rowIndexes) {
2933
+ var rows = this._get_data('rows') || [];
2934
+ var selectedFlag = this.getSelectedFlag();
2935
+ var keys = rowIndexes && new Set(isArray(rowIndexes) ? rowIndexes : [rowIndexes]);
2936
+ return rows.filter(function (row, index) {
2937
+ return row[selectedFlag] && (!keys || keys.has(index));
2938
+ });
2939
+ }
2940
+ }, {
2941
+ key: "getSelectedRowIndexes",
2942
+ value: function getSelectedRowIndexes() {
2943
+ var rows = this._get_data('rows') || [];
2944
+ var selectedFlag = this.getSelectedFlag();
2945
+ var indexes = [];
2946
+ rows.forEach(function (row, index) {
2947
+ if (row[selectedFlag]) indexes.push(index);
2948
+ });
2949
+ return indexes;
2950
+ }
2951
+ }, {
2952
+ key: "getSelectedKeys",
2953
+ value: function getSelectedKeys() {
2954
+ return this._get_data('selectedKeys') || [];
2955
+ }
2956
+
2957
+ /** 跨页选中的全部行(按选中顺序) */
2958
+ }, {
2959
+ key: "getAllCacheSelectedRows",
2960
+ value: function getAllCacheSelectedRows() {
2961
+ var keys = this._get_data('selectedKeys') || [];
2962
+ var rowsMap = this._get_data('selectedRowsMap') || {};
2963
+ return keys.map(function (key) {
2964
+ return rowsMap[key];
2965
+ }).filter(Boolean);
2966
+ }
2967
+ }, {
2968
+ key: "selectByKeys",
2969
+ value: function selectByKeys(keys) {
2970
+ var selected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2971
+ var rowKeyField = this.getRowKeyField();
2972
+ var list = isArray(keys) ? keys : [keys];
2973
+ var rows = this._get_data('rows') || [];
2974
+ var indexes = [];
2975
+ list.forEach(function (key) {
2976
+ var index = rows.findIndex(function (row) {
2977
+ return String(row[rowKeyField]) === String(key);
2978
+ });
2979
+ if (index > -1) indexes.push(index);
2980
+ });
2981
+ if (!indexes.length) return;
2982
+ selected ? this.select(indexes) : this.unselect(indexes);
2983
+ }
2984
+ }, {
2985
+ key: "getSelectedNodes",
2986
+ value: function getSelectedNodes() {
2987
+ return this.getAllCacheSelectedRows();
2988
+ }
2989
+ }, {
2990
+ key: "cacheSelectedRow",
2991
+ value: function cacheSelectedRow(row, selected) {
2992
+ var key = String(row === null || row === void 0 ? void 0 : row[this.getRowKeyField()]);
2993
+ var keys = (this._get_data('selectedKeys') || []).filter(function (item) {
2994
+ return item !== key;
2995
+ });
2996
+ var rowsMap = _objectSpread2({}, this._get_data('selectedRowsMap') || {});
2997
+ if (selected) keys.push(key);
2998
+ if (selected) rowsMap[key] = row;else delete rowsMap[key];
2999
+ this._set_data('selectedKeys', keys, true);
3000
+ this._set_data('selectedRowsMap', rowsMap, true);
3001
+ this._set_data('selectedKeysSet', new Set(keys), true);
3002
+ }
3003
+
3004
+ // 选中变化统一在这里下发视图(组件侧用同步开关挡住回灌死循环)
3005
+ }, {
3006
+ key: "flushSelection",
3007
+ value: function flushSelection() {
3008
+ this._applyState('selectedRows', this.getSelectedRows());
3009
+ this.execute('selectionChange', {
3010
+ value: this.getSelectedRows(),
3011
+ keys: this.getSelectedKeys(),
3012
+ indexes: this.getSelectedRowIndexes()
3013
+ });
3014
+ }
3015
+
3016
+ // 重新取数后把跨页选中的标记补回当前页的行上
3017
+ }, {
3018
+ key: "restoreSelectedFlags",
3019
+ value: function restoreSelectedFlags() {
3020
+ if (!this.get('cacheSelectedRows')) return;
3021
+ var keysSet = this._get_data('selectedKeysSet') || new Set();
3022
+ if (!keysSet.size) return;
3023
+ var rowKeyField = this.getRowKeyField();
3024
+ var selectedFlag = this.getSelectedFlag();
3025
+ (this.getRows() || []).forEach(function (row) {
3026
+ row[selectedFlag] = keysSet.has(String(row[rowKeyField]));
3027
+ });
3028
+ }
3029
+
3030
+ /* ======================= 分页 ======================= */
3031
+ }, {
3032
+ key: "setPagination",
3033
+ value: function setPagination(value) {
3034
+ this._applyState('pagination', !!value);
3035
+ this.showPage();
3036
+ }
3037
+ }, {
3038
+ key: "getPageInfo",
3039
+ value: function getPageInfo() {
3040
+ return this._get_data('pageInfo') || createDefaults().pageInfo;
3041
+ }
3042
+ }, {
3043
+ key: "getPageIndex",
3044
+ value: function getPageIndex() {
3045
+ return this.getPageInfo().pageIndex;
3046
+ }
3047
+ }, {
3048
+ key: "getPageSize",
3049
+ value: function getPageSize() {
3050
+ return this.getPageInfo().pageSize;
3051
+ }
3052
+ }, {
3053
+ key: "getTotalCount",
3054
+ value: function getTotalCount() {
3055
+ return this.getPageInfo().recordCount;
3056
+ }
3057
+ }, {
3058
+ key: "setPageInfo",
3059
+ value: function setPageInfo(pageInfo) {
3060
+ this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), pageInfo), {
3061
+ refresh: true
3062
+ });
3063
+ }
3064
+ }, {
3065
+ key: "setPageIndex",
3066
+ value: function setPageIndex(pageIndex) {
3067
+ var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3068
+ if (typeof pageIndex !== 'number') return;
3069
+ this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3070
+ pageIndex: Math.max(1, pageIndex)
3071
+ }), {
3072
+ refresh: refresh
3073
+ });
3074
+ }
3075
+ }, {
3076
+ key: "setPageSize",
3077
+ value: function setPageSize(pageSize) {
3078
+ var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3079
+ if (typeof pageSize !== 'number') return;
3080
+ // 与中台一致:pageSize = -1 表示不分页
3081
+ this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3082
+ pageSize: Math.max(-1, pageSize),
3083
+ pageIndex: 1
3084
+ }), {
3085
+ refresh: refresh
3086
+ });
3087
+ }
3088
+ }, {
3089
+ key: "setRecordCount",
3090
+ value: function setRecordCount(recordCount) {
3091
+ this.applyPageInfo(_objectSpread2(_objectSpread2({}, this.getPageInfo()), {}, {
3092
+ recordCount: recordCount || 0
3093
+ }));
3094
+ }
3095
+
3096
+ /**
3097
+ * 统一的分页写入:算 pageCount / 记录 begin~end、切片、下发视图
3098
+ * @param {Object} options silent=true 时不通知视图(组件自己的翻页动作走这里)
3099
+ */
3100
+ }, {
3101
+ key: "applyPageInfo",
3102
+ value: function applyPageInfo(pageInfo) {
3103
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3104
+ var next = _objectSpread2({}, pageInfo || {});
3105
+ var pageSize = next.pageSize === -1 ? -1 : next.pageSize || DEFAULT_PAGE_SIZE;
3106
+ var recordCount = next.recordCount || 0;
3107
+ // recordCount 还没取到时不要按 pageCount 夹 pageIndex,否则「跳第 N 页」会被压回第 1 页
3108
+ var known = recordCount > 0;
3109
+ next.pageSize = pageSize;
3110
+ next.recordCount = recordCount;
3111
+ next.pageCount = pageSize > 0 ? Math.max(1, Math.ceil(recordCount / pageSize)) : 1;
3112
+ next.pageIndex = pageSize > 0 ? Math.max(1, known ? Math.min(next.pageIndex || 1, next.pageCount) : next.pageIndex || 1) : 1;
3113
+ next.beginPageIndex = pageSize > 0 ? (next.pageIndex - 1) * pageSize + 1 : 1;
3114
+ next.endPageIndex = pageSize > 0 ? Math.min(next.pageIndex * pageSize, recordCount) : recordCount;
3115
+ this._set_data('pageInfo', next, true);
3116
+ if (options.silent) return next;
3117
+ this._applyState('pageInfo', next);
3118
+ if (!this.isRemote()) this.showPage();
3119
+ if (options.refresh && this.isRemote()) this.refresh();
3120
+ return next;
3121
+ }
3122
+
3123
+ /** 本地分页:按 pageInfo 从 dataSource 切出当前页 rows */
3124
+ }, {
3125
+ key: "showPage",
3126
+ value: function showPage() {
3127
+ var source = this._get_data('dataSource') || [];
3128
+ if (this.isRemote() || !this.isPagination()) {
3129
+ this.setRows(source);
3130
+ return;
3131
+ }
3132
+ var _this$getPageInfo = this.getPageInfo(),
3133
+ pageIndex = _this$getPageInfo.pageIndex,
3134
+ pageSize = _this$getPageInfo.pageSize;
3135
+ var start = (pageIndex - 1) * pageSize;
3136
+ this.setRows(source.slice(start, start + pageSize));
3137
+ }
3138
+
3139
+ /* ======================= 数据写入 ======================= */
3140
+
3141
+ /** 全量赋值(中台 setDataSource):本地模式重新切片,远程模式等于当前页 */
3142
+ }, {
3143
+ key: "setDataSource",
3144
+ value: function setDataSource(proxyConfig) {
3145
+ var queryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3146
+ var callback = arguments.length > 2 ? arguments[2] : undefined;
3147
+ if (this._get_data('dataSourceMode') === 'local') {
3148
+ var data = cb.utils.isArray(proxyConfig) ? proxyConfig : [];
3149
+ if (!this.execute('beforeSetDataSource', data)) return;
3150
+ var rowKeyField = this._get_data('rowKeyField');
3151
+ var keyMap = {};
3152
+ data.forEach(function (item) {
3153
+ keyMap[item[rowKeyField]] = item;
3154
+ });
3155
+ this._set_data('keyMap', keyMap);
3156
+ this._set_data('dataSource', data, true);
3157
+ this.getCache('grandson');
3158
+ if (data.length) {
3159
+ setIds.call(this, data);
3160
+ }
3161
+ this.initRowState();
3162
+ // 修改缓存数据
3163
+ setCachePaginationRowData.call(this, data);
3164
+ // 修改行号
3165
+ this.doPropertyChange('resetCellStatus');
3166
+ this._set_data('rowState', {}, true);
3167
+ // this.showRows(null, true)
3168
+ this.doPropertyChange('setDataSource', this.getShowRows());
3169
+ this._set_data('delayInsertRows', []); // setDataSource方法会同步模型和组件数据,把延迟存的数据清掉
3170
+ if (this._get_data('isSorting')) {
3171
+ this._set_data('isSorting', false);
3172
+ }
3173
+ this.execute('afterSetDataSource', data);
3174
+ } else {
3175
+ if (!this.execute('beforeProxyLoad', queryParams)) return;
3176
+ var pageInfo = this._get_data('pageInfo');
3177
+ pageInfo.pageIndex = 1;
3178
+ var needLoadPageination = true;
3179
+ // this.rebuildProxyConfig(proxyConfig)
3180
+ this._set_data('proxyConfig', proxyConfig);
3181
+ this._set_data('queryParams', queryParams);
3182
+ this._set_data('callback', callback);
3183
+ showPageInner.call(this, proxyConfig, queryParams, callback, true, needLoadPageination);
3184
+ }
3185
+ }
3186
+
3187
+ /** 只换当前页 rows(中台 setRows) */
3188
+ }, {
3189
+ key: "setRows",
3190
+ value: function setRows(rows) {
3191
+ var list = isArray(rows) ? rows : [];
3192
+ this._set_data('rows', list, true);
3193
+ this.setRowsIdMap();
3194
+ // 注意:这里推的是原始行对象,而不是中台的 getShowRows() 展示副本 —— 否则
3195
+ // 选中回灌、单元格编辑会落到副本上,模型与视图的数据对不上
3196
+ this._applyState('data', list);
3197
+ }
3198
+ }, {
3199
+ key: "setDataSourceView",
3200
+ value: function setDataSourceView() {
3201
+ this._applyState('data', this._get_data('rows') || []);
3202
+ }
3203
+ }, {
3204
+ key: "setRowsIdMap",
3205
+ value: function setRowsIdMap() {
3206
+ var _this18 = this;
3207
+ var map = {};
3208
+ (this._get_data('rows') || []).forEach(function (row) {
3209
+ if ((row === null || row === void 0 ? void 0 : row[_this18.getIdFlag()]) !== undefined) map[row[_this18.getIdFlag()]] = row;
3210
+ });
3211
+ this._set_data('rowsIdMap', map);
3212
+ }
3213
+ }, {
3214
+ key: "getRowIdMap",
3215
+ value: function getRowIdMap() {
3216
+ return this._get_data('rowsIdMap') || {};
3217
+ }
3218
+
3219
+ /* ======================= 校验 ======================= */
3220
+
3221
+ /**
3222
+ * 必输校验(中台会把校验委托给 editRowModel,我们这层没有行模型,只做列级必输)
3223
+ * @returns {Boolean} 通过返回 true,不通过返回 false,并把消息推给视图(validate 事件)
3224
+ */
3225
+ }, {
3226
+ key: "validate",
3227
+ value: function validate(cancel, paramsRowsIndex) {
3228
+ var _this19 = this;
3229
+ if (cancel) {
3230
+ this.doPropertyChange('validate', {
3231
+ type: '',
3232
+ message: '',
3233
+ errors: []
3234
+ });
3235
+ this._set_data('validateErrors', []);
3236
+ return false;
3237
+ }
3238
+ this.deleteNotModifiedRows();
3239
+ var columns = this._get_data('columns') || {};
3240
+ var rows = paramsRowsIndex ? this.getRowsByIndexes(paramsRowsIndex) : this.getRows();
3241
+ var errors = [];
3242
+ rows.forEach(function (row, index) {
3243
+ for (var field in columns) {
3244
+ var column = columns[field];
3245
+ if (!_this19.isRequiredColumn(column)) continue;
3246
+ var value = row[field];
3247
+ var empty = isEmpty(value) || isArray(value) && !value.length || isEmptyObject(value);
3248
+ if (!empty) continue;
3249
+ var caption = column.cShowCaption || column.cCaption || column.cCaption || column.title || field;
3250
+ errors.push({
3251
+ rowIndex: index,
3252
+ rowId: row[_this19.getIdFlag()],
3253
+ cellName: field,
3254
+ message: "".concat(caption, "\u4E0D\u80FD\u4E3A\u7A7A")
3255
+ });
3256
+ _this19.setCellState(index, field, 'msg', '不能为空');
3257
+ }
3258
+ });
3259
+ this._set_data('validateErrors', errors);
3260
+ var message = errors.length ? errors[0].message : '';
3261
+ this.doPropertyChange('validate', {
3262
+ type: errors.length ? 'error' : '',
3263
+ message: message,
3264
+ errors: errors
3265
+ });
3266
+ this.execute('afterValidate', {
3267
+ valid: !errors.length,
3268
+ errors: errors
3269
+ });
3270
+ return !errors.length;
3271
+ }
3272
+ }]);
3273
+ }(BaseModel);
3274
+
3275
+ var ViewModel = /*#__PURE__*/function (_BaseModel) {
3276
+ function ViewModel() {
3277
+ _classCallCheck(this, ViewModel);
3278
+ return _callSuper(this, ViewModel, arguments);
3279
+ }
3280
+ _inherits(ViewModel, _BaseModel);
3281
+ return _createClass(ViewModel, [{
3282
+ key: "getParams",
3283
+ value: function getParams() {
3284
+ return this._get_data('params');
3285
+ }
3286
+ }, {
3287
+ key: "setParams",
3288
+ value: function setParams(params) {
3289
+ this._set_data('params', params, true);
3290
+ }
3291
+ }, {
3292
+ key: "set",
3293
+ value: function set(propertyName, value) {
3294
+ if (value instanceof BaseModel) {
3295
+ value.setParent(this);
3296
+ value.setName(propertyName);
3297
+ }
3298
+ this._set_data(propertyName, value, true);
3299
+ }
3300
+ }, {
3301
+ key: "setData",
3302
+ value: function setData(data) {
3303
+ for (var propertyName in data) {
3304
+ this.addProperty(propertyName, data[propertyName]);
3305
+ }
3306
+ }
3307
+ }, {
3308
+ key: "addProperty",
3309
+ value: function addProperty(propertyName, value) {
3310
+ var property = this.get(propertyName);
3311
+ if (property !== null && property !== void 0 && property.setData) {
3312
+ property.setData(value);
3313
+ } else {
3314
+ this.set(propertyName, value);
3315
+ }
3316
+ }
3317
+ }, {
3318
+ key: "getData",
3319
+ value: function getData() {
3320
+ var _this = this;
3321
+ var propertyNames = this._get_data('propertyNames') || [];
3322
+ var data = {};
3323
+ propertyNames.forEach(function (propertyName) {
3324
+ var property = _this.get(propertyName);
3325
+ if (property instanceof BaseModel && property._get_data('needCollect') !== false) {
3326
+ var _property$getData;
3327
+ data[propertyName] = (_property$getData = property.getData) === null || _property$getData === void 0 ? void 0 : _property$getData.call(property);
3328
+ }
3329
+ });
3330
+ return data;
3331
+ }
3332
+
3333
+ /**
3334
+ * 收集全部属性数据
3335
+ * @param withOutGrid 为 true 时跳过标记了 isGrid 的子模型(子表格)
3336
+ */
3337
+ }, {
3338
+ key: "getAllData",
3339
+ value: function getAllData(withOutGrid) {
3340
+ var _this2 = this;
3341
+ var propertyNames = this._get_data('propertyNames') || [];
3342
+ var rawData = {};
3343
+ propertyNames.forEach(function (propertyName) {
3344
+ var _property$getData2;
3345
+ var property = _this2.get(propertyName);
3346
+ if (!(property instanceof BaseModel) || property._get_data('needCollect') === false) {
3347
+ return;
3348
+ }
3349
+ if (withOutGrid && property._get_data('isGrid')) {
3350
+ return;
3351
+ }
3352
+ var value = (_property$getData2 = property.getData) === null || _property$getData2 === void 0 ? void 0 : _property$getData2.call(property);
3353
+ if (value !== undefined) {
3354
+ rawData[propertyName] = value;
3355
+ }
3356
+ });
3357
+ return rawData;
3358
+ }
3359
+ }, {
3360
+ key: "removeProperty",
3361
+ value: function removeProperty(propertyName) {
3362
+ var propertyNames = this._get_data('propertyNames') || [];
3363
+ var index = propertyNames.indexOf(propertyName);
3364
+ if (index !== -1) {
3365
+ propertyNames.splice(index, 1);
3366
+ }
3367
+ this._del_data(propertyName);
3368
+ }
3369
+ }, {
3370
+ key: "loadData",
3371
+ value: function loadData(data) {
3372
+ this.setCache('isLoadData', true);
3373
+ this.clear();
3374
+ this.setData(data);
3375
+ this.setDirty(false);
3376
+ this.setCache('isLoadData', false);
3377
+ }
3378
+ }, {
3379
+ key: "clear",
3380
+ value: function clear(useDefault) {
3381
+ var _this3 = this;
3382
+ var propertyNames = this._get_data('propertyNames') || [];
3383
+ propertyNames.forEach(function (propertyName) {
3384
+ var property = _this3.get(propertyName);
3385
+ if (property instanceof BaseModel && property._get_data('needClear') !== false) {
3386
+ var _property$clear;
3387
+ (_property$clear = property.clear) === null || _property$clear === void 0 || _property$clear.call(property, useDefault);
3388
+ }
3389
+ });
3390
+ }
3391
+ }, {
3392
+ key: "setDirty",
3393
+ value: function setDirty(dirty) {
3394
+ if (dirty) {
3395
+ this._set_data('isDirty', true);
3396
+ return;
3397
+ }
3398
+ this._del_data('isDirty');
3399
+ this._set_data('originalData', this.getData());
3400
+ }
3401
+ }, {
3402
+ key: "getGridModel",
3403
+ value: function getGridModel(propertyName) {
3404
+ var _this$getParams;
3405
+ if (propertyName) {
3406
+ return this.get(propertyName);
3407
+ }
3408
+ var gridModel = this._get_data('gridModel');
3409
+ if (gridModel) {
3410
+ return gridModel;
3411
+ }
3412
+ var masterGridModelName = (_this$getParams = this.getParams()) === null || _this$getParams === void 0 ? void 0 : _this$getParams.masterGridModelName;
3413
+ if (masterGridModelName) {
3414
+ return this.get(masterGridModelName);
3415
+ }
3416
+ var propertyNames = this._get_data('propertyNames');
3417
+ for (var i = 0, len = propertyNames.length; i < len; i++) {
3418
+ gridModel = this.get(propertyNames[i]);
3419
+ var isGridModel = gridModel instanceof GridModel;
3420
+ if (isGridModel) {
3421
+ this._set_data('gridModel', gridModel);
3422
+ return gridModel;
3423
+ }
3424
+ }
3425
+ }
3426
+ }, {
3427
+ key: "getGridModels",
3428
+ value: function getGridModels() {
3429
+ var propertyNames = this._get_data('propertyNames');
3430
+ var gridModels = [];
3431
+ for (var i = 0, len = propertyNames.length; i < len; i++) {
3432
+ var gridModel = this.get(propertyNames[i]);
3433
+ if (gridModel instanceof GridModel) {
3434
+ gridModels.push(gridModel);
3435
+ }
3436
+ }
3437
+ return gridModels;
3438
+ }
3439
+ }]);
3440
+ }(BaseModel);
3441
+
3442
+ function createModelFactory(props) {
3443
+ var cControlType = props.cControlType.toLowerCase();
3444
+ var model;
3445
+ switch (cControlType) {
3446
+ case 'input':
3447
+ model = new SimpleModel(props);
3448
+ break;
3449
+ }
3450
+ return model;
3451
+ }
3452
+ function createViewModel(meta, params) {
3453
+ var _window$devfab;
3454
+ var _require = (_window$devfab = window.devfab) === null || _window$devfab === void 0 ? void 0 : _window$devfab.require;
3455
+ var _ref = params || {},
3456
+ _ref$domainKeyField = _ref.domainKeyField,
3457
+ domainKeyField = _ref$domainKeyField === void 0 ? 'domainKey' : _ref$domainKeyField,
3458
+ _ref$billNoField = _ref.billNoField,
3459
+ billNoField = _ref$billNoField === void 0 ? 'billNo' : _ref$billNoField,
3460
+ _ref$modelNameField = _ref.modelNameField,
3461
+ modelNameField = _ref$modelNameField === void 0 ? 'modelName' : _ref$modelNameField,
3462
+ _ref$enableExtendjs = _ref.enableExtendjs,
3463
+ enableExtendjs = _ref$enableExtendjs === void 0 ? true : _ref$enableExtendjs;
3464
+ if (params !== null && params !== void 0 && params.require) {
3465
+ _require = params === null || params === void 0 ? void 0 : params.require;
3466
+ }
3467
+ var domainKey = meta[domainKeyField] || '';
3468
+ var billno = meta[billNoField];
3469
+ var VM = /*#__PURE__*/function (_ViewModel) {
3470
+ function VM() {
3471
+ _classCallCheck(this, VM);
3472
+ return _callSuper(this, VM, arguments);
3473
+ }
3474
+ _inherits(VM, _ViewModel);
3475
+ return _createClass(VM, [{
3476
+ key: "init",
3477
+ value: function init(_models, meta) {
3478
+ var fields = this.createModels(_models, meta);
3479
+ this.setData(fields);
3480
+ this.setDirty(false);
3481
+ }
3482
+ }, {
3483
+ key: "createModels",
3484
+ value: function createModels(_models, meta) {
3485
+ var fields = {};
3486
+ var models = Array.isArray(_models) ? _models : [];
3487
+ models.forEach(function (m) {
3488
+ var _params$createModelFa, _params$onBeforeCreat;
3489
+ var model = params === null || params === void 0 || (_params$createModelFa = params.createModelFactory) === null || _params$createModelFa === void 0 ? void 0 : _params$createModelFa.call(params, m);
3490
+ if (!model) {
3491
+ model = createModelFactory(m);
3492
+ }
3493
+ var param = {
3494
+ model: model,
3495
+ field: m,
3496
+ meta: meta
3497
+ };
3498
+ params === null || params === void 0 || (_params$onBeforeCreat = params.onBeforeCreateModel) === null || _params$onBeforeCreat === void 0 || _params$onBeforeCreat.call(params, param);
3499
+ fields[m[modelNameField]] = param.model;
3500
+ });
3501
+ return fields;
3502
+ }
3503
+ }, {
3504
+ key: "initData",
3505
+ value: function initData() {
3506
+ this.initExtendJs();
3507
+ }
3508
+ }, {
3509
+ key: "initExtendJs",
3510
+ value: function initExtendJs() {
3511
+ if (window && window.__debugger_initExtendJs) {
3512
+ // eslint-disable-next-line no-debugger
3513
+ debugger;
3514
+ }
3515
+ var self = this;
3516
+ if (!enableExtendjs) {
3517
+ self.execute('extendReady', self);
3518
+ return;
3519
+ }
3520
+ var extendFile = "".concat(billno, "_VM.Extend.js");
3521
+ var extendFiles = [extendFile];
3522
+ // if (self.getEnv && self.getEnv('everyCommonExtend')) {
3523
+ // extendFiles.push(self.getEnv('everyCommonExtend'))
3524
+ // }
3525
+ if (typeof _require !== 'function') {
3526
+ console.warn("requirejs.js \u672A\u52A0\u8F7D\uFF0C\u8DF3\u8FC7\u6269\u5C55\u811A\u672C\uFF1A".concat(extendFile));
3527
+ self.execute('extendReady', self);
3528
+ return;
3529
+ }
3530
+ _require(domainKey, extendFiles, function (extend, everyCommonExtend) {
3531
+ if (extend && extend.doAction) {
3532
+ // 处理扩展脚本异常导致渲染失败
3533
+ try {
3534
+ extend.doAction('init', self);
3535
+ if (everyCommonExtend) {
3536
+ everyCommonExtend.doAction('init', self);
3537
+ }
3538
+ } catch (err) {
3539
+ console.error('扩展脚本异常:', err);
3540
+ }
3541
+ } else {
3542
+ console.error("".concat(extendFile, "\u6269\u5C55\u6587\u4EF6extend.*.min.js\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25 \u6216 \u672A\u6CE8\u518C\u6269\u5C55\u811A\u672C"));
3543
+ }
3544
+ self.execute('extendReady', self);
3545
+ }, function (err) {
3546
+ console.warn("\u672A\u627E\u5230\u6269\u5C55\u811A\u672C\uFF1A".concat(extendFile, "\u9519\u8BEF\u4FE1\u606F\uFF1A"), err);
3547
+ self.execute('extendReady', self);
3548
+ });
3549
+ }
3550
+ }]);
3551
+ }(ViewModel);
3552
+ VM.prototype.modelType = 'ViewModel';
3553
+ return VM;
3554
+ }
3555
+ function initViewModel(meta, params) {
3556
+ var ContainerModel = createViewModel(meta, params);
3557
+ var vm = new ContainerModel();
3558
+ vm.init(meta.models, meta);
3559
+ return vm;
3560
+ }
3561
+ var models = {
3562
+ BaseModel: BaseModel,
3563
+ FilterModel: FilterModel,
3564
+ SimpleModel: SimpleModel,
3565
+ GridModel: GridModel,
3566
+ ViewModel: ViewModel,
3567
+ createViewModel: createViewModel,
3568
+ initViewModel: initViewModel
3569
+ };
3570
+
3571
+ window.__ASYNC_EXECUTE__ = true;
3572
+ var devfab = {
3573
+ builder: new Builder(),
3574
+ utils: {
3575
+ cache: new CacheUtil(),
3576
+ event: new EventUtil(),
3577
+ models: models
3578
+ }
3579
+ };
3580
+
3581
+ exports["default"] = devfab;
3582
+
3583
+ Object.defineProperty(exports, '__esModule', { value: true });
3584
+
3585
+ }));