@byteluck-fe/model-driven-engine 2.5.0-alpha.9 → 2.5.0-beta.1

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.
Files changed (33) hide show
  1. package/dist/esm/common/ActionManager.js +63 -98
  2. package/dist/esm/common/DataManager.js +34 -75
  3. package/dist/esm/common/Engine.js +931 -1100
  4. package/dist/esm/common/OkWorker.js +74 -119
  5. package/dist/esm/common/Runtime.js +21 -38
  6. package/dist/esm/common/Store.js +141 -152
  7. package/dist/esm/common/checkerValue.js +241 -316
  8. package/dist/esm/plugins/CalcPlugin.js +309 -389
  9. package/dist/esm/plugins/ControlsEventPlugin.js +130 -169
  10. package/dist/esm/plugins/ES6ModulePlugin.js +31 -65
  11. package/dist/esm/plugins/LifecycleEventPlugin.js +83 -119
  12. package/dist/esm/plugins/StylePlugin.js +13 -46
  13. package/dist/index.umd.js +8 -8
  14. package/dist/types/common/ActionManager.d.ts +14 -14
  15. package/dist/types/common/DataManager.d.ts +10 -10
  16. package/dist/types/common/Engine.d.ts +180 -180
  17. package/dist/types/common/OkWorker.d.ts +13 -13
  18. package/dist/types/common/Plugin.d.ts +6 -6
  19. package/dist/types/common/Runtime.d.ts +25 -25
  20. package/dist/types/common/Store.d.ts +50 -49
  21. package/dist/types/common/checkerValue.d.ts +3 -3
  22. package/dist/types/common/index.d.ts +2 -2
  23. package/dist/types/common/proxyState.d.ts +30 -30
  24. package/dist/types/index.d.ts +3 -3
  25. package/dist/types/plugins/CalcPlugin.d.ts +121 -121
  26. package/dist/types/plugins/ControlsEventPlugin.d.ts +15 -15
  27. package/dist/types/plugins/ES6ModulePlugin.d.ts +26 -26
  28. package/dist/types/plugins/LifecycleEventPlugin.d.ts +14 -14
  29. package/dist/types/plugins/StylePlugin.d.ts +12 -12
  30. package/dist/types/plugins/index.d.ts +5 -5
  31. package/dist/types/utils/index.d.ts +1 -1
  32. package/dist/types/utils/runtimeUtils.d.ts +5 -5
  33. package/package.json +4 -4
@@ -11,33 +11,6 @@ function _classCallCheck(instance, Constructor) {
11
11
  throw new TypeError("Cannot call a class as a function");
12
12
  }
13
13
  }
14
- function _defineProperties(target, props) {
15
- for(var i = 0; i < props.length; i++){
16
- var descriptor = props[i];
17
- descriptor.enumerable = descriptor.enumerable || false;
18
- descriptor.configurable = true;
19
- if ("value" in descriptor) descriptor.writable = true;
20
- Object.defineProperty(target, descriptor.key, descriptor);
21
- }
22
- }
23
- function _createClass(Constructor, protoProps, staticProps) {
24
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
- if (staticProps) _defineProperties(Constructor, staticProps);
26
- return Constructor;
27
- }
28
- function _defineProperty(obj, key, value) {
29
- if (key in obj) {
30
- Object.defineProperty(obj, key, {
31
- value: value,
32
- enumerable: true,
33
- configurable: true,
34
- writable: true
35
- });
36
- } else {
37
- obj[key] = value;
38
- }
39
- return obj;
40
- }
41
14
  function _iterableToArray(iter) {
42
15
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
16
  }
