|
@@ -18,6 +18,7 @@ const TreeExprCalc = (function(){
|
|
valueChar: '$',
|
|
valueChar: '$',
|
|
|
|
|
|
calcCache: {},
|
|
calcCache: {},
|
|
|
|
+ error: { loop: '', deep: '' },
|
|
|
|
|
|
// 计算必须项
|
|
// 计算必须项
|
|
tree: null,
|
|
tree: null,
|
|
@@ -28,6 +29,7 @@ const TreeExprCalc = (function(){
|
|
exprCacheKey: [],
|
|
exprCacheKey: [],
|
|
exprFieldsIndex: {},
|
|
exprFieldsIndex: {},
|
|
exprCacheFields: [],
|
|
exprCacheFields: [],
|
|
|
|
+ errorMsg: true,
|
|
};
|
|
};
|
|
const getCalcField = function(value) {
|
|
const getCalcField = function(value) {
|
|
return calcRela.exprFieldsIndex[value];
|
|
return calcRela.exprFieldsIndex[value];
|
|
@@ -43,6 +45,7 @@ const TreeExprCalc = (function(){
|
|
calcRela.exprCacheKey = setting.exprCacheKey;
|
|
calcRela.exprCacheKey = setting.exprCacheKey;
|
|
calcRela.exprCacheFields = calcRela.exprCacheKey.map(x => { return getCalcField(x); });
|
|
calcRela.exprCacheFields = calcRela.exprCacheKey.map(x => { return getCalcField(x); });
|
|
}
|
|
}
|
|
|
|
+ calcRela.errorMsg = setting.errorMsg || true;
|
|
};
|
|
};
|
|
const checkExprValid = function(expr, invalidOrders = []) {
|
|
const checkExprValid = function(expr, invalidOrders = []) {
|
|
if (!expr) return [true, ''];
|
|
if (!expr) return [true, ''];
|
|
@@ -239,8 +242,8 @@ const TreeExprCalc = (function(){
|
|
}
|
|
}
|
|
calcExprId = sortIds;
|
|
calcExprId = sortIds;
|
|
}
|
|
}
|
|
- if (calcSort > 100) calcRela.warningMsg = '公式计算引用过深,请检查公式';
|
|
|
|
- if (calcSort === 'max') calcRela.errorMsg = '公式计算存在循环引用,请检查公式';
|
|
|
|
|
|
+ if (calcSort > 100 && !calcRela.error.deep) calcRela.error.deep = x.id;
|
|
|
|
+ if (calcSort === 'max' && !calcRela.error.loop) calcRela.error.loop = x.id;
|
|
x.calcSort = calcSort;
|
|
x.calcSort = calcSort;
|
|
});
|
|
});
|
|
exprList.sort((x, y) => {
|
|
exprList.sort((x, y) => {
|
|
@@ -251,8 +254,25 @@ const TreeExprCalc = (function(){
|
|
};
|
|
};
|
|
const _initCache = function() {
|
|
const _initCache = function() {
|
|
calcRela.calcCache = {};
|
|
calcRela.calcCache = {};
|
|
- calcRela.warningMsg = '';
|
|
|
|
- calcRela.errorMsg = '';
|
|
|
|
|
|
+ calcRela.error.deep = '';
|
|
|
|
+ calcRela.error.loop = '';
|
|
|
|
+ };
|
|
|
|
+ const checkError = function() {
|
|
|
|
+ if (!calcRela.errorMsg) return;
|
|
|
|
+ if (calcRela.error.loop) {
|
|
|
|
+ const nodeIndex = calcRela.tree.nodes.findIndex(x => { return x.id === calcRela.error.loop; });
|
|
|
|
+ const node = calcRela.tree.nodes[nodeIndex];
|
|
|
|
+ const hintCode = (node.code || '') + (node.b_code || '');
|
|
|
|
+ toastr.warning(`第${nodeIndex + 1}行 ${hintCode} 公式存在循环计算,请检查`);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (calcRela.error.deep) {
|
|
|
|
+ const nodeIndex = calcRela.tree.nodes.findIndex(x => { return x.id === calcRela.error.deep; });
|
|
|
|
+ const node = calcRela.tree.nodes[nodeIndex];
|
|
|
|
+ const hintCode = (node.code || '') + (node.b_code || '');
|
|
|
|
+ toastr.warning(`第${nodeIndex + 1}行 ${hintCode} 公式引用层次过深,请检查`);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
};
|
|
};
|
|
const calcAllExpr = function(exprList) {
|
|
const calcAllExpr = function(exprList) {
|
|
_initCache();
|
|
_initCache();
|
|
@@ -261,7 +281,10 @@ const TreeExprCalc = (function(){
|
|
[expr.formula, expr.value] = calcExpr(expr.expr);
|
|
[expr.formula, expr.value] = calcExpr(expr.expr);
|
|
addCache(expr);
|
|
addCache(expr);
|
|
}
|
|
}
|
|
|
|
+ checkError();
|
|
|
|
+ const result = JSON.parse(JSON.stringify(calcRela.error));
|
|
_initCache();
|
|
_initCache();
|
|
|
|
+ return result;
|
|
};
|
|
};
|
|
const expr2ExprStr = function(expr) {
|
|
const expr2ExprStr = function(expr) {
|
|
if (!expr) return '';
|
|
if (!expr) return '';
|