|
@@ -157,21 +157,33 @@ $(document).ready(() => {
|
|
|
return expr;
|
|
return expr;
|
|
|
}
|
|
}
|
|
|
trans2NodeExpr(expr, payTree) {
|
|
trans2NodeExpr(expr, payTree) {
|
|
|
- const orderParam = expr.match(this.orderReg);
|
|
|
|
|
- if (orderParam) {
|
|
|
|
|
- for (const op of orderParam) {
|
|
|
|
|
- const order = parseInt(op.substring(1, op.length));
|
|
|
|
|
- const payNode = payTree.nodes[order - 1];
|
|
|
|
|
- expr = expr.replace(op, payNode ? `<<${payNode.uuid}>>` || '' : 0);
|
|
|
|
|
|
|
+ const orderParam = [...expr.matchAll(this.orderReg)];
|
|
|
|
|
+ if (!orderParam) return expr;
|
|
|
|
|
+
|
|
|
|
|
+ orderParam.forEach(op => {
|
|
|
|
|
+ op.matchLength = op[0].length;
|
|
|
|
|
+ op.matchEnd = op.index + op.matchLength;
|
|
|
|
|
+ });
|
|
|
|
|
+ const parts = [];
|
|
|
|
|
+ for (const [i, op] of orderParam.entries()) {
|
|
|
|
|
+ if (i === 0) {
|
|
|
|
|
+ if (op.index > 0) parts.push(expr.substring(0, op.index));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ parts.push(expr.substring(orderParam[i-1].matchEnd, op.index));
|
|
|
|
|
+ }
|
|
|
|
|
+ const order = parseInt(op[0].substring(1, op.matchLength));
|
|
|
|
|
+ const payNode = payTree.nodes[order - 1];
|
|
|
|
|
+ parts.push(payNode ? `<<${payNode.uuid}>>` || '' : 0);
|
|
|
|
|
+ if (i === orderParam.length - 1) {
|
|
|
|
|
+ if (op.matchEnd < expr.length) parts.push(expr.substring(op.matchEnd, expr.length));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return expr;
|
|
|
|
|
|
|
+ return parts.join('');
|
|
|
}
|
|
}
|
|
|
- checkExprValid(expr, invalidParam, selfId, payTree) {
|
|
|
|
|
|
|
+ checkExprValid(expr, invalidParam, selfId, payTree, allowFixed = false) {
|
|
|
if (!expr) return [true, ''];
|
|
if (!expr) return [true, ''];
|
|
|
const param = [];
|
|
const param = [];
|
|
|
- let num = '', base = '';
|
|
|
|
|
- let fixedIdParam;
|
|
|
|
|
|
|
+ let num = '', base = '', fixedIdParam = undefined;
|
|
|
for (let i = 0, iLen = expr.length; i < iLen; i++) {
|
|
for (let i = 0, iLen = expr.length; i < iLen; i++) {
|
|
|
const subExpr = expr.substring(i, expr.length);
|
|
const subExpr = expr.substring(i, expr.length);
|
|
|
if (/^[\d\.%]+/.test(expr[i])) {
|
|
if (/^[\d\.%]+/.test(expr[i])) {
|
|
@@ -283,10 +295,12 @@ $(document).ready(() => {
|
|
|
if (!selfId) return [false, '输入的表达式错误:不支持行号引用'];
|
|
if (!selfId) return [false, '输入的表达式错误:不支持行号引用'];
|
|
|
|
|
|
|
|
if ([`<<${selfId}>>`].indexOf(p.value) >= 0) return [false, '输入的表达式非法:请勿引用自己'];
|
|
if ([`<<${selfId}>>`].indexOf(p.value) >= 0) return [false, '输入的表达式非法:请勿引用自己'];
|
|
|
- if (!fixedIdParam) {
|
|
|
|
|
- fixedIdParam = payTree.nodes.filter(x => { return x.is_fixed; }).map(x => { return `<<${x.uuid}>>`});
|
|
|
|
|
|
|
+ if (!allowFixed) {
|
|
|
|
|
+ if (fixedIdParam === undefined) {
|
|
|
|
|
+ fixedIdParam = payTree.nodes.filter(x => { return x.is_fixed; }).map(x => { return `<<${x.uuid}>>`});
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fixedIdParam.indexOf(p.value) >= 0) return [false, '输入的表达式非法:请勿引用固定项'];
|
|
|
}
|
|
}
|
|
|
- if (fixedIdParam.indexOf(p.value) >= 0) return [false, '输入的表达式非法:请勿引用固定项'];
|
|
|
|
|
}
|
|
}
|
|
|
if (p.type === 'left') {
|
|
if (p.type === 'left') {
|
|
|
iLeftCount += 1;
|
|
iLeftCount += 1;
|
|
@@ -318,7 +332,7 @@ $(document).ready(() => {
|
|
|
data.expr = num;
|
|
data.expr = num;
|
|
|
} else {
|
|
} else {
|
|
|
const expr = this.trans2NodeExpr($.trim(text).replace('\t', '').replace('=', '').toLowerCase(), payTree);
|
|
const expr = this.trans2NodeExpr($.trim(text).replace('\t', '').replace('=', '').toLowerCase(), payTree);
|
|
|
- const [valid, msg] = this.checkExprValid(expr, [], payNode.uuid, payTree);
|
|
|
|
|
|
|
+ const [valid, msg] = this.checkExprValid(expr, [], payNode.uuid, payTree, true);
|
|
|
if (!valid) return [valid, msg];
|
|
if (!valid) return [valid, msg];
|
|
|
data.expr = expr;
|
|
data.expr = expr;
|
|
|
}
|
|
}
|