Skip to content

表达式相关

概述

织信提供在脚本中调用表达式中方法的能力,支持的表达式有:

类别描述说明
Array集合数组集合相关函数
Date日期日期运算相关函数
Encode字符编码字符串编解码相关函数
Math数字数学运算
Misc其他其他工具函数
String字符串字符串相关函数
User用户当前系统下的用户相关操作函数
Context上下文上下文相关函数。上下文表示在执行过程中的环境参数
Record数据表记录数据表相关函数
T国际化国际化相关函数

Array

数组集合相关函数,调用方式为informat.Array.方法

方法传参返回值说明示例
of...item: ObjectArray<Object>将多个元素转化为数组informat.Array.of('x', 2, 3) // ["x",2,3]
toListitem: ObjectArray<Object>将元素转化为数组,数组则cloneinformat.Array.toList('x') // ["x"]
joinarray: Array, separator: StringString按分隔符拼接数组内容informat.Array.join([1,2,3], '-') // "1-2-3"
lengthlist: ArrayInteger返回数组长度,null返回0informat.Array.length([1,2,3]) // 3
getlist: Array|Map, key: Integer|StringObject获取集合中指定位置的元素informat.Array.get([{name:'张三'}], 0) // {name:'张三'}
setlist: Array|Map, key: String|Integer, value: ObjectArray|Map设置集合中的元素值informat.Array.set({name:'张三'}, 'name', '李四')
addlist: Array, item: ObjectArray向数组尾部添加元素informat.Array.add([1,2], 3) // [1,2,3]
removelist: Array|Map, item: Object|StringArray|Map移除集合中的元素(仅第一个匹配项)informat.Array.remove([1,2,3], 2) // [1,3]
removeAlllist: Array|Map, item: Object|String|ArrayArray|Map移除集合中的所有匹配元素informat.Array.removeAll([1,2,2,3], 2) // [1,3]
isEmptylist: Array|MapBoolean判断集合是否为空informat.Array.isEmpty([]) // true
isNotEmptylist: Array|MapBoolean判断集合是否不为空informat.Array.isNotEmpty([1]) // true
containslist: Array|Map, item: ObjectBoolean判断集合是否包含指定元素informat.Array.contains([1,2,3], 2) // true
containsAnylist1: Array, list2: ArrayBoolean判断list1是否包含list2中任意元素informat.Array.containsAny([1,2],[2,3]) // true
containsAlllist1: Array, list2: ArrayBoolean判断list1是否包含list2中所有元素informat.Array.containsAll([1,2,3],[1,2]) // true
maplist: Array, key: StringArray返回数组中每个元素指定属性的列表informat.Array.map([{name:'张三'}], 'name') // ["张三"]
propslist: Array, props: Array<String>Array返回元素指定属性组成的新对象列表informat.Array.props([{name:'张三'}], ['name']) // [{name:'张三'}]
transformlist: Array, mapping: Map<String,String>Array按映射关系转换对象属性informat.Array.transform([{name:'张三'}], {name:'userName'})
concatlist1: Array, list2: ArrayArray拼接两个数组informat.Array.concat([1,2],[3,4]) // [1,2,3,4]
sortlist: Array, key: StringArray按指定属性排序数组informat.Array.sort([{age:20},{age:18}], 'age')
distinctlist: ArrayArray去除数组中的重复项informat.Array.distinct([1,2,2,3]) // [1,2,3]
reverselist: ArrayArray反转数组顺序informat.Array.reverse([1,2,3]) // [3,2,1]
repeatcount: Integer, element: ObjectArray生成重复元素的数组informat.Array.repeat(3, 'a') // ["a","a","a"]
sublistlist: Array, fromIndex: Integer, toIndex: IntegerArray返回数组的子集informat.Array.sublist([1,2,3,4], 1, 2) // [2,3]
filterlist: Array, key: String, value: ObjectArray过滤数组中指定属性值的元素informat.Array.filter([{a:1},{a:2}], "a", 2) // [{a:2}]
shiftlist: ArrayObject移除并返回数组头部元素informat.Array.shift([1,2,3]) // 1
poplist: ArrayObject移除并返回数组尾部元素informat.Array.pop([1,2,3]) // 3
sumlist: ArrayDouble对数字数组求和informat.Array.sum([1,2,3]) // 6.0
avglist: ArrayDouble对数字数组求平均值informat.Array.avg([1,2,3]) // 2.0
maxlist: ArrayDouble求数字数组最大值informat.Array.max([1,2,3]) // 3.0
minlist: ArrayDouble求数字数组最小值informat.Array.min([1,2,3]) // 1.0
firstlist: ArrayObject返回数组第一个元素informat.Array.first([1,2,3]) // 1
lastlist: ArrayObject返回数组最后一个元素informat.Array.last([1,2,3]) // 3

