@byteluck-fe/model-driven-engine 2.7.0-alpha.0 → 2.7.0-alpha.2

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