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