Date

日期运算相关函数,调用方式为informat.Date.方法

方法传参返回值说明示例
sysdate无参数Date返回当前日期和时间informat.Date.sysdate() // Date对象
now无参数Long返回当前时间的UNIX时间戳informat.Date.now() // 1668483800328
newDateyear, month, day, hour, minute, second, millisecond (均为Integer,可选)Date返回指定的日期,参数可选informat.Date.newDate(2025, 0, 3) // 2025-01-03 00:00:00,000
dateSetd: Date或Long, type: String, value: IntegerDate将日期中指定部分设置为值informat.Date.dateSet(date, 'year', 2024) // 设置年份为2024
dateAddd: Date或Long, type: String, diff: IntegerDate计算日期按类型加上差值后的日期informat.Date.dateAdd(date, 'year', 1) // 加1年
datePartd: Date或Long, type: StringInteger返回日期中指定部分的值informat.Date.datePart(date, 'year') // 返回年份
dateBefored1: Date或Long, d2: Date或LongBoolean判定d1是否在d2之前informat.Date.dateBefore(date1, date2) // true/false
dateAfterd1: Date或Long, d2: Date或LongBoolean判定d1是否在d2之后informat.Date.dateAfter(date1, date2) // true/false
dateDiffd1: Date或Long, d2: Date或LongInteger计算两个日期之间的天数差值informat.Date.dateDiff(date1, date2) // 相差天数
monthDiffd1: Date或Long, d2: Date或LongInteger计算两个日期之间的月份数差值informat.Date.monthDiff(date1, date2) // 相差月数
weekDiffd1: Date或Long, d2: Date或LongInteger计算两个日期之间的周差值informat.Date.weekDiff(date1, date2) // 相差周数
quarterDiffd1: Date或Long, d2: Date或LongInteger计算两个日期之间的季度差值informat.Date.quarterDiff(date1, date2) // 相差季度数

特殊说明

month的值范围

月份
1月0
2月1
3月2
4月3
5月4
6月5
7月6
8月7
9月8
10月9
11月10
12月11

day_of_week的值范围

星期日0
星期一1
星期二2
星期三3
星期四4
星期五5
星期六6

Encode

字符串编解码相关函数,调用方式为informat.Encode.方法

方法传参返回值说明示例
md5s: StringString返回字符串的MD5哈希值informat.Encode.md5('123456') // e10adc3949ba59abbe56e057f20f883e
urlEncodestr: StringString将字符串进行URL编码informat.Encode.urlEncode('https://next.informat.cn') // https%3A%2F%2Fnext.informat.cn
urlDecodestr: StringString将字符串进行URL解码informat.Encode.urlDecode('https%3A%2F%2Fnext.informat.cn') // https://next.informat.cn

Math

数学运算。它包括了一些数学函数,调用方式为informat.Math.方法

方法传参返回值说明示例
absx: Integer或DoubleInteger或Double返回数字的绝对值informat.Math.abs(-100.3) // 100.3
powd1: Integer或Double, d2: Integer或DoubleDouble返回d1的d2次方informat.Math.pow(2, 3) // 8.0
ceilx: DoubleDouble返回大于或等于x的最小整数informat.Math.ceil(2.2) // 3.0
floorx: DoubleDouble返回小于或等于x的最大整数informat.Math.floor(2.2) // 2.0
random无参数Double返回0到1之间的随机数informat.Math.random() // 0.6260832016946124
sqrtx: DoubleDouble返回x的平方根informat.Math.sqrt(4) // 2.0
roundn: Double, digits: IntegerDouble返回数字按指定位数四舍五入的值informat.Math.round(3.1415926, 2) // 3.14

Misc

工具函数,调用方式为informat.Misc.方法