@@ -70,413 +43,360 @@ export var CalcPlugin = /*#__PURE__*/ function() {
70
43
  "use strict";
71
44
  function CalcPlugin(options) {
72
45
  _classCallCheck(this, CalcPlugin);
73
- _defineProperty(this, "engine", void 0);
74
- _defineProperty(this, "options", void 0);
75
46
  /**
76
47
  * 所有的计算公式控件
77
48
  * */ // @ts-ignore
78
- _defineProperty(this, "calcControls", []);
49
+ this.calcControls = [];
79
50
  /**
80
51
  * key=控件id value=控件修改后需要触发重新计算的计算公式控件组成的数组
81
52
  * 存储为一个Map,用于在控件change的时候,重新计算依赖的calc
82
- * */ _defineProperty(this, "dependenciesTriggerMap", new Map());
53
+ * */ this.dependenciesTriggerMap = new Map();
83
54
  /**
84
55
  * 隐藏以后需要被计算的控件
85
- * */ _defineProperty(this, "hideNotRememberControlIds", []);
86
- _defineProperty(this, "dontHasPermissionControlIds", []);
87
- _defineProperty(this, "cacheComputedResult", {});
56
+ * */ this.hideNotRememberControlIds = [];
57
+ this.dontHasPermissionControlIds = [];
58
+ this.cacheComputedResult = {};
88
59
  this.options = options;
89
60
  this.getDontHasPermissionControlIds();
90
61
  this.getNeedHideRememberControlIds();
91
62
  }
92
- _createClass(CalcPlugin, [
93
- {
94
- key: "getNeedHideRememberControlIds",
95
- value: /**
63
+ var _proto = CalcPlugin.prototype;
64
+ /**
96
65
  * @description 获取显隐控制的需要被记住值的控件id
97
- * */ function getNeedHideRememberControlIds() {
98
- var _this_options;
99
- if (!((_this_options = this.options) === null || _this_options === void 0 ? void 0 : _this_options.displayBoList)) {
100
- return;
101
- }
102
- this.hideNotRememberControlIds = this.options.displayBoList.reduce(function(result, current) {
103
- if (!current.is_remember) {
104
- var _result;
105
- (_result = result).push.apply(_result, _toConsumableArray(current.hide_controls));
106
- }
107
- return result;
108
- }, []);
66
+ * */ _proto.getNeedHideRememberControlIds = function getNeedHideRememberControlIds() {
67
+ var _this_options;
68
+ if (!((_this_options = this.options) === null || _this_options === void 0 ? void 0 : _this_options.displayBoList)) {
69
+ return;
70
+ }
71
+ this.hideNotRememberControlIds = this.options.displayBoList.reduce(function(result, current) {
72
+ if (!current.is_remember) {
73
+ var _result;
74
+ (_result = result).push.apply(_result, _toConsumableArray(current.hide_controls));
109
75
  }
110
- },
111
- {
112
- key: "getDontHasPermissionControlIds",
113
- value: /**
76
+ return result;
77
+ }, []);
78
+ };
79
+ /**
114
80
  * @description 获取权限控制的隐藏的字段,不需要参与计算
115
- * */ function getDontHasPermissionControlIds() {
116
- var _this_options;
117
- if (!((_this_options = this.options) === null || _this_options === void 0 ? void 0 : _this_options.behavior)) {
118
- return;
119
- }
120
- this.dontHasPermissionControlIds = this.options.behavior.reduce(function(result, current) {
121
- if (current.ctrlBehavior === 1) {
122
- result.push(current.ctrlId);
123
- }
124
- return result;
125
- }, []);
81
+ * */ _proto.getDontHasPermissionControlIds = function getDontHasPermissionControlIds() {
82
+ var _this_options;
83
+ if (!((_this_options = this.options) === null || _this_options === void 0 ? void 0 : _this_options.behavior)) {
84
+ return;
85
+ }
86
+ this.dontHasPermissionControlIds = this.options.behavior.reduce(function(result, current) {
87
+ if (current.ctrlBehavior === 1) {
88
+ result.push(current.ctrlId);
126
89
  }
127
- },
128
- {
129
- key: "controlNeedComputedValue",
130
- value: /**
90
+ return result;
91
+ }, []);
92
+ };
93
+ /**
131
94
  * @description 判断控件是否需要被计算
132
95
  * @param control 控件
133
- * */ function controlNeedComputedValue(control) {
134
- if (!control) {
135
- return false;
136
- }
137
- var isHide = this.getControlIsHide(control);
138
- // 权限控制的控件隐藏,并且控件已经隐藏了(不需要知道是否记住值,统一不计算,这个逻辑前置是因为可能存在显隐控制的,需要记住值,但是被权限控制隐藏的字段,这种情况下权限控制权重最高)
139
- if (this.dontHasPermissionControlIds.includes(control.id) && isHide) {
140
- return false;
141
- }
142
- // 被显隐控制的且不需要记住值,并且控件已经隐藏了(控件已经隐藏以后,因为不需要记住值,所以一律不计算)
143
- if (this.hideNotRememberControlIds.includes(control.id) && isHide) {
144
- return false;
145
- }
146
- // 其余都计算
147
- return true;
148
- }
149
- },
150
- {
151
- key: "getControlIsHide",
152
- value: /**
96
+ * */ _proto.controlNeedComputedValue = function controlNeedComputedValue(control) {
97
+ if (!control) {
98
+ return false;
99
+ }
100
+ var isHide = this.getControlIsHide(control);
101
+ // 权限控制的控件隐藏,并且控件已经隐藏了(不需要知道是否记住值,统一不计算,这个逻辑前置是因为可能存在显隐控制的,需要记住值,但是被权限控制隐藏的字段,这种情况下权限控制权重最高)
102
+ if (this.dontHasPermissionControlIds.includes(control.id) && isHide) {
103
+ return false;
104
+ }
105
+ // 被显隐控制的且不需要记住值,并且控件已经隐藏了(控件已经隐藏以后,因为不需要记住值,所以一律不计算)
106
+ if (this.hideNotRememberControlIds.includes(control.id) && isHide) {
107
+ return false;
108
+ }
109
+ // 其余都计算
110
+ return true;
111
+ };
112
+ /**
153
113
  * @description 获取控件是否被隐藏
154
114
  * @param control 控件
155
- * */ function getControlIsHide(control) {
156
- if (control.props.isHide) {
157
- return true;
158
- }
159
- if (control.parent === null) {
160
- return false;
161
- }
162
- return this.getControlIsHide(control.parent);
163
- }
164
- },
165
- {
166
- key: "apply",
167
- value: function apply(engine) {
168
- var _this = this;
169
- this.engine = engine;
170
- this.resetDependencies();
171
- this.watchControlChange();
172
- this.watchSubtableChange();
173
- this.watchSchemaHideChange();
174
- this.engine.on("engine-mounted", function() {
175
- _this.allCalcControlComputed();
176
- });
177
- }
178
- },
179
- {
180
- key: "resetDependencies",
181
- value: /**
115
+ * */ _proto.getControlIsHide = function getControlIsHide(control) {
116
+ if (control.props.isHide) {
117
+ return true;
118
+ }
119
+ if (control.parent === null) {
120
+ return false;
121
+ }
122
+ return this.getControlIsHide(control.parent);
123
+ };
124
+ _proto.apply = function apply(engine) {
125
+ var _this = this;
126
+ this.engine = engine;
127
+ this.resetDependencies();
128
+ this.watchControlChange();
129
+ this.watchSubtableChange();
130
+ this.watchSchemaHideChange();
131
+ this.engine.on("engine-mounted", function() {
132
+ _this.allCalcControlComputed();
133
+ });
134
+ };
135
+ /**
182
136
  * @description 重置依赖,获取所有的计算公式控件,并根据计算公式获取控件依赖关系
183
- * */ function resetDependencies() {
184
- this.calcControls = [];
185
- this.dependenciesTriggerMap.clear();
186
- this.getAllCalcControl();
187
- this.getCalcDependencies();
188
- }
189
- },
190
- {
191
- key: "allCalcControlComputed",
192
- value: /**
137
+ * */ _proto.resetDependencies = function resetDependencies() {
138
+ this.calcControls = [];
139
+ this.dependenciesTriggerMap.clear();
140
+ this.getAllCalcControl();
141
+ this.getCalcDependencies();
142
+ };
143
+ /**
193
144
  * @description 执行所有计算公式控件的计算
194
- * */ function allCalcControlComputed() {
195
- var _this = this;
196
- this.calcControls.forEach(function(item) {
197
- return _this.computedCalcValue(item);
198
- });
199
- }
200
- },
201
- {
202
- key: "getAllCalcControl",
203
- value: /**
145
+ * */ _proto.allCalcControlComputed = function allCalcControlComputed() {
146
+ var _this = this;
147
+ this.calcControls.forEach(function(item) {
148
+ return _this.computedCalcValue(item);
149
+ });
150
+ };
151
+ /**
204
152
  * @description 获取所有的计算公式控件
205
- * */ function getAllCalcControl() {
206
- this.calcControls = this.engine.runtime.flatInstances.filter(// @ts-ignore
207
- function(item) {
208
- return item.type === CONTROL_TYPE.CALC;
209
- });
210
- }
211
- },
212
- {
213
- key: "getCalcDependencies",
214
- value: /**
153
+ * */ _proto.getAllCalcControl = function getAllCalcControl() {
154
+ this.calcControls = this.engine.runtime.flatInstances.filter(// @ts-ignore
155
+ function(item) {
156
+ return item.type === CONTROL_TYPE.CALC;
157
+ });
158
+ };
159
+ /**
215
160
  * @description 获取计算公式控件依赖,组成 依赖=>[计算公式] 的Map结构
216
- * */ function getCalcDependencies() {
217
- var _this = this;
218
- this.calcControls.forEach(function(item) {
219
- var scriptEcho = item.props.scriptEcho;
220
- scriptEcho.forEach(function(scriptItem) {
221
- if (scriptItem.type === CALC_TOKEN_TYPE.VariableInMainTable || scriptItem.type === CALC_TOKEN_TYPE.VariableInCurrentSubTable || scriptItem.type === CALC_TOKEN_TYPE.VariableInOtherSubTable) {
222
- // 当前是一个变量,存储依赖于当前变量的计算公式
223
- _this.setDependenciesTriggerMapItem(scriptItem.id, item);
224
- }
225
- // 依赖明细子表的计算公式控件,不收集自己表内的,而是主表或者其他明细子表的控件
226
- if (scriptItem.type === CALC_TOKEN_TYPE.VariableInOtherSubTable && scriptItem.subTableId) {
227
- _this.setDependenciesTriggerMapItem(scriptItem.subTableId, item);
228
- }
229
- });
230
- });
231
- }
232
- },
233
- {
234
- key: "setDependenciesTriggerMapItem",
235
- value: function setDependenciesTriggerMapItem(id, // @ts-ignore
236
- item) {
237
- if (!this.dependenciesTriggerMap.has(id)) {
238
- this.dependenciesTriggerMap.set(id, []);
161
+ * */ _proto.getCalcDependencies = function getCalcDependencies() {
162
+ var _this = this;
163
+ this.calcControls.forEach(function(item) {
164
+ var scriptEcho = item.props.scriptEcho;
165
+ scriptEcho.forEach(function(scriptItem) {
166
+ if (scriptItem.type === CALC_TOKEN_TYPE.VariableInMainTable || scriptItem.type === CALC_TOKEN_TYPE.VariableInCurrentSubTable || scriptItem.type === CALC_TOKEN_TYPE.VariableInOtherSubTable) {
167
+ // 当前是一个变量,存储依赖于当前变量的计算公式
168
+ _this.setDependenciesTriggerMapItem(scriptItem.id, item);
239
169
  }
240
- var arr = this.dependenciesTriggerMap.get(id);
241
- if (!arr.includes(item)) {
242
- arr.push(item);
170
+ // 依赖明细子表的计算公式控件,不收集自己表内的,而是主表或者其他明细子表的控件
171
+ if (scriptItem.type === CALC_TOKEN_TYPE.VariableInOtherSubTable && scriptItem.subTableId) {
172
+ _this.setDependenciesTriggerMapItem(scriptItem.subTableId, item);
243
173
  }
244
- }
245
- },
246
- {
247
- key: "getCalcControlsFromSubtableRows",
248
- value: function getCalcControlsFromSubtableRows(// @ts-ignore
249
- subtableRows) {
250
- var _this = this;
251
- return subtableRows.reduce(function(result, current) {
252
- // @ts-ignore
253
- current.children.forEach(function(item) {
254
- var control = item.children[0];
255
- // @ts-ignore
256
- if (control && _this.engine.assertInstance(control, CONTROL_TYPE.CALC)) {
257
- result.push(control);
258
- }
259
- });
260
- return result;
174
+ });
175
+ });
176
+ };
177
+ _proto.setDependenciesTriggerMapItem = function setDependenciesTriggerMapItem(id, // @ts-ignore
178
+ item) {
179
+ if (!this.dependenciesTriggerMap.has(id)) {
180
+ this.dependenciesTriggerMap.set(id, []);
181
+ }
182
+ var arr = this.dependenciesTriggerMap.get(id);
183
+ if (!arr.includes(item)) {
184
+ arr.push(item);
185
+ }
186
+ };
187
+ _proto.getCalcControlsFromSubtableRows = function getCalcControlsFromSubtableRows(// @ts-ignore
188
+ subtableRows) {
189
+ var _this = this;
190
+ return subtableRows.reduce(function(result, current) {
191
+ // @ts-ignore
192
+ current.children.forEach(function(item) {
193
+ var control = item.children[0];
261
194
  // @ts-ignore
262
- }, []);
263
- }
264
- },
265
- {
266
- key: "watchSchemaHideChange",
267
- value: /**
195
+ if (control && _this.engine.assertInstance(control, CONTROL_TYPE.CALC)) {
196
+ result.push(control);
197
+ }
198
+ });
199
+ return result;
200
+ // @ts-ignore
201
+ }, []);
202
+ };
203
+ /**
268
204
  * @description 监听控件的显隐事件,把显隐会影响的控件触发一遍计算
269
- * */ function watchSchemaHideChange() {
270
- var _this = this;
271
- this.engine.on("schema-change", function(payload) {
272
- if (payload.props === "isHide") {
273
- var _this_dependenciesTriggerMap_get;
274
- var calcControls = (_this_dependenciesTriggerMap_get = _this.dependenciesTriggerMap.get(payload.instance.id)) !== null && _this_dependenciesTriggerMap_get !== void 0 ? _this_dependenciesTriggerMap_get : [];
275
- calcControls.forEach(function(calc) {
276
- _this.computedCalcValue(calc);
277
- });
278
- }
205
+ * */ _proto.watchSchemaHideChange = function watchSchemaHideChange() {
206
+ var _this = this;
207
+ this.engine.on("schema-change", function(payload) {
208
+ if (payload.props === "isHide") {
209
+ var _this_dependenciesTriggerMap_get;
210
+ var calcControls = (_this_dependenciesTriggerMap_get = _this.dependenciesTriggerMap.get(payload.instance.id)) !== null && _this_dependenciesTriggerMap_get !== void 0 ? _this_dependenciesTriggerMap_get : [];
211
+ calcControls.forEach(function(calc) {
212
+ _this.computedCalcValue(calc);
279
213
  });
280
214
  }
281
- },
282
- {
283
- key: "watchSubtableChange",
284
- value: /**
215
+ });
216
+ };
217
+ /**
285
218
  * @description 监听明细子表的change事件,把明细表会影响的控件触发一遍计算
286
- * */ function watchSubtableChange() {
287
- var _this = this;
288
- this.engine.on("list-change", function(payload) {
289
- var _payload_options;
290
- _this.resetDependencies();
291
- var _payload_options_changed;
292
- var changedRows = (_payload_options_changed = (_payload_options = payload.options) === null || _payload_options === void 0 ? void 0 : _payload_options.changed) !== null && _payload_options_changed !== void 0 ? _payload_options_changed : [];
293
- // 对发生改变的行进行重新计算
294
- var changedCalc = _this.getCalcControlsFromSubtableRows(changedRows);
295
- // @ts-ignore
296
- changedCalc.forEach(function(calcControl) {
297
- _this.computedCalcValue(calcControl);
298
- });
299
- var _this_dependenciesTriggerMap_get;
300
- var calcControls = (_this_dependenciesTriggerMap_get = _this.dependenciesTriggerMap.get(payload.instance.id)) !== null && _this_dependenciesTriggerMap_get !== void 0 ? _this_dependenciesTriggerMap_get : [];
301
- // @ts-ignore
302
- calcControls.forEach(function(calcControl) {
303
- _this.computedCalcValue(calcControl);
304
- });
305
- });
306
- }
307
- },
308
- {
309
- key: "watchControlChange",
310
- value: /**
219
+ * */ _proto.watchSubtableChange = function watchSubtableChange() {
220
+ var _this = this;
221
+ this.engine.on("list-change", function(payload) {
222
+ var _payload_options;
223
+ _this.resetDependencies();
224
+ var _payload_options_changed;
225
+ var changedRows = (_payload_options_changed = (_payload_options = payload.options) === null || _payload_options === void 0 ? void 0 : _payload_options.changed) !== null && _payload_options_changed !== void 0 ? _payload_options_changed : [];
226
+ // 对发生改变的行进行重新计算
227
+ var changedCalc = _this.getCalcControlsFromSubtableRows(changedRows);
228
+ // @ts-ignore
229
+ changedCalc.forEach(function(calcControl) {
230
+ _this.computedCalcValue(calcControl);
231
+ });
232
+ var _this_dependenciesTriggerMap_get;
233
+ var calcControls = (_this_dependenciesTriggerMap_get = _this.dependenciesTriggerMap.get(payload.instance.id)) !== null && _this_dependenciesTriggerMap_get !== void 0 ? _this_dependenciesTriggerMap_get : [];
234
+ // @ts-ignore
235
+ calcControls.forEach(function(calcControl) {
236
+ _this.computedCalcValue(calcControl);
237
+ });
238
+ });
239
+ };
240
+ /**
311
241
  * @description 监听控件的change事件,当控件change的时候,取到控件会影响的计算公式,然后执行对应的计算
312
- * */ function watchControlChange() {
313
- var _this = this;
314
- this.engine.on("change", function(payload) {
315
- var instance = payload.instance;
316
- if (!_this.dependenciesTriggerMap.has(instance.id)) {
317
- return;
318
- }
319
- var _this_dependenciesTriggerMap_get;
320
- var calcControls = (_this_dependenciesTriggerMap_get = _this.dependenciesTriggerMap.get(instance.id)) !== null && _this_dependenciesTriggerMap_get !== void 0 ? _this_dependenciesTriggerMap_get : [];
321
- // 在明细子表中的控件,如果计算公式也在明细子表,那只触发同一行的计算公式的计算
322
- if (payload.rowIndex !== undefined && payload.rowIndex > -1) {
323
- // @ts-ignore
324
- calcControls.forEach(function(calcControl) {
325
- if (_this.controlInSubtable(calcControl)) {
326
- var calcIndex = _this.engine.getInstanceRowIndex(calcControl);
327
- if (calcIndex !== payload.rowIndex) {
328
- return;
329
- }
330
- }
331
- _this.computedCalcValue(calcControl);
332
- });
333
- } else {
334
- // @ts-ignore
335
- calcControls.forEach(function(calcControl) {
336
- _this.computedCalcValue(calcControl);
337
- });
242
+ * */ _proto.watchControlChange = function watchControlChange() {
243
+ var _this = this;
244
+ this.engine.on("change", function(payload) {
245
+ var instance = payload.instance;
246
+ if (!_this.dependenciesTriggerMap.has(instance.id)) {
247
+ return;
248
+ }
249
+ var _this_dependenciesTriggerMap_get;
250
+ var calcControls = (_this_dependenciesTriggerMap_get = _this.dependenciesTriggerMap.get(instance.id)) !== null && _this_dependenciesTriggerMap_get !== void 0 ? _this_dependenciesTriggerMap_get : [];
251
+ // 在明细子表中的控件,如果计算公式也在明细子表,那只触发同一行的计算公式的计算
252
+ if (payload.rowIndex !== undefined && payload.rowIndex > -1) {
253
+ // @ts-ignore
254
+ calcControls.forEach(function(calcControl) {
255
+ if (_this.controlInSubtable(calcControl)) {
256
+ var calcIndex = _this.engine.getInstanceRowIndex(calcControl);
257
+ if (calcIndex !== payload.rowIndex) {
258
+ return;
259
+ }
338
260
  }
261
+ _this.computedCalcValue(calcControl);
262
+ });
263
+ } else {
264
+ // @ts-ignore
265
+ calcControls.forEach(function(calcControl) {
266
+ _this.computedCalcValue(calcControl);
339
267
  });
340
268
  }
341
- },
342
- {
343
- key: "controlInSubtable",
344
- value: /**
269
+ });
270
+ };
271
+ /**
345
272
  * @description 控件在明细子表内
346
- * */ function controlInSubtable(control) {
347
- var _control_parent;
348
- return ((_control_parent = control.parent) === null || _control_parent === void 0 ? void 0 : _control_parent.type) === CONTROL_TYPE.SUBTABLE_COLUMN;
349
- }
350
- },
351
- {
352
- key: "computedCalcValue",
353
- value: /**
273
+ * */ _proto.controlInSubtable = function controlInSubtable(control) {
274
+ var _control_parent;
275
+ return ((_control_parent = control.parent) === null || _control_parent === void 0 ? void 0 : _control_parent.type) === CONTROL_TYPE.SUBTABLE_COLUMN;
276
+ };
277
+ /**
354
278
  * @description 执行计算公式的计算
355
279
  * */ // @ts-ignore
356
- function computedCalcValue(control) {
357
- var _this = this;
358
- var scriptEcho = control.props.scriptEcho;
359
- if (!scriptEcho || scriptEcho.length === 0) {
360
- return;
361
- }
362
- // @ts-ignore
363
- var scriptText = scriptEcho.reduce(function(result, current) {
364
- if (current.type === CALC_TOKEN_TYPE.Operator || current.type === CALC_TOKEN_TYPE.Number) {
365
- return result + current.name;
366
- }
367
- var num = 0;
368
- var instance;
369
- switch(current.type){
370
- case CALC_TOKEN_TYPE.VariableInMainTable:
371
- {
372
- var value = _this.getNumberValue(_this.engine.getState(current.id));
373
- instance = _this.engine.getInstance(current.id);
374
- num = Number(value);
375
- break;
376
- }
377
- case CALC_TOKEN_TYPE.VariableInCurrentSubTable:
378
- {
379
- var rowIndex = _this.engine.getInstanceRowIndex(control);
380
- instance = _this.engine.getInstance(current.id, rowIndex);
381
- var state = _this.engine.getState(current.id, rowIndex);
382
- var value1 = _this.getNumberValue(state);
383
- num = Number(value1);
384
- break;
385
- }
386
- case CALC_TOKEN_TYPE.VariableInOtherSubTable:
387
- {
388
- var states = _this.engine.getState(current.id);
389
- var values = Array.isArray(states) ? states.map(function(item) {
390
- return _this.getNumberValue(item);
391
- }) : [];
392
- var value2 = _this.getAggregateTypeValue(values, current.aggregateType);
393
- instance = _this.engine.getInstance(current.subTableId);
394
- num = Number(value2);
395
- break;
396
- }
280
+ _proto.computedCalcValue = function computedCalcValue(control) {
281
+ var _this = this;
282
+ var scriptEcho = control.props.scriptEcho;
283
+ if (!scriptEcho || scriptEcho.length === 0) {
284
+ return;
285
+ }
286
+ var rowIndex = undefined;
287
+ if (this.controlInSubtable(control)) {
288
+ rowIndex = this.engine.getInstanceRowIndex(control);
289
+ }
290
+ // @ts-ignore
291
+ var scriptText = scriptEcho.reduce(function(result, current) {
292
+ if (current.type === CALC_TOKEN_TYPE.Operator || current.type === CALC_TOKEN_TYPE.Number) {
293
+ return result + current.name;
294
+ }
295
+ var num = 0;
296
+ var instance;
297
+ switch(current.type){
298
+ case CALC_TOKEN_TYPE.VariableInMainTable:
299
+ {
300
+ var value = _this.getNumberValue(_this.engine.getState(current.id));
301
+ instance = _this.engine.getInstance(current.id);
302
+ num = Number(value);
303
+ break;
397
304
  }
398
- if (!Number.isNaN(num) && _this.controlNeedComputedValue(instance)) {
399
- // 在每一个数字外边包一个括号,将 --1 转为 -(-1) 确保 --1 这种情况不会出问题
400
- result += "(".concat(num, ")");
401
- } else {
402
- result += 0;
305
+ case CALC_TOKEN_TYPE.VariableInCurrentSubTable:
306
+ {
307
+ //const rowIndex = this.engine.getInstanceRowIndex(control)
308
+ instance = _this.engine.getInstance(current.id, rowIndex);
309
+ var state = _this.engine.getState(current.id, rowIndex);
310
+ var value1 = _this.getNumberValue(state);
311
+ num = Number(value1);
312
+ break;
403
313
  }
404
- return result;
405
- }, "");
406
- var value;
407
- // 有缓存的话取缓存,没有缓存再执行eval
408
- if (this.cacheComputedResult[scriptText] !== undefined) {
409
- value = this.cacheComputedResult[scriptText];
410
- } else {
411
- // 解决js精准度问题
412
- value = Number(format(new Function("return ".concat(scriptText))(), {
413
- precision: 16
414
- }));
415
- this.cacheComputedResult[scriptText] = value;
416
- }
417
- var rowIndex = undefined;
418
- if (this.controlInSubtable(control)) {
419
- rowIndex = this.engine.getInstanceRowIndex(control);
420
- // 控件在明细表内,但是没有行下标,说明控件被已经删除了,所以直接return
421
- if (rowIndex === undefined) {
422
- return;
314
+ case CALC_TOKEN_TYPE.VariableInOtherSubTable:
315
+ {
316
+ var states = _this.engine.getState(current.id);
317
+ var values = Array.isArray(states) ? states.map(function(item) {
318
+ return _this.getNumberValue(item);
319
+ }) : [];
320
+ var value2 = _this.getAggregateTypeValue(values, current.aggregateType);
321
+ instance = _this.engine.getInstance(current.subTableId);
322
+ num = Number(value2);
323
+ break;
423
324
  }
424
- }
425
- var oldValue = this.engine.getState(control.id, rowIndex);
426
- var result = !value || value === Infinity || value === -Infinity ? 0 : control.props.precision === "" ? value : Number(value.toFixed(control.props.precision));
427
- // 如果值没变的话,不触发修改
428
- if (result === (oldValue === null || oldValue === void 0 ? void 0 : oldValue.result)) {
429
- return;
430
- }
431
- var _oldValue_unit;
432
- this.engine.setState(control.id, {
433
- result: result,
434
- unit: (_oldValue_unit = oldValue === null || oldValue === void 0 ? void 0 : oldValue.unit) !== null && _oldValue_unit !== void 0 ? _oldValue_unit : ""
435
- }, rowIndex);
436
325
  }
437
- },
438
- {
439
- key: "getNumberValue",
440
- value: /**
326
+ if (!Number.isNaN(num) && _this.controlNeedComputedValue(instance)) {
327
+ // 在每一个数字外边包一个括号,将 --1 转为 -(-1) 确保 --1 这种情况不会出问题
328
+ result += "(".concat(num, ")");
329
+ } else {
330
+ result += 0;
331
+ }
332
+ return result;
333
+ }, "");
334
+ var value;
335
+ // 有缓存的话取缓存,没有缓存再执行eval
336
+ if (this.cacheComputedResult[scriptText] !== undefined) {
337
+ value = this.cacheComputedResult[scriptText];
338
+ } else {
339
+ // 解决js精准度问题
340
+ value = Number(format(new Function("return ".concat(scriptText))(), {
341
+ precision: 16
342
+ }));
343
+ this.cacheComputedResult[scriptText] = value;
344
+ }
345
+ // let rowIndex = undefined
346
+ if (this.controlInSubtable(control)) {
347
+ // rowIndex = this.engine.getInstanceRowIndex(control)
348
+ // 控件在明细表内,但是没有行下标,说明控件被已经删除了,所以直接return
349
+ if (rowIndex === undefined) {
350
+ return;
351
+ }
352
+ }
353
+ var oldValue = this.engine.getState(control.id, rowIndex);
354
+ var result = !value || value === Infinity || value === -Infinity ? 0 : control.props.precision === "" ? value : Number(value.toFixed(control.props.precision));
355
+ // 如果值没变的话,不触发修改
356
+ if (result === (oldValue === null || oldValue === void 0 ? void 0 : oldValue.result)) {
357
+ return;
358
+ }
359
+ var _oldValue_unit;
360
+ this.engine.setState(control.id, {
361
+ result: result,
362
+ unit: (_oldValue_unit = oldValue === null || oldValue === void 0 ? void 0 : oldValue.unit) !== null && _oldValue_unit !== void 0 ? _oldValue_unit : ""
363
+ }, rowIndex);
364
+ };
365
+ /**
441
366
  * @description 获取数字值,因为计算公式可以依赖计算公式和金额,所以需要从value中取到对应的值
442
- * */ function getNumberValue(value) {
443
- if (typeof value === "object" && value) {
444
- if ("result" in value) {
445
- return value.result;
446
- } else if ("amount" in value) {
447
- return value.amount;
448
- }
449
- }
450
- if (typeof value === "number") {
451
- return value;
452
- }
453
- return 0;
367
+ * */ _proto.getNumberValue = function getNumberValue(value) {
368
+ if (typeof value === "object" && value) {
369
+ if ("result" in value) {
370
+ return value.result;
371
+ } else if ("amount" in value) {
372
+ return value.amount;
454
373
  }
455
- },
456
- {
457
- key: "getAggregateTypeValue",
458
- value: /**
374
+ }
375
+ if (typeof value === "number") {
376
+ return value;
377
+ }
378
+ return 0;
379
+ };
380
+ /**
459
381
  * 计算明细子表最大值最小值平均值总和
460
- * */ function getAggregateTypeValue(values, type) {
461
- if (!type || !values || !values.length) return 0;
462
- switch(type){
463
- case CALC_AGGREGATE_TYPE.MAX:
464
- var _Math;
465
- return (_Math = Math).max.apply(_Math, _toConsumableArray(values));
466
- case CALC_AGGREGATE_TYPE.MIN:
467
- var _Math1;
468
- return (_Math1 = Math).min.apply(_Math1, _toConsumableArray(values));
469
- case CALC_AGGREGATE_TYPE.SUM:
470
- return values.reduce(function(a, b) {
471
- return a + b;
472
- });
473
- case CALC_AGGREGATE_TYPE.AVG:
474
- return values.reduce(function(a, b) {
475
- return a + b;
476
- }) / values.length;
477
- }
478
- }
382
+ * */ _proto.getAggregateTypeValue = function getAggregateTypeValue(values, type) {
383
+ if (!type || !values || !values.length) return 0;
384
+ switch(type){
385
+ case CALC_AGGREGATE_TYPE.MAX:
386
+ var _Math;
387
+ return (_Math = Math).max.apply(_Math, _toConsumableArray(values));
388
+ case CALC_AGGREGATE_TYPE.MIN:
389
+ var _Math1;
390
+ return (_Math1 = Math).min.apply(_Math1, _toConsumableArray(values));
391
+ case CALC_AGGREGATE_TYPE.SUM:
392
+ return values.reduce(function(a, b) {
393
+ return a + b;
394
+ });
395
+ case CALC_AGGREGATE_TYPE.AVG:
396
+ return values.reduce(function(a, b) {
397
+ return a + b;
398
+ }) / values.length;
479
399
  }
480
- ]);
400
+ };
481
401
  return CalcPlugin;
482
402
  }();