Appearance
表达式
此功能允许你根据以下数据为块设置动态值:
| 名称 | 描述 | 访问项目 |
|---|---|---|
表 | 从表 | 获取数据 table |
变量 | 从变量 | 获取数据 variables.<variableName> |
循环数据 | 获取循环数据块的当前迭代数据 | loopData.<loopId> |
获取上一个区块的数据 | 获取上一个区块的数据 | prevBlockData |
全局数据 | 获取工作流程全局数据 | globalData |
获取活动标签页url | 获取活动标签页 url | activeTabUrl |
工作流程 | 获取调用子流程块已执行的工作流的数据(表和变量) | workflow.<executeId> |
MakAgent 使用 模板并使用上面的数据和函数对其进行扩展。
书写表达式
要编写表达式,必须遵循以下格式“{{keyword }}”; 并将“关键字”替换为上述数据源之一。 它允许 MakAgent 区分静态和动态数据。
假设你在工作流程中有一个变量,变量名称是“socials”; 它的值是一个对象数组。 你想要使用 HTTP 请求块 将此变量发送到 API。
json
[
{ "name": "GitHub", "url": "https://github.com/" },
{ "name": "Gitee", "url": "https://gitee.com/" },
{ "name": "MakWing", "url": "https://makwing.com" }
][
{ "name": "GitHub", "url": "https://github.com/" },
{ "name": "Gitee", "url": "https://gitee.com/" },
{ "name": "MakWing", "url": "https://makwing.com" }
]你可以在 HTTP 请求块 正文中使用以下表达式:
{{variables.socials}}{{variables.socials}}
但是,如果你想使用数组第一个元素上的“url”属性作为 新标签页块 URL 内的值,该怎么办? 为此,请使用以下表达式:
{{variables.socials.0.url}}{{variables.socials.0.url}}
该表达式中的“0”表示数组的第一个元素。 如果你想获取数组的第二个元素,请将其替换为“1”。 2 代表第三个元素; 3 代表第四个元素; 等等。
访问表达式内的其他数据
要访问表达式内的其他数据,必须使用方括号 ([]) 将用于访问数据的表达式括起来。 例如,当你想要使用 $increment 函数递增变量或根据循环的当前索引获取表行时。 你可以编写如下表达式:
{{$increment([variables.variableName]}}
{{table.[loopData.loopId.$index].columnName}}{{$increment([variables.variableName]}}
{{table.[loopData.loopId.$index].columnName}}函数
所有内置函数始终以前缀“$”开头; 例如,$funcName(param); 以下是MakAgent 中可用函数的参考列表。
$date(date, dateFormat?)
获取或格式化日期。 该函数有两个参数,其中第二个参数是可选的。
如果你想格式化当前日期,可以直接传递 dateFormat 作为第一个参数,如 {{ $date('DD-MMMM-YYYY') }},以及 输出将为“14-January-2022”。 在 day.js 页面 上查看所有可用的日期格式。
对于 date参数,请参阅 MDN 页面 上的有效日期格式。
示例
js
$date("DD MMMM YYYY") // 14 January 2022
$date("DD-MM-YYYY, hh:mm A") // 14-01-2022, 02:24 PM
$date("relative") // A few seconds ago
$date("timestamp") // 1651118110948
$date("2005-06-07", "DD MMMM YYYY") // 07 June 2005
$date("1977-04-01T14:00:30", "DD-MM-YYYY, hh:mm A") // 01-04-1977, 02:00 PM
$date("14 January 2021", "relative") // A year ago
$date("14 January 2021", "timestamp") // 1610553600000$date("DD MMMM YYYY") // 14 January 2022
$date("DD-MM-YYYY, hh:mm A") // 14-01-2022, 02:24 PM
$date("relative") // A few seconds ago
$date("timestamp") // 1651118110948
$date("2005-06-07", "DD MMMM YYYY") // 07 June 2005
$date("1977-04-01T14:00:30", "DD-MM-YYYY, hh:mm A") // 01-04-1977, 02:00 PM
$date("14 January 2021", "relative") // A year ago
$date("14 January 2021", "timestamp") // 1610553600000$randint(min?, max?)
生成一个随机数。 你可以通过输入min 和 max 参数来更改随机数的范围。
示例
js
$randint() // 30
$randint() // 14
$randint(0, 10) // 4
$randint(0, 10) // 7$randint() // 30
$randint() // 14
$randint(0, 10) // 4
$randint(0, 10) // 7$getLength(str)
获取字符串或数组的长度。
示例
js
// Get the length of a string
$getLength("testing") // 7
// Get tabel length
$getLength([table]) // 14
// Get the length of the "text" column on the second row
$getLength([table.1.text]) // 5// Get the length of a string
$getLength("testing") // 7
// Get tabel length
$getLength([table]) // 14
// Get the length of the "text" column on the second row
$getLength([table.1.text]) // 5$randData(expression)
生成随机数据的函数,只需将表达式传递给其参数即可。 例如,$randData("?l")将生成一个随机小写字母,如a。 支持的表达式:
?l: lowercase?u: uppercase?d: digit?f: uppercase + lowercase?s: symbol?m: uppercase + digit?n: lowercase + digit?a: any
你还可以组合这些表达式,例如$randData("?u?l?l?l?l?d?d@gmail.com"),这将生成`Apond89@gmail。
示例
js
$randData("?d?d") // 89
$randData("?l?l?l?d?d@gmail.com") // wal29@gmail.com
$randData("?d?u?s?l?l?s?a?m") // 4C%ee^MF9$randData("?d?d") // 89
$randData("?l?l?l?d?d@gmail.com") // wal29@gmail.com
$randData("?d?u?s?l?l?s?a?m") // 4C%ee^MF9$multiply(value, multiplyBy)
用于乘以一个值。
示例
js
$multiply(5, 2) // 10
// Multiply a variable
$multiply([variables.variableName], 0.3) //20.7$multiply(5, 2) // 10
// Multiply a variable
$multiply([variables.variableName], 0.3) //20.7$increment(value, incrementBy)
用于增加一个值。
示例
js
$increment(10, 2) // 12
$increment(72, 2) // 74$increment(10, 2) // 12
$increment(72, 2) // 74$divide(value, incrementBy)
用于除以一个值。
示例
js
$divide(22, 7) // 3.142857142857143
$divide(10, 2) // 5$divide(22, 7) // 3.142857142857143
$divide(10, 2) // 5$subtract(value, incrementBy)
用于减去一个值。
示例
js
$subtract(80, 7) // 73
$subtract(11, 2) // 9$subtract(80, 7) // 73
$subtract(11, 2) // 9$replace(value, search, replace)
用于替换字符串,从要替换的字符串的值中搜索。
示例
js
$replace("hello world!", "world", "everyone") // hello everyone!
$replace("hello world!", "hello", "hi") // hi world!$replace("hello world!", "world", "everyone") // hello everyone!
$replace("hello world!", "hello", "hi") // hi world!$replaceAll(value, search, replace)
用于替换从要替换字符串的值中搜索的所有匹配字符串。
示例
js
$replace("hello world!", "o", "0") // hell0 w0rld
$replace("The temperature is 25 degrees today", " ", "") // Thetemperatureis25degreestoday$replace("hello world!", "o", "0") // hell0 w0rld
$replace("The temperature is 25 degrees today", " ", "") // Thetemperatureis25degreestoday$toLowerCase(value)
用于小写值。
示例
js
$toLowerCase("HELLO WORLD!") // hello world!
$toLowerCase("hELLO wORLD!") // hello world!$toLowerCase("HELLO WORLD!") // hello world!
$toLowerCase("hELLO wORLD!") // hello world!$toUpperCase(value)
用于将值大写。
示例
js
$toUpperCase("hello world!") // HELLO WORLD!
$toUpperCase("hELLO wORLD!") // HELLO WORLD!$toUpperCase("hello world!") // HELLO WORLD!
$toUpperCase("hELLO wORLD!") // HELLO WORLD!$modulo(num, divisor)
返回除法的余数或有符号余数。
示例
js
$modulo(13, 5) // 3
$modulo(-13, 5) // -3
$modulo(4, 2) // 0
$modulo(-4, 2) // -0$modulo(13, 5) // 3
$modulo(-13, 5) // -3
$modulo(4, 2) // 0
$modulo(-4, 2) // -0$filter(data, syntax)
过滤/查询 javascript 对象。 MakAgent 使用 JSONPath 库进行查询。
data: 要查询的 Javascript 对象syntax: JSONPath 语法
示例
使用以下值查询“colors”变量:
json
[
{ color: "red", value: "#f00" },
{ color: "green", value: "#0f0" },
{ color: "blue", value: "#00f" },
{ color: "cyan", value: "#0ff" },
{ color: "magenta", value: "#f0f" },
{ color: "yellow", value: "#ff0" },
{ color: "black", value: "#000" }
][
{ color: "red", value: "#f00" },
{ color: "green", value: "#0f0" },
{ color: "blue", value: "#00f" },
{ color: "cyan", value: "#0ff" },
{ color: "magenta", value: "#f0f" },
{ color: "yellow", value: "#ff0" },
{ color: "black", value: "#000" }
]js
{{ $filter([variables.colors], "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']
{{ $filter([variables.colors], "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']{{ $filter([variables.colors], "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']
{{ $filter([variables.colors], "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']使用 JS 表达式
js
!!{{ $filter(variables.colors, "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']
!!{{ $filter(variables.colors, "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']!!{{ $filter(variables.colors, "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']
!!{{ $filter(variables.colors, "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']$stringify(value)
将 JavaScript 值转换为 JSON 字符串。
示例
本节提供了有关如何编写表达式的更多示例。 以及源数据的数据结构。
表格
该表存储为对象数组,其中表列作为对象键。
json
[
{ "color": "blue", "value": "#00f" },
{ "color": "cyan", "value": "#0ff" },
{ "color": "magenta", "value": "#f0f" },
{ "color": "yellow", "value": "#ff0" },
{ "color": "black", "value": "#000" }
][
{ "color": "blue", "value": "#00f" },
{ "color": "cyan", "value": "#0ff" },
{ "color": "magenta", "value": "#f0f" },
{ "color": "yellow", "value": "#ff0" },
{ "color": "black", "value": "#000" }
]获取表格的第一行。
表达式:{{ table.0 }}
输出:{“color”:“blue”,“value”:“#00f”}获取表格的第二行。
表达式:{{ table.1 }}
输出:{“color”:“cyan”,“value”:“#0ff”}获取表格的最后一行。
表达式:{{ table.$last }}
输出:{“color”:“black”,“value”:“#000”}获取表格第一行
颜色列的值。
表达式:{{ table.0.color }}
输出:“blue”获取表第一行
value列的值。
表达式:{{ table.0.value }}
输出:#00f
变量
变量存储为对象,变量名作为对象键。
json
{
"url": "https://makwing.com",
"numbers": [100, 500, 300, 200, 400]
}{
"url": "https://makwing.com",
"numbers": [100, 500, 300, 200, 400]
}获取
url变量的值。
表达式:{{ Variables.url }}
输出:https://makwing.com获取
numbers变量的值。
表达式:{{ Variables.numbers }}
输出:[100, 500, 300, 200, 400]获取
numbers变量的第一个数字。
表达式:{{variables.numbers.0 }}
输出:100
JavaScript 表达式
MakAgent 还支持表达式中的 javascript,但要编写 javascript,你必须添加 !! 字符作为块的文本字段上的第一个值。 例如,从 数字为:{{variables.number}} 到 !!数字为:{{variables.number}}。

并且你可以像使用 javascript 函数一样使用内置函数。
示例
- 使用内置函数
js
{{$getLength(table)}} //10
{{$randData("?d?d")}} // 89{{$getLength(table)}} //10
{{$randData("?d?d")}} // 89- 获取表的最后一行
js
{{table[table.length - 1].columnName}}{{table[table.length - 1].columnName}}- 获取当前时间戳
js
{{Date.now()}} //1666237704022{{Date.now()}} //1666237704022- 访问循环数据和索引
js
// Loop data
{{loopData.loopId.data}}
// Loop index
{{loopData.loopId.$index}}// Loop data
{{loopData.loopId.data}}
// Loop index
{{loopData.loopId.$index}}
MakAgent在线文档