方法传参返回值说明示例
jsonStringifyobj: ObjectString将对象转换为JSON字符串informat.Misc.jsonStringify({a:1}) // "{\"a\":1}"
jsonParsestr: StringObject将JSON字符串转换为对象informat.Misc.jsonParse('{"a":1}') // {a:1}
parseFloatstr: StringDouble将字符串转换为小数informat.Misc.parseFloat("3.14") // 3.14
parseIntstr: StringInteger将字符串转换为整数informat.Misc.parseInt("3.14") // 3
timestampToDatetimestamp: IntegerDate将UNIX时间戳转换为日期informat.Misc.timestampToDate(1667232000000)
dateToTimestampdate: DateInteger将日期转换为UNIX时间戳informat.Misc.dateToTimestamp(new Date())
formatDatedate: Date, fmt: StringString按格式格式化日期informat.Misc.formatDate(date, 'yyyy-MM-dd')
parseDatestr: String, fmt: StringDate按格式解析日期字符串informat.Misc.parseDate('2022-11-01', 'yyyy-MM-dd')
host无参数String返回系统首页地址informat.Misc.host() // https://next.informat.cn/
pinyinstr: StringString返回字符串的中文拼音informat.Misc.pinyin('你好') // "ni hao"
shortPinyinstr: StringString返回拼音首字母informat.Misc.shortPinyin('你好') // "nh"
expectNotNullobj: Object, message: StringObject判空,为空则抛异常informat.Misc.expectNotNull(obj, '不能为空')
expectFirstarray: Array, message: StringObject返回数组第一个元素informat.Misc.expectFirst([1,2], '空数组') // 1
expectLastarray: Array, message: StringObject返回数组最后一个元素informat.Misc.expectLast([1,2], '空数组') // 2
invokeScriptscript: String, func: String, ...args: ObjectObject调用脚本中的函数informat.Misc.invokeScript('test.js', 'add', 1, 2)
invokeAutomaticautomaticId: String, ...args: ObjectObject调用自动化程序informat.Misc.invokeAutomatic('test', 1, 2)
httpGeturl: StringString通过GET方式访问URLinformat.Misc.httpGet('https://example.com')
propobject: Object, key: StringObject获取对象属性值informat.Misc.prop({a:1}, 'a') // 1
propsobject: Object, props: Array<String>Object获取多个属性组成新对象informat.Misc.props({a:1,b:2}, ['a'])
transformobject: Object, mapping: Map<String,String>Object按映射关系转换对象属性informat.Misc.transform({name:'张三'}, {name:'userName'})
appId无参数String获取所在应用的IDinformat.Misc.appId()
getAppIdByKeykey: StringString通过应用标识符查询应用IDinformat.Misc.getAppIdByKey('appKey')
attachmentURLtableKey: String, fieldKey: String, value: StringString获取附件访问链接informat.Misc.attachmentURL('staff','photo','1.png')
appResURLappResId: StringString获取应用资源库资源地址informat.Misc.appResURL('image.jpg')
websiteResURLmoduleKey: String, filePath: StringString获取网站模块资源地址informat.Misc.websiteResURL('module','logo.png')
barcodeURLvalue: String, format: StringString返回条码图片BASE64值informat.Misc.barcodeURL('12345','CODE128')
qrcodeURLvalue: String, width: IntegerString返回二维码图片BASE64值informat.Misc.qrcodeURL('text', 300)
evalstr: String, context: ObjectObject执行表达式引擎替换模板informat.Misc.eval('${name}', {name:'test'})
safesqlsql: String, params: Array<Object>String生成安全的完整SQLinformat.Misc.safesql('select ?', ['test'])
uuid16无参数String生成16位UUID字符串informat.Misc.uuid16() // "lqjfw3xaglp38tru"
uuid32无参数String生成32位UUID字符串informat.Misc.uuid32() // "rigzv6usysisu2gmkash6hdg526y10b5"
newObject无参数Object构建空对象informat.Misc.newObject() // {}
recordSqlsql: String, parameters: Array<Object>Array<Object>执行SQL查询数据表记录informat.Misc.recordSql('select * from table', [])

String

字符串相关函数,调用方式为informat.String.方法

