mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:58:05 +08:00
fix: formula 的加法支持字符串拼接 (#5251)
This commit is contained in:
parent
c363e8ac2a
commit
dce548c6b4
@ -138,6 +138,8 @@ test('formula:math', () => {
|
||||
expect(evalFormual('"3" - "3"')).toBe(0);
|
||||
expect(evalFormual('AVG(4, "6", "10", 10, 10)')).toBe(8);
|
||||
expect(evalFormual('MAX(4, "6", "10", 2, 3)')).toBe(10);
|
||||
|
||||
expect(evalFormual('"a" + "b"')).toBe('ab');
|
||||
});
|
||||
|
||||
test('formula:text', () => {
|
||||
|
@ -230,6 +230,10 @@ export class Evaluator {
|
||||
add(ast: {left: any; right: any}) {
|
||||
const left = this.evalute(ast.left);
|
||||
const right = this.evalute(ast.right);
|
||||
// 如果有一个不是数字就变成字符串拼接
|
||||
if (isNaN(left) || isNaN(right)) {
|
||||
return left + right;
|
||||
}
|
||||
return stripNumber(this.formatNumber(left) + this.formatNumber(right));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user