@byteluck-fe/model-driven-engine 2.5.0-beta.1 → 2.5.0-beta.4
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/dist/esm/common/ActionManager.js +72 -154
- package/dist/esm/common/DataManager.js +60 -128
- package/dist/esm/common/Engine.js +1111 -1060
- package/dist/esm/common/OkWorker.js +106 -75
- package/dist/esm/common/Runtime.js +29 -27
- package/dist/esm/common/Store.js +181 -149
- package/dist/esm/common/checkerValue.js +328 -253
- package/dist/esm/common/index.js +2 -2
- package/dist/esm/common/proxyState.js +47 -47
- package/dist/esm/index.js +3 -3
- package/dist/esm/plugins/CalcPlugin.js +382 -306
- package/dist/esm/plugins/ControlsEventPlugin.js +141 -225
- package/dist/esm/plugins/ES6ModulePlugin.js +56 -38
- package/dist/esm/plugins/LifecycleEventPlugin.js +107 -190
- package/dist/esm/plugins/StylePlugin.js +31 -13
- 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 +180 -180
- 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 -25
- 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 -26
- 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
|
@@ -11,6 +11,20 @@ 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
|
+
}
|
|
14
28
|
function _iterableToArray(iter) {
|
|
15
29
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
16
30
|
}
|
|
@@ -28,8 +42,8 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
28
42
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
29
43
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
30
44
|
}
|
|
31
|
-
import { CONTROL_TYPE, CALC_TOKEN_TYPE, CALC_AGGREGATE_TYPE } from
|
|
32
|
-
import { format } from
|
|
45
|
+
import { CONTROL_TYPE, CALC_TOKEN_TYPE, CALC_AGGREGATE_TYPE } from '@byteluck-fe/model-driven-shared';
|
|
46
|
+
import { format } from 'mathjs';
|
|
33
47
|
var DisplayType;
|
|
34
48
|
(function(DisplayType) {
|
|
35
49
|
DisplayType[/**
|
|
@@ -60,343 +74,405 @@ export var CalcPlugin = /*#__PURE__*/ function() {
|
|
|
60
74
|
this.getDontHasPermissionControlIds();
|
|
61
75
|
this.getNeedHideRememberControlIds();
|
|
62
76
|
}
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
_createClass(CalcPlugin, [
|
|
78
|
+
{
|
|
79
|
+
key: "getNeedHideRememberControlIds",
|
|
80
|
+
value: /**
|
|
65
81
|
* @description 获取显隐控制的需要被记住值的控件id
|
|
66
|
-
* */
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
}, []);
|
|
75
94
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: "getDontHasPermissionControlIds",
|
|
98
|
+
value: /**
|
|
80
99
|
* @description 获取权限控制的隐藏的字段,不需要参与计算
|
|
81
|
-
* */
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
}, []);
|
|
89
111
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
key: "controlNeedComputedValue",
|
|
115
|
+
value: /**
|
|
94
116
|
* @description 判断控件是否需要被计算
|
|
95
117
|
* @param control 控件
|
|
96
|
-
* */
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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: /**
|
|
113
138
|
* @description 获取控件是否被隐藏
|
|
114
139
|
* @param control 控件
|
|
115
|
-
* */
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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: /**
|
|
136
167
|
* @description 重置依赖,获取所有的计算公式控件,并根据计算公式获取控件依赖关系
|
|
137
|
-
* */
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
168
|
+
* */ function resetDependencies() {
|
|
169
|
+
this.calcControls = [];
|
|
170
|
+
this.dependenciesTriggerMap.clear();
|
|
171
|
+
this.getAllCalcControl();
|
|
172
|
+
this.getCalcDependencies();
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
key: "allCalcControlComputed",
|
|
177
|
+
value: /**
|
|
144
178
|
* @description 执行所有计算公式控件的计算
|
|
145
|
-
* */
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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: /**
|
|
152
189
|
* @description 获取所有的计算公式控件
|
|
153
|
-
* */
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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: /**
|
|
160
200
|
* @description 获取计算公式控件依赖,组成 依赖=>[计算公式] 的Map结构
|
|
161
|
-
* */
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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, []);
|
|
169
225
|
}
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
226
|
+
var arr = this.dependenciesTriggerMap.get(id);
|
|
227
|
+
if (!arr.includes(item)) {
|
|
228
|
+
arr.push(item);
|
|
173
229
|
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
current.children.forEach(function(item) {
|
|
193
|
-
var control = item.children[0];
|
|
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;
|
|
194
248
|
// @ts-ignore
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}, []);
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
249
|
+
}, []);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
key: "watchSchemaHideChange",
|
|
254
|
+
value: /**
|
|
204
255
|
* @description 监听控件的显隐事件,把显隐会影响的控件触发一遍计算
|
|
205
|
-
* */
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
+
}
|
|
213
267
|
});
|
|
214
268
|
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
key: "watchSubtableChange",
|
|
272
|
+
value: /**
|
|
218
273
|
* @description 监听明细子表的change事件,把明细表会影响的控件触发一遍计算
|
|
219
|
-
* */
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* @description 监听控件的change事件,当控件change的时候,取到控件会影响的计算公式,然后执行对应的计算
|
|
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;
|
|
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
|
+
});
|
|
248
295
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
key: "watchControlChange",
|
|
299
|
+
value: /**
|
|
300
|
+
* @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
|
+
});
|
|
260
329
|
}
|
|
261
|
-
_this.computedCalcValue(calcControl);
|
|
262
|
-
});
|
|
263
|
-
} else {
|
|
264
|
-
// @ts-ignore
|
|
265
|
-
calcControls.forEach(function(calcControl) {
|
|
266
|
-
_this.computedCalcValue(calcControl);
|
|
267
330
|
});
|
|
268
331
|
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
key: "controlInSubtable",
|
|
335
|
+
value: /**
|
|
272
336
|
* @description 控件在明细子表内
|
|
273
|
-
* */
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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: /**
|
|
278
345
|
* @description 执行计算公式的计算
|
|
279
346
|
* */ // @ts-ignore
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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;
|
|
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;
|
|
304
361
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
+
}
|
|
313
393
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}) : [];
|
|
320
|
-
var value2 = _this.getAggregateTypeValue(values, current.aggregateType);
|
|
321
|
-
instance = _this.engine.getInstance(current.subTableId);
|
|
322
|
-
num = Number(value2);
|
|
323
|
-
break;
|
|
394
|
+
if (!Number.isNaN(num) && _this.controlNeedComputedValue(instance)) {
|
|
395
|
+
// 在每一个数字外边包一个括号,将 --1 转为 -(-1) 确保 --1 这种情况不会出问题
|
|
396
|
+
result += "(".concat(num, ")");
|
|
397
|
+
} else {
|
|
398
|
+
result += 0;
|
|
324
399
|
}
|
|
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;
|
|
419
|
+
}
|
|
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);
|
|
325
432
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
/**
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
key: "getNumberValue",
|
|
436
|
+
value: /**
|
|
366
437
|
* @description 获取数字值,因为计算公式可以依赖计算公式和金额,所以需要从value中取到对应的值
|
|
367
|
-
* */
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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;
|
|
373
450
|
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return 0;
|
|
379
|
-
};
|
|
380
|
-
/**
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
key: "getAggregateTypeValue",
|
|
454
|
+
value: /**
|
|
381
455
|
* 计算明细子表最大值最小值平均值总和
|
|
382
|
-
* */
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
|
+
}
|
|
399
475
|
}
|
|
400
|
-
|
|
476
|
+
]);
|
|
401
477
|
return CalcPlugin;
|
|
402
478
|
}();
|