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