方法传参返回值说明示例
uppers: StringString将字符串所有字母转为大写informat.String.upper('abc') // "ABC"
lowers: StringString将字符串所有字母转为小写informat.String.lower('ABC') // "abc"
concats1: String, s2: StringString将两个字符串合并informat.String.concat('a','b') // "ab"
lpads1: String, len: Integer, s2: StringString在字符串开始处填充字符informat.String.lpad('ABC',6,'0') // "000ABC"
rpads1: String, len: Integer, s2: StringString在字符串结尾处填充字符informat.String.rpad('ABC',6,'0') // "ABC000"
trims: StringString移除字符串左右空白字符informat.String.trim(' abc ') // "abc"
replaces: String, s1: String, s2: StringString替换字符串中第一次出现的子串informat.String.replace('abca','a','_') // "_bca"
replaceAlls: String, s1: String, s2: StringString替换字符串中所有出现的子串informat.String.replaceAll('abca','a','_') // "_bc_"
substrs: String, start: Integer, len: IntegerString从指定位置截取指定长度子串informat.String.substr('abcd',1,2) // "bc"
substrings: String, start: Integer, end: IntegerString截取从开始到结束位置的子串informat.String.substring('abcd',0,2) // "ab"
indexOfs: String, s2: StringInteger获取子串首次出现的位置informat.String.indexOf('abcd','a') // 0
lastIndexOfs: String, s2: StringInteger获取子串最后出现的位置informat.String.lastIndexOf('abcad','a') // 3
containss: String, s2: StringBoolean判断是否包含子串informat.String.contains('abcd','a') // true
lengths: StringInteger获取字符串长度informat.String.length('abcd') // 4
startsWiths: String, s2: StringBoolean判断是否以子串开头informat.String.startsWith('abcd','a') // true
endsWiths: String, s2: StringBoolean判断是否以子串结尾informat.String.endsWith('abcd','d') // true
matchregex: String, input: StringBoolean使用正则表达式验证字符串informat.String.match('^[a-z]+','abcd') // true
isEmptys: StringBoolean判断字符串是否为空(去除首尾空格)informat.String.isEmpty(' ') // true
isNotEmptys: StringBoolean判断字符串是否不为空(去除首尾空格)informat.String.isNotEmpty('a') // true
html2texts: StringString将HTML内容转换为文本(XSS过滤)informat.String.html2text('<div>test</div>') // "test"

User

当前系统下的用户相关操作函数,调用方式为informat.User.方法

方法传参返回值说明示例
usersWithRoleroleIdList: Array<String>Array<String>返回拥有指定角色中任意一个角色的用户列表informat.User.usersWithRole(['admin']) // [user1, user2, user3]
usersWithDepartmentdepartmentIdList: Array<String>Array<String>返回属于指定部门的用户列表informat.User.usersWithDepartment(['yanfabu'])
superiorUsersuserId: StringArray<String>返回用户的直接上级列表informat.User.superiorUsers('user1') // [user2, user3]
superiorUsersWithLeveluserId: String, level: IntegerArray<String>返回用户的连续上级列表(指定层级)informat.User.superiorUsersWithLevel(Context.userId(), 1)
subordinateUsersuserId: StringArray<String>返回用户的直接下属列表informat.User.subordinateUsers('user1') // [user2, user3]
subordinateUsersWithLeveluserId: String, level: IntegerArray<String>返回用户的连续下属列表(指定层级)informat.User.subordinateUsersWithLevel('user1', 2) // [user2, user3]
leaderOfDeptdepartmentId: StringArray<String>返回单个部门负责人列表informat.User.leaderOfDept('dept1') // [user2, user3]
leaderOfDeptWithLeveldepartmentId: String, level: IntegerArray<String>返回连续上级部门负责人列表informat.User.leaderOfDeptWithLevel('yanfabu', 1)
leaderOfDeptListdepartmentIdList: Array<String>Array<String>返回多个部门的负责人列表informat.User.leaderOfDeptList(['dept1', 'dept2']) // [user2, user3, user4]
parentOfDeptdepartmentId: StringString返回部门的直接父部门IDinformat.User.parentOfDept('dept1') // dept2
parentOfDeptListdepartmentId: StringArray<String>返回部门的所有父部门ID列表informat.User.parentOfDept('dept1') // ['dept2', 'dept3']
childrenOfDeptdepartmentId: StringArray<String>返回单个部门所有下级部门列表(递归)informat.User.childrenOfDept('dept1') // [dept2, dept3]
childrenOfDeptListdepartmentList: Array<String>Array<String>返回多个部门的所有下级部门列表informat.User.childrenOfDeptList(['dept1', 'dept2']) // [dept2, dept3]
directChildrenOfDeptdepartmentId: StringArray<String>返回直接下级部门列表informat.User.directChildrenOfDept('dept1') // [dept2]
useruserId: StringUser返回用户信息对象informat.User.user(Context.userId())
userInfouserId: StringUserInfo返回用户详细信息对象informat.User.userInfo(Context.userId())
deptListdepartmentIdList: Array<String>Array<Dept>返回部门信息对象列表informat.User.deptList(['dept1', 'dept2'])
deptdeptId: StringDept返回部门信息对象informat.User.dept('dept1')

