|
@@ -728,30 +728,23 @@ let analyzer = {
|
|
|
let idx = FName.slice(1) - 1;
|
|
|
return calcTemplate.calcItems[idx];
|
|
|
},
|
|
|
- isCycleCalc: function (expression, calcTemplate) { // 这里判断expression,是ID引用: @5+@6
|
|
|
- let me = analyzer;
|
|
|
-
|
|
|
- function isCycle(nodeExpr, template) {
|
|
|
- let atIDArr = me.getAtIDArr(nodeExpr);
|
|
|
- for (let atID of atIDArr){
|
|
|
- let ID = atID.slice(1);
|
|
|
- let item = template.compiledCalcItems[ID];
|
|
|
- if (item.expression.includes(atID)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- else {
|
|
|
- isCycle(item.expression, template);
|
|
|
- }
|
|
|
- };
|
|
|
- return false;
|
|
|
- };
|
|
|
+ isCycleCalc: function (expression, ID, template) { // 这里判断expression,是ID引用: @5+@6
|
|
|
+ if (expression.includes(`@${ID}`))
|
|
|
+ return true;
|
|
|
+
|
|
|
+ let atIDs = analyzer.getAtIDArr(expression);
|
|
|
+ for (let atID of atIDs) {
|
|
|
+ let item = template.compiledCalcItems[atID.slice(1)];
|
|
|
+ if (analyzer.isCycleCalc(item.expression, ID, template))
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- return isCycle(expression, calcTemplate);
|
|
|
+ return false;
|
|
|
},
|
|
|
- isLegal: function (dispExpr, calcTemplate) { // 检测包括:无效字符、基数是否中括号、基数是否定义、行引用、循环计算
|
|
|
+ isLegal: function (dispExpr, itemID, calcTemplate) { // 检测包括:无效字符、基数是否中括号、基数是否定义、行引用、循环计算
|
|
|
let me = analyzer;
|
|
|
let expr = me.standard(dispExpr);
|
|
|
- let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]F%]/g;
|
|
|
+ let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]FL%]/g;
|
|
|
if (invalidChars.test(expr)){
|
|
|
alert('表达式中含有无效的字符!');
|
|
|
return false;
|
|
@@ -761,7 +754,11 @@ let analyzer = {
|
|
|
let arrCn = expr.match(pattCn);
|
|
|
let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
|
|
|
let arrBase = expr.match(pattBase);
|
|
|
- if (arrCn.length != arrBase.length){
|
|
|
+ if (arrCn && !arrBase){
|
|
|
+ alert('定额基数必须用中括号[]括起来!');
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ if (arrCn && arrBase && (arrCn.length != arrBase.length)){
|
|
|
for (let cn of arrCn){
|
|
|
let tempBase = `[${cn}]`;
|
|
|
if (!arrBase.includes(tempBase)){
|
|
@@ -773,13 +770,14 @@ let analyzer = {
|
|
|
alert('定额基数必须用中括号[]括起来!');
|
|
|
return false;
|
|
|
};
|
|
|
-
|
|
|
- for (let base of arrBase){
|
|
|
- let baseName = base.slice(1, -1);
|
|
|
- if (!rationCalcBases[baseName]){
|
|
|
- alert('定额基数 [' + baseName + '] 末定义!');
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if (arrBase){
|
|
|
+ for (let base of arrBase){
|
|
|
+ let baseName = base.slice(1, -1);
|
|
|
+ if (!rationCalcBases[baseName]){
|
|
|
+ alert('定额基数 [' + baseName + '] 末定义!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ };
|
|
|
};
|
|
|
|
|
|
let arrF = me.getFArr(expr);
|
|
@@ -792,26 +790,13 @@ let analyzer = {
|
|
|
};
|
|
|
|
|
|
let expression = me.getExpression(expr, calcTemplate);
|
|
|
- if (me.isCycleCalc(expression, calcTemplate)){
|
|
|
+ if (me.isCycleCalc(expression, itemID, calcTemplate)){
|
|
|
alert('表达式中有循环计算!');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ return true; // 表达式合法
|
|
|
},
|
|
|
- analyzeUserExpr: function(calcItem, calcTemplate){
|
|
|
- let me = analyzer;
|
|
|
- let expr = calcItem.dispExpr;
|
|
|
- expr = me.standard(expr);
|
|
|
- calcItem.dispExpr = expr;
|
|
|
-
|
|
|
- if (me.isLegal(expr, calcTemplate)){
|
|
|
- calcItem.expression = expr;
|
|
|
- return true;
|
|
|
- }else
|
|
|
- return false;
|
|
|
- },
|
|
|
-
|
|
|
getExpression: function (dispExpr, calcTemplate) {
|
|
|
function refLineToID(expr, template) {
|
|
|
let rst = expr;
|