From 2d6ade5790373be6ddf99b1bd455af43a640bb6a Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Wed, 27 Mar 2024 11:03:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20inputFormula=20eval?= =?UTF-8?q?Mode=20false=20=E6=97=B6=E6=8F=90=E4=BA=A4=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#9899)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/form/input-formula.md | 16 +++++++++++++++- .../amis-ui/src/components/formula/Picker.tsx | 7 ++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/zh-CN/components/form/input-formula.md b/docs/zh-CN/components/form/input-formula.md index e6d4b81eb..5015d2c8d 100644 --- a/docs/zh-CN/components/form/input-formula.md +++ b/docs/zh-CN/components/form/input-formula.md @@ -22,7 +22,7 @@ order: 21 "name": "formula", "label": "公式", "evalMode": true, - "value": "SUM(1 , 2)", + "value": "SUM(1 , user.id)", "variables": [ { "label": "表单字段", @@ -72,6 +72,20 @@ order: 21 } ] }, + { + "label": "人员对象", + "value": "user", + "children": [ + { + "label": "ID", + "value": "user.id" + }, + { + "label": "用户名", + "value": "user.name" + }, + ] + }, { "label": "长文本测试分类长文本测试分类长文本测试分类长文本测试分类", "children": [ diff --git a/packages/amis-ui/src/components/formula/Picker.tsx b/packages/amis-ui/src/components/formula/Picker.tsx index add29b767..e0e7d6a7b 100644 --- a/packages/amis-ui/src/components/formula/Picker.tsx +++ b/packages/amis-ui/src/components/formula/Picker.tsx @@ -344,7 +344,11 @@ export class FormulaPicker extends React.Component< let ast: any; try { - ast = parse(editorValue, {evalMode: true, allowFilter: false}); + ast = parse(editorValue, { + // mixedMode 弹窗中的一定是表达式 + evalMode: this.props.mixedMode ? true : this.props.evalMode, + allowFilter: false + }); } catch (error) { this.setState({isError: error?.message ?? true}); return; @@ -462,6 +466,7 @@ export class FormulaPicker extends React.Component< try { value && parse(value, { + // mixedMode 值是模版, 要 ${} 包裹表达式 evalMode: this.props.mixedMode ? false : this.props.evalMode, allowFilter: false });