Context

上下文相关函数。上下文表示在执行过程中的环境参数,调用方式为informat.Context.方法

方法传参返回值说明示例
userId无参数String返回当前操作用户IDinformat.Context.userId() // "ek5veueb6c9zg"
appId无参数String返回当前应用IDinformat.Context.appId()
appEnvProppropKey: StringString返回应用环境变量值informat.Context.appEnvProp('payURL') // "http://dev-demo.com/pay"
httpHeaders无参数Object返回当前HTTP请求头信息informat.Context.httpHeaders() // {headers: {...}}
clipboardType无参数String返回应用剪切板数据类型informat.Context.clipboardType() // "test"
clipboardData无参数Object返回应用剪切板存储数据informat.Context.clipboardData()
weworkAccessToken无参数String返回企业微信AccessTokeninformat.Context.weworkAccessToken()
dingtalkAccessToken无参数String返回钉钉AccessTokeninformat.Context.dingtalkAccessToken()
feishuAccessToken无参数String返回飞书应用AccessTokeninformat.Context.feishuAccessToken()
feishuTenantAccessToken无参数String返回飞书租户AccessTokeninformat.Context.feishuTenantAccessToken()
requestIp无参数String返回当前请求IP地址informat.Context.requestIp() // "192.168.1.1"
hasAppPermpermKey: StringBoolean判断用户是否有应用权限informat.Context.hasAppPerm('admin') // true
hasModulePermmoduleKey: String, permKey: StringBoolean判断用户是否有模块权限informat.Context.hasModulePerm('crm', 'read') // true

Record

数据表相关函数,调用方式为informat.Record.方法

方法传参返回值说明示例
getByIdtableId: String, recordId: StringObject根据ID查询数据表记录信息informat.Record.getById('order', 'z2koxrkxtp854') // {amount:11, name:'测试采购单', id:'z2koxrkxtp854'}
getFieldValuetableId: String, recordId: String, fieldId: StringObject获取数据表记录的字段值informat.Record.getFieldValue('order','z2koxrkxtp854','amount') // 11
getByFieldtableId: String, fieldId: String, opt: String, value: ObjectArray<Record>根据单个字段过滤记录列表informat.Record.getByField('order', 'amount', 'eq', 11) // [{amount:11, name:'测试采购单', id:'z2koxrkxtp854'}]
getByFieldstableId: String, conditions: ArrayArray<Record>根据多个字段过滤记录列表informat.Record.getByFields('tab', [{fieldId:'text', opt:'eq', value:'13'}]) // [{amount:11, text:'13', id:'z2koxrkxtp854'}]
getRecordOptionNametableId: String, fieldId: String, value: StringString返回单个选项值的名称informat.Record.getRecordOptionName('order', 'type', 'a') // "选项1"
getRecordOptionNamestableId: String, fieldId: String, valueList: Array<String>, join: StringString返回多个选项值的名称并拼接informat.Record.getRecordOptionNames('order', 'type', ['a','b'], ',') // "选项1,选项2"
getRecordOptionstableId: String, fieldId: StringArray<Option>返回选项值列表informat.Record.getRecordOptions('order', 'type') // [{id:'a',name:'选项1'},{id:'b',name:'选项2'}]
getRelationListtableId: String, fieldId: String, recordId: StringArray<Record>返回关联列表字段的值informat.Record.getRelationList('order','orderDetail','z2koxrkxtp854')

T

国际化相关函数,调用方式为informat.T.方法

方法传参返回值说明示例
locale无参数String获取当前使用语言informat.T.locale() // "zh-CN"
tkey: String, args: Object/ArrayString通过翻译标识符和参数进行翻译informat.T.t('welcome.message') // "欢迎"
tWithLocalelocale: String, key: String, args: Object/ArrayString通过指定语言进行翻译informat.T.tWithLocale('en-US', 'welcome.message') // "Welcome"