Skip to content

if/else

if/else控件用于进行条件判断,目前仅支持ifelse两部分,不支持else if

默认仅使用if,如需使用else,可点击IF控件右上角的折叠按钮对控件进行展开。

业务属性

属性含义说明输入限定示例值
enable是否启用该控件,未启用时不编译是否编译选择值启用
text与控件关联的文本设计页控件显示常量ifElse
expression判断表达式Lua判断表达式Lua脚本var1==var2

判断表达式完全遵循Lua语言的语法,其中不等于逻辑与逻辑或逻辑非分别用~=andornot表示,在判断表达式中变量的表示无需使用#{}占位符,直接书写变量名即可。

使用示例

if

判断表达式输入:body.param ~= true

img_3.png

添加输出控件,输出字符串this is if

img_4.png

使用curl请求接口:

$ curl http://localhost:6636/api/if -d "{ \"param\": false }"
$ curl http://localhost:6636/api/if -d "{ \"param\": false }"

此时param属性为false

接口返回:

json
{
  "resCode": "0",
  "resMsg": "success",
  "data": "this is if"
}
{
  "resCode": "0",
  "resMsg": "success",
  "data": "this is if"
}

if else

点击右上角折叠按钮,展开else控件,添加输出控件,输出字符串this is else

img_5.png

使用curl请求接口:

$ curl http://localhost:6636/api/if -d "{ \"param\": true }"
$ curl http://localhost:6636/api/if -d "{ \"param\": true }"

此时param属性为true

接口返回:

json
{
  "resCode": "0",
  "resMsg": "success",
  "data": "this is else"
}
{
  "resCode": "0",
  "resMsg": "success",
  "data": "this is